Skip to content

Commit d53b570

Browse files
ctruedendscho
authored andcommitted
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 <johannes.schindelin@gmx.de>
1 parent db3942b commit d53b570

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

add-default-github-hooks.sh

Lines changed: 4 additions & 2 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,8 +14,9 @@ die "Usage: $0 <org>/<repository>"
1314

1415
repository="$1"
1516

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

2022
url="https://api.github.com/repos/$repository/hooks"

0 commit comments

Comments
 (0)