Skip to content

Commit b50c504

Browse files
author
dysrama
committed
Added filter to GC trigger and trigger push event after webhook creation
1 parent 2ebe4ee commit b50c504

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

createWebhook.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ gcloud alpha builds triggers create webhook \
5151
--name=${TRIGGER_NAME} \
5252
--inline-config=$BUILD_YAML_PATH \
5353
--secret=${SECRET_PATH} \
54-
--substitutions="_APP_ID=${APP_ID},_REGION=${REGION}"',_APP_REPO=$(body.repository.html_url),_REF=$(body.ref),_SHA=$(body.after)'
54+
--substitutions="_APP_ID=${APP_ID},_REGION=${REGION}"',_APP_REPO=$(body.repository.html_url),_REF=$(body.ref),_SHA=$(body.after)' \
55+
--subscription-filter="_REF != '\$(body.ref)'"
5556

5657
## Retrieve the URL
5758
WEBHOOK_URL="https://cloudbuild.googleapis.com/v1/projects/${PROJECT_ID}/triggers/${TRIGGER_NAME}:webhook?key=${API_KEY_VALUE}&secret=${SECRET_VALUE}"

git/gh.sh

+10-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,17 @@ export GIT_ASKPASS=$BASE_DIR/common/ghp.sh
4747

4848
## Execution
4949
create_webhook () {
50-
curl -H "Authorization: token ${GIT_TOKEN}" \
50+
response=$(curl -H "Authorization: token ${GIT_TOKEN}" \
5151
-d '{"config": {"url": "'${WEBHOOK_URL}'", "content_type": "json"}}' \
52-
-X POST ${GIT_API_BASE}/repos/${GIT_USERNAME}/${repo}/hooks
52+
-X POST ${GIT_API_BASE}/repos/${GIT_USERNAME}/${repo}/hooks)
53+
54+
hook_id=`echo "$response" | grep -o '"id": [0-9]*' | grep -o '[0-9]*$'`
55+
56+
# Trigger webhook using the hook id returned by the create webhook call to ensure a payload with ref and sha is sent
57+
curl -L \
58+
-X POST \
59+
-H "Authorization: token ${GIT_TOKEN}" \
60+
-H "X-GitHub-Api-Version: 2022-11-28" ${GIT_API_BASE}/repos/${GIT_USERNAME}/${repo}/hooks/$hook_id/tests
5361
}
5462

5563

0 commit comments

Comments
 (0)