#!/bin/bash # Script for pulling a github pull request # along with generating a merge commit message. # Example usage for pull request #6007 and /next branch: # git fetch # git checkout origin/next # ./scripts/pull_github_pr.sh 6007 set -e shopt -s extglob trap 'echo "error $? in $0 line $LINENO"' ERR gh_hosts=~/.config/gh/hosts.yml jenkins_url="https://jenkins.scylladb.com" ORANGE='\033[0;33m' NC='\033[0m' if [[ ( -z "$GITHUB_LOGIN" || -z "$GITHUB_TOKEN" ) && -f "$gh_hosts" ]]; then GITHUB_LOGIN=$(awk '/user:/ { print $2 }' "$gh_hosts") GITHUB_TOKEN=$(awk '/oauth_token:/ { print $2 }' "$gh_hosts") fi if [[ -z "$JENKINS_USERNAME" || -z "$JENKINS_API_TOKEN" ]]; then echo " JENKINS_USERNAME or JENKINS_API_TOKEN is missing from env. To create a TOKEN, browse to https://jenkins.scylladb.com, then click on your username (upper right corner) and go to the Security tab. Click on Add new token and set the JENKINS_USERNAME and JENKINS_API_TOKEN environment variables accordingly. " exit 1 fi for required in jq curl; do if ! type $required >& /dev/null; then echo Please install $required first exit 1 fi done ALLOW_SUBMODULE=0 ALLOW_UNSTABLE=0 ALLOW_ANY_BRANCH=0 function print_usage { cat << EOF Usage: ${0} [options] PR_NUMBER Script for pulling and merging a pull request. Fetches the PR locally and merges it into current branch. The branch must be named next*. PR with a single commit in it is cherry-picked and thus the merge commit is not created and the PR description is lost. By default, doesn't merge PR that contains a submodule update, use --allow-submodule option to proceed. Options: -h Print this help message and exit. --allow-submodule Allow a PR to update a submudule --allow-unstable Do not check jenkins job status --allow-any-branch Merge PR even if target branch is not next --force Sets all above --allow-* options EOF } while [[ $# -gt 0 ]] do case $1 in "--force"|"-f") ALLOW_UNSTABLE=1 ALLOW_SUBMODULE=1 ALLOW_ANY_BRANCH=1 shift 1 ;; --allow-submodule) ALLOW_SUBMODULE=1 shift ;; --allow-unstable) ALLOW_UNSTABLE=1 shift ;; --allow-any-branch) ALLOW_ANY_BRANCH=1 shift ;; +([0-9])) PR_NUM=$1 shift 1 ;; "-h") print_usage exit 0 ;; *) echo "error: unrecognized option: $1, see $0 -h for usage" >&2 exit 1 ;; esac done if [ -z "$PR_NUM" ]; then echo Please provide a github pull request number exit 1 fi curl() { local opts=() if [[ -n "$GITHUB_LOGIN" && -n "$GITHUB_TOKEN" ]]; then opts+=(--user "${GITHUB_LOGIN}:${GITHUB_TOKEN}") fi command curl "${opts[@]}" "$@" } set_jenkins_job() { branch=$(git rev-parse --abbrev-ref HEAD) version="${branch#next-}" product=$(awk -F'=' '/^PRODUCT/ {print $2}'