#!/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 gh_hosts=~/.config/gh/hosts.yml jenkins_url="https://jenkins.scylladb.com" FORCE=$2 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 if [ -z "$1" ]; then echo Please provide a github pull request number exit 1 fi for required in jq curl; do if ! type $required >& /dev/null; then echo Please install $required first exit 1 fi done 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}'