From db3942b7ec5b6f5ed6dd6fe384c03596cda86da4 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 18 Apr 2014 14:26:45 -0500 Subject: [PATCH 1/2] Refactor the call to curl in add-default-github-hooks ... in preparation for two-factor authentication... Signed-off-by: Johannes Schindelin --- add-default-github-hooks.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/add-default-github-hooks.sh b/add-default-github-hooks.sh index d249ff1..c4b5ca4 100755 --- a/add-default-github-hooks.sh +++ b/add-default-github-hooks.sh @@ -13,19 +13,23 @@ die "Usage: $0 /" repository="$1" +mycurl () { + curl --netrc "$@" "$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 From d53b57098fd96a1f433e13204d198eaa3ef82d07 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Mon, 14 Apr 2014 14:21:06 -0500 Subject: [PATCH 2/2] add-default-github-hooks.sh: support 2-factor auth GitHub requires a special header when two-factor authentication is enabled. Signed-off-by: Johannes Schindelin --- add-default-github-hooks.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/add-default-github-hooks.sh b/add-default-github-hooks.sh index c4b5ca4..479691f 100755 --- a/add-default-github-hooks.sh +++ b/add-default-github-hooks.sh @@ -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 @@ -13,8 +14,9 @@ die "Usage: $0 /" repository="$1" +TWO_FACTOR_HEADER="${GITHUB_TWO_FACTOR:+X-GitHub-OTP: }$GITHUB_TWO_FACTOR" mycurl () { - curl --netrc "$@" "$url" + curl --netrc --header "$TWO_FACTOR_HEADER" "$@" "$url" } url="https://api.github.com/repos/$repository/hooks"