From 04ee82b0c8c9514a647a954fdf0edc616399fa27 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 13 Jan 2012 12:07:07 +0800 Subject: [PATCH] Added Travis CI status caching task, for status in shell prompts --- lib/git/repo_index.sh | 2 +- lib/git/tools.sh | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/git/repo_index.sh b/lib/git/repo_index.sh index 445de51..8271f4c 100644 --- a/lib/git/repo_index.sh +++ b/lib/git/repo_index.sh @@ -259,7 +259,7 @@ function _git_index_batch_cmd() { echo -e "== Running command for $_bld_col$(_git_index_count)$_txt_col repos...\n" unset IFS for base_path in $(sed -e "s/--.*//" "$GIT_REPO_DIR/.git_index" | grep . | sort); do - cd "$base_path" + if [ -z "$NOCD" ]; then cd "$base_path"; fi $@ done else diff --git a/lib/git/tools.sh b/lib/git/tools.sh index c93fa82..dfdb007 100644 --- a/lib/git/tools.sh +++ b/lib/git/tools.sh @@ -114,4 +114,30 @@ git_swap_remotes() { # (use git fetch tab completion) if [ "$shell" = "bash" ]; then complete -o default -o nospace -F _git_fetch git_swap_remotes -fi \ No newline at end of file +fi + + +# Updates cached Travis CI status if repo contains .travis.yml +# +# Creates and excludes TRAVIS_CI_STATUS +# Use with SCM breeze repo index. +# Add the following line to your crontab: (updates every 2 minutes) +# */2 * * * * /bin/bash -c '. /home/YOUR_USERNAME/.bashrc && git_index --rebuild && NOCD=true git_index --batch-cmd git_update_travis_status' +# +git_update_travis_status() { + if [ -e "$base_path/.travis.yml" ]; then + if type ruby > /dev/null 2>&1 && type travis > /dev/null 2>&1; then + # Only use slug from origin + local repo=$(ruby -e "puts %x[cd $base_path && git remote -v].scan(/origin.*(?:\:|\/)([^\:\/]+\/[^\:\/]+)\.git/m).flatten.uniq") + local travis_output=$(travis repositories --slugs="$repo") + local status="" + case "$travis_output" in + *Passing*) status="Passing";; + *Failing*) status="Failing";; + *Running*) status="Running";; + esac + echo "$status" > "$base_path/TRAVIS_CI_STATUS" + git_ignore "TRAVIS_CI_STATUS" "$base_path/.git/info/exclude" + fi + fi +}