Skip to content

Instantly share code, notes, and snippets.

@diesalbla
Created September 18, 2019 17:49
Show Gist options
  • Save diesalbla/338d8601a7d467020c70152c6f316d13 to your computer and use it in GitHub Desktop.
Save diesalbla/338d8601a7d467020c70152c6f316d13 to your computer and use it in GitHub Desktop.
Scala-Steward-Merger: Merge Pull-Requests from scala-steward that carry patch library upgrades
#!/usr/bin/bash
export OWNER=$1
export REPOSITORY=$2
export LOGIN="<GITHUB_LOGIN>"
export TOKEN="<GITHUB_TOKEN>"
processPullRequest() {
NUMPR=$1
COMMIT=$2
echo "Processing Pull Request $NUMPR from $REPOSITORY of $OWNER with HEAD at commit $COMMIT"
status=$(
curl --silent \
--user "$LOGIN:$TOKEN" \
https://api.github.com/repos/$OWNER/$REPOSITORY/commits/$COMMIT/status |
jq '.state'
)
if [ $status = '"success"' ] ; then
echo "Attempting to merge "
curl --silent \
--request PUT \
--data '{"sha":"'$COMMIT'"}' \
--user "$LOGIN:$TOKEN" \
"https://api.github.com/repos/$OWNER/$REPOSITORY/pulls/$NUMPR/merge"
else
echo "Pull Request $NUMPR from $REPOSITORY has not succeeded yet. Skipping."
fi
}
export -f processPullRequest
curl --silent \
--user "$LOGIN:$TOKEN" \
https://api.github.com/repos/$OWNER/$REPOSITORY/pulls |
jq '.[] | select(.user.login | contains("scala-steward")) | select(.state | contains("open")) | select(.body | contains("labels: semver-patch")) | "\(.number) \(.head.sha)"' |
xargs -L1 echo |
xargs -L1 bash -c 'processPullRequest $1 $2' {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment