-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathentrypoint.sh
executable file
·70 lines (61 loc) · 2.02 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bash
set -o errexit
set -o pipefail
fail() {
echo "$@" >&2
exit 1
}
[ -n "${GITHUB_REPOSITORY}" ] || fail "No GITHUB_REPOSITORY was supplied."
[ -n "${PULL_REQUEST_LABEL}" ] || fail "No PULL_REQUEST_LABEL was supplied."
[ -n "${GITHUB_TOKEN}" ] || fail "No GITHUB_TOKEN was supplied."
# Determine https://github.com/OWNER/REPO from GITHUB_REPOSITORY.
REPO="${GITHUB_REPOSITORY##*/}"
OWNER="${GITHUB_REPOSITORY%/*}"
git config user.name "${GIT_AUTHOR_NAME}"
git config user.email "${GIT_AUTHOR_EMAIL}"
[ -n "${OWNER}" ] || fail "Could not determine GitHub owner from GITHUB_REPOSITORY."
[ -n "${REPO}" ] || fail "Could not determine GitHub repo from GITHUB_REPOSITORY."
# Fetch the SHAs from the pull requests that are marked with $PULL_REQUEST_LABEL.
readarray -t shas < <(
jq -cn '
{
query: $query,
variables: {
owner: $owner,
repo: $repo,
pull_request_label: $pull_request_label
}
}' \
--arg query '
query($owner: String!, $repo: String!, $pull_request_label: String!) {
repository(owner: $owner, name: $repo) {
pullRequests(states: OPEN, labels: [$pull_request_label], first: 100) {
nodes {
headRefOid
}
}
}
}' \
--arg owner "$OWNER" \
--arg repo "$REPO" \
--arg pull_request_label "$PULL_REQUEST_LABEL" |
curl \
--fail \
--show-error \
--silent \
--header "Authorization: token $GITHUB_TOKEN" \
--header "Content-Type: application/json" \
--data @- \
https://api.github.com/graphql |
jq -r '.data.repository.pullRequests.nodes | .[].headRefOid'
)
# Do not attempt to merge if there are no pull requests to be merged.
if [ ${#shas[@]} -eq 0 ]; then
echo "No pull requests with label $PULL_REQUEST_LABEL"
exit 0
fi
# Merge all shas together into one commit.
git fetch origin "${shas[@]}"
git merge --no-ff --no-commit "${shas[@]}"
git commit --message "Merged Pull Requests (${shas[*]})"
echo "Merged ${#shas[@]} pull requests"