Skip to content

Support GitHub 2-factor authentication #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 18, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions add-default-github-hooks.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/sh

# Use this script to add the IRC and Jenkins webhooks to the GitHub repositories.
# You will need to add credentials to your $HOME/.netrc for this to work.
# You will need to add credentials to your $HOME/.netrc for this to work. And if
# you use two-factor authentication, you'll also need to pass GITHUB_TWO_FACTOR.

die () {
echo "$*" >&2
Expand All @@ -13,19 +14,24 @@ die "Usage: $0 <org>/<repository>"

repository="$1"

TWO_FACTOR_HEADER="${GITHUB_TWO_FACTOR:+X-GitHub-OTP: }$GITHUB_TWO_FACTOR"
mycurl () {
curl --netrc --header "$TWO_FACTOR_HEADER" "$@" "$url"
}

url="https://api.github.com/repos/$repository/hooks"
hooks="$(curl --netrc "$url")"
hooks="$(mycurl)"

# IRC
if ! echo "$hooks" | grep '^ "name": "irc",$'
then
echo "Adding IRC hook"
curl --netrc -XPOST -d '{"name":"irc","active":true,"events":["push","pull_request"],"config":{"server":"irc.freenode.net","port":"6667","room":"#imagejdev","message_without_join":"1","notice":"1"}}' "$url"
mycurl -XPOST -d '{"name":"irc","active":true,"events":["push","pull_request"],"config":{"server":"irc.freenode.net","port":"6667","room":"#imagejdev","message_without_join":"1","notice":"1"}}'
fi

# Jenkins
if ! echo "$hooks" | grep '^ "name": "jenkinsgit",$'
then
echo "Adding Jenkins hook"
curl --netrc -XPOST -d '{"name":"jenkinsgit","active":true,"events":["push"],"config":{"jenkins_url":"http://jenkins.imagej.net/"}}' "$url"
mycurl -XPOST -d '{"name":"jenkinsgit","active":true,"events":["push"],"config":{"jenkins_url":"http://jenkins.imagej.net/"}}'
fi