Skip to content

Instantly share code, notes, and snippets.

@clux
Last active February 6, 2016 23:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clux/247d74d956d384a49209 to your computer and use it in GitHub Desktop.
Save clux/247d74d956d384a49209 to your computer and use it in GitHub Desktop.
mass edit .travis.yml
#!/bin/bash
set -e
dir="$1"
cd "$dir"
file=".travis.yml"
# ensure we have an empty staging area before we start committing
cache=$(git diff --cached)
if [[ -n "${cache// }" ]]; then
echo "non-empty cache"
elif [[ -f "$file" ]]; then
emailnotifies="{email: {on_success: 'change',on_failure: 'always'}}"
json=$(js-yaml "$file" | json -e this.notifications="$emailnotifies")
echo "$json" | js-yaml | head -n-1 > "$file"
git commit "$file" -m "automated change of .travis.yml to enable email notifications - https://gist.github.com/clux/247d74d956d384a49209"
git push
else
echo "no $file in current directory"
fi
@clux
Copy link
Author

clux commented Feb 6, 2016

Requires the two npm packages js-yaml and json installed globally. The head -n-1 quirk is to get rid of an extra newline output by js-yaml.

Usage: in a directory of repositories run:

find . -mindepth 1 -maxdepth 1 -type d -print -exec ~/repos/enable-notifications.sh {} \;

This current example updates the notifications: part of the .travis.yml file to enable partial email notifications, and this information is duplicated in many-many repositories.

Example commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment