Skip to content

Instantly share code, notes, and snippets.

@jtolio
Created February 28, 2012 18:17
Show Gist options
  • Save jtolio/1934071 to your computer and use it in GitHub Desktop.
Save jtolio/1934071 to your computer and use it in GitHub Desktop.
gerrit events in irc
#!/bin/bash
function event_stream {
ssh -p 29418 gerrit@localhost gerrit stream-events
}
function get_json {
python -c "import sys, json; print json.dumps(json.loads(sys.stdin.read())[sys.argv[1]])" $1
}
function get_value {
python -c "import sys, json; print json.loads(sys.stdin.read())[sys.argv[1]]" $1
}
function notify {
nc localhost 65435
}
event_stream | while read -r; do
event=$REPLY
type=$(echo $event | get_value type)
if [ "$type" == "patchset-created" ]; then
user=$(echo $event | get_json uploader | get_value name)
change_name=$(echo $event | get_json change | get_value subject)
change_url=$(echo $event | get_json change | get_value url)
echo "$user added new patchset for" \
"change \"$change_name\" $change_url" | notify
elif [ "$type" == "change-abandoned" ]; then
user=$(echo $event | get_json abandoner | get_value name)
change_name=$(echo $event | get_json change | get_value subject)
change_url=$(echo $event | get_json change | get_value url)
echo "$user abandoned change \"$change_name\" $change_url" | notify
elif [ "$type" == "change-restored" ]; then
user=$(echo $event | get_json restorer | get_value name)
change_name=$(echo $event | get_json change | get_value subject)
change_url=$(echo $event | get_json change | get_value url)
echo "$user restored change \"$change_name\" $change_url" | notify
elif [ "$type" == "change-merged" ]; then
user=$(echo $event | get_json submitter | get_value name)
change_name=$(echo $event | get_json change | get_value subject)
change_url=$(echo $event | get_json change | get_value url)
echo "$user submitted change \"$change_name\" $change_url" | notify
elif [ "$type" == "comment-added" ]; then
user=$(echo $event | get_json author | get_value name)
change_name=$(echo $event | get_json change | get_value subject)
change_url=$(echo $event | get_json change | get_value url)
if [ "$user" != "Jenkins CI" ]; then
echo "$user commented on change \"$change_name\" $change_url" |
notify
fi
elif [ "$type" == "ref-updated" ]; then
user=$(echo $event | get_json submitter | get_value name)
project=$(echo $event | get_json refUpdate | get_value project)
refname=$(echo $event | get_json refUpdate | get_value refName)
echo "$user updated $project:$refname" | notify
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment