Skip to content

Commit c527985

Browse files
committed
feat: use bot token to create org hook
Signed-off-by: sebastien.heurtematte <[email protected]>
1 parent 9157815 commit c527985

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

github/create_webhook.sh

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ set -o nounset
1414
set -o pipefail
1515

1616
IFS=$'\n\t'
17-
SCRIPT_FOLDER="$(dirname "$(readlink -f "${0}")")"
18-
CI_ADMIN_ROOT="${SCRIPT_FOLDER}/.."
17+
set -x
18+
19+
SCRIPT_FOLDER="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
20+
#shellcheck disable=SC1091
21+
source "${SCRIPT_FOLDER}/../pass/pass_wrapper.sh"
22+
23+
GITHUB_PASS_DOMAIN="github.com"
1924

20-
TOKEN="$("${CI_ADMIN_ROOT}/utils/local_config.sh" "get_var" "access_token" "github")"
2125
#shellcheck disable=SC2089
2226
EVENTS='["push","pull_request"]'
2327

@@ -47,13 +51,16 @@ org() {
4751
exit 1
4852
fi
4953

54+
local pw_store_path="bots/${project_name}/${GITHUB_PASS_DOMAIN}"
55+
local bot_token=$(passw cbi "${pw_store_path}/api-token")
56+
5057
echo "Creating organization webhook..."
5158

5259
local response
5360
response="$(curl -sS\
5461
-X POST \
5562
-H "Accept: application/vnd.github+json" \
56-
-H "Authorization: Bearer ${TOKEN}"\
63+
-H "Authorization: Bearer ${bot_token}"\
5764
-H "X-GitHub-Api-Version: 2022-11-28" \
5865
"https://api.github.com/orgs/${org}/hooks" \
5966
-d '{"name":"web","active":true,"events":'${EVENTS}',"config":{"url":"'${webhook_url}'","content_type":"json"}}')"
@@ -62,6 +69,7 @@ org() {
6269
echo "ERROR:"
6370
printf " Message: %s\n" "$(echo "${response}" | jq '.message')"
6471
printf " Errors/Message: %s\n" "$(echo "${response}" | jq '.errors[].message')"
72+
exit 1
6573
fi
6674
}
6775

@@ -71,6 +79,7 @@ repo() {
7179
local short_name="${project_name##*.}"
7280
local webhook_url="https://ci.eclipse.org/${short_name}/github-webhook/"
7381

82+
7483
# check that project name is not empty
7584
if [[ -z "${project_name}" ]]; then
7685
printf "ERROR: a project name must be given.\n"
@@ -83,13 +92,16 @@ repo() {
8392
exit 1
8493
fi
8594

95+
local pw_store_path="bots/${project_name}/${GITHUB_PASS_DOMAIN}"
96+
local bot_token=$(passw cbi "${pw_store_path}/api-token")
97+
8698
echo "Creating repo webhook..."
8799

88100
local response
89101
response="$(curl -sS\
90102
-X POST \
91103
-H "Accept: application/vnd.github+json" \
92-
-H "Authorization: Bearer ${TOKEN}"\
104+
-H "Authorization: Bearer ${bot_token}"\
93105
-H "X-GitHub-Api-Version: 2022-11-28" \
94106
"https://api.github.com/repos/${repo}/hooks" \
95107
-d '{"name":"web","active":true,"events":'${EVENTS}',"config":{"url":"'${webhook_url}'","content_type":"json"}}')"

github/setup_github_bot.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ set_up_github_account() {
5959
* API token
6060
* Name: Jenkins GitHub Plugin token https://ci.eclipse.org/${SHORT_NAME}
6161
* Expiration: No expiration
62-
* Scopes: repo:status, public_repo, admin:repo_hook
62+
* Scopes: repo:status, public_repo, admin:repo_hook, admin:org_hook
6363
* Add token to pass (api-token)
6464
* Add GitHub bot to project’s GitHub org (invite via webmaster account)
6565
EOF

0 commit comments

Comments
 (0)