#!/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 configure. 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 FORCE=0 ALLOW_SUBMODULE=0 while [[ $# -gt 0 ]] do case $1 in "--force"|"-f") FORCE=1 shift 1 ;; --allow-submodule) ALLOW_SUBMODULE=1 shift ;; +([0-9])) PR_NUM=$1 shift 1 ;; *) 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}'