Set up a daily notification in Slack for changes in a remote git repo on Heroku Scheduler
# set up an incoming webhook on Slack (https://api.slack.com/incoming-webhooks), then | |
heroku create my-notifier | |
heroku config:set REPO='https://github.com/some/repo.git' -a my-notifier | |
heroku config:set SINCE='1 day ago' -a my-notifier | |
heroku config:set WATCHFILES='file1 file2 /full/path/to/file3' -a my-notifier | |
heroku config:set WEBHOOK='https://hooks.slack.com/services/my/web/hook' -a my-notifier | |
heroku config:set USERNAME='a user who notifies' -a my-notifier | |
heroku config:set EMOJI='ghost' -a my-notifier | |
heroku addons:create scheduler:standard -a my-notifier | |
# note the ID of the scheduler, then | |
heroku addons:open scheduler-with-some-id | |
# and add a new job to run the following command line daily: | |
# git clone $REPO . -q ; CHANGED=`git log --pretty=format: --name-only --since="$SINCE" | grep -v -e '^$' | sort | uniq` ; MATCHED=`for FILE in $WATCHFILES ; do grep $FILE <<< "$CHANGED" ; done` ; [ -n "$MATCHED" ] && curl -X POST -H 'Content-type: application/json' --data '{"text":"Files changed in <'"$REPO"'|'"`basename ${REPO%.*}`"'> since '"$SINCE"':\n'"$(echo $MATCHED | sed 's/[^ ][^ ]*/`&`\\n/g')"'", "username": "'"$USERNAME"'", "icon_emoji": ":'"$EMOJI"':"}' "$WEBHOOK" |
This comment has been minimized.
This comment has been minimized.
Note that Heroku Scheduler (https://devcenter.heroku.com/articles/scheduler) says that
That is, with a daily run and |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
There's probably a way to do this with the GitHub API, but this approach should work with non-GitHub remotes.