Created
August 13, 2020 08:07
-
-
Save suzuki-shunsuke/11b74e51a4f7826eec20b744119ba1ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -eu | |
if [ -z "${CODEBUILD_WEBHOOK_EVENT:-}" ]; then | |
repo=$(echo "${CODEBUILD_SOURCE_REPO_URL}" | sed -E "s|https://github\.com/(.*)$|\1|" | sed -E "s|\.git$||") | |
# https://docs.github.com/en/rest/reference/repos#list-pull-requests-associated-with-a-commit | |
body=$(curl \ | |
-H "Authorization: token $GITHUB_TOKEN" \ | |
-H "Accept: application/vnd.github.groot-preview+json" \ | |
"https://api.github.com/repos/$repo/commits/$CODEBUILD_SOURCE_VERSION/pulls") | |
if [ "$(echo "$body" | jq ". | length")" -eq 0 ]; then | |
echo "no pull requests" | |
exit 0 | |
else | |
pr_number=$(echo "$body" | jq ".[0].number") | |
base=$(echo "$body" | jq -r ".[0].base.ref") | |
head=$(echo "$body" | jq -r ".[0].head.ref") | |
echo "$pr_number" | |
echo "$base" | |
echo "$head" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment