mirror of
https://github.com/jessfraz/dockerfiles.git
synced 2024-11-23 11:31:49 +01:00
f81fc91bfd
* attempt to fix build correcting error message from travis ci In ./github-dev/cleanup-pr-branch line 5: if [[ ! -z "$TOKEN" ]]; then ^-- SC2236: Use -n instead of ! -z. * Update cleanup-pr-branch * Update release-email-notification corrected SC2236 * Update upload-assets correct SC2236 * Update sendemail Fix SC2236 * Update entrypoint.sh Fix SC2236 * Update run Fix SC2236
53 lines
1.3 KiB
Bash
Executable File
53 lines
1.3 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
set -o pipefail
|
|
|
|
if [[ -n "$TOKEN" ]]; then
|
|
GITHUB_TOKEN=$TOKEN
|
|
fi
|
|
|
|
if [[ -z "$GITHUB_TOKEN" ]]; then
|
|
echo "Set the GITHUB_TOKEN env variable."
|
|
exit 1
|
|
fi
|
|
|
|
if [[ -z "$GITHUB_REPOSITORY" ]]; then
|
|
echo "Set the GITHUB_REPOSITORY env variable."
|
|
exit 1
|
|
fi
|
|
|
|
URI=https://api.github.com
|
|
API_VERSION=v3
|
|
API_HEADER="Accept: application/vnd.github.${API_VERSION}+json"
|
|
AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}"
|
|
|
|
main(){
|
|
action=$(jq --raw-output .action "$GITHUB_EVENT_PATH")
|
|
merged=$(jq --raw-output .pull_request.merged "$GITHUB_EVENT_PATH")
|
|
|
|
echo "action: $action merged: $merged"
|
|
|
|
if [[ "$action" == "closed" ]] && [[ "$merged" == "true" ]]; then
|
|
# delete the branch.
|
|
ref=$(jq --raw-output .pull_request.head.ref "$GITHUB_EVENT_PATH")
|
|
owner=$(jq --raw-output .pull_request.head.repo.owner.login "$GITHUB_EVENT_PATH")
|
|
repo=$(jq --raw-output .pull_request.head.repo.name "$GITHUB_EVENT_PATH")
|
|
|
|
if [[ "$ref" == "master" ]]; then
|
|
# Never delete the master branch.
|
|
echo "Will not delete master branch for ${owner}/${repo}, exiting."
|
|
exit 0
|
|
fi
|
|
|
|
echo "Deleting branch ref $ref for owner ${owner}/${repo}..."
|
|
curl -XDELETE -sSL \
|
|
-H "${AUTH_HEADER}" \
|
|
-H "${API_HEADER}" \
|
|
"${URI}/repos/${owner}/${repo}/git/refs/heads/${ref}"
|
|
|
|
echo "Branch delete success!"
|
|
fi
|
|
}
|
|
|
|
main "$@"
|