#!/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" ORANGE='\033[0;33m' NC='\033[0m' PR_NUM="" CI_STABLE=true VALID_REF=true IGNORE_CI=false IGNORE_REF_CHECK=false while [[ $# -gt 0 ]]; do case "$1" in --force) IGNORE_REF_CHECK=true IGNORE_CI=true shift ;; --ignore-ci) IGNORE_CI=true shift ;; --ignore-ref-check) IGNORE_REF_CHECK=true shift ;; # Check if the argument is a number [0-9]*) if [[ -z "$PR_NUM" ]]; then PR_NUM="$1" else echo "Error: Multiple numbers provided." exit 1 fi shift ;; *) echo "Error: Invalid flag or argument: $1" exit 1 ;; esac done if [[ -z "$PR_NUM" ]]; then echo "Error: Number is required." exit 1 fi 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 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}'