Skip to content

Commit fb3bc45

Browse files
committed
Merge branch 'two-factor'
This branch adds support for GitHub two-factor authentication to the add-default-github-hooks.sh script.
2 parents 57c353d + d53b570 commit fb3bc45

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

add-default-github-hooks.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/bin/sh
22

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

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

1415
repository="$1"
1516

17+
TWO_FACTOR_HEADER="${GITHUB_TWO_FACTOR:+X-GitHub-OTP: }$GITHUB_TWO_FACTOR"
18+
mycurl () {
19+
curl --netrc --header "$TWO_FACTOR_HEADER" "$@" "$url"
20+
}
21+
1622
url="https://api.github.com/repos/$repository/hooks"
17-
hooks="$(curl --netrc "$url")"
23+
hooks="$(mycurl)"
1824

1925
# IRC
2026
if ! echo "$hooks" | grep '^ "name": "irc",$'
2127
then
2228
echo "Adding IRC hook"
23-
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"
29+
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"}}'
2430
fi
2531

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

0 commit comments

Comments
 (0)