Added Travis CI status caching task, for status in shell prompts

This commit is contained in:
Nathan Broadbent
2012-01-13 12:07:07 +08:00
parent 0c510f73ff
commit 04ee82b0c8
2 changed files with 28 additions and 2 deletions

View File

@@ -259,7 +259,7 @@ function _git_index_batch_cmd() {
echo -e "== Running command for $_bld_col$(_git_index_count)$_txt_col repos...\n" echo -e "== Running command for $_bld_col$(_git_index_count)$_txt_col repos...\n"
unset IFS unset IFS
for base_path in $(sed -e "s/--.*//" "$GIT_REPO_DIR/.git_index" | grep . | sort); do 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 done
else else

View File

@@ -115,3 +115,29 @@ git_swap_remotes() {
if [ "$shell" = "bash" ]; then if [ "$shell" = "bash" ]; then
complete -o default -o nospace -F _git_fetch git_swap_remotes complete -o default -o nospace -F _git_fetch git_swap_remotes
fi 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
}