From bef015da0dd1408fc3d49e6953d8e3fc06af79b7 Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Mon, 18 Nov 2024 12:29:22 +0200 Subject: [PATCH] Revert ".github/scripts/auto-backport.py: validate backport candidate with `Fixes` prefix" This reverts commit 8414cd743e731fdbef5cddeb8ba44ad14ba0821a. It prevents pulling pull requests that do have "Fixes" references. --- .github/scripts/auto-backport.py | 16 ------- scripts/pull_github_pr.sh | 72 +++++--------------------------- 2 files changed, 10 insertions(+), 78 deletions(-) diff --git a/.github/scripts/auto-backport.py b/.github/scripts/auto-backport.py index 85efd9ee02..d0b255fcc4 100755 --- a/.github/scripts/auto-backport.py +++ b/.github/scripts/auto-backport.py @@ -129,20 +129,6 @@ def backport(repo, pr, version, commits, backport_base_branch): logging.warning(f"GitCommandError: {e}") -def with_github_keyword_prefix(repo, pr): - pattern = rf"(?:fix(?:|es|ed))\s*:?\s*(?:(?:(?:{repo.full_name})?#)|https://github\.com/{repo.full_name}/issues/)(\d+)" - match = re.findall(pattern, pr.body, re.IGNORECASE) - if not match: - print(f'No valid close reference for {pr.number}') - comment = f':warning: @{pr.user.login} PR body does not contain a Fixes reference to an issue ' - comment += ' and can not be backported\n\n' - comment += 'The following labels were removed:\n' - create_pr_comment_and_remove_label(pr, comment) - return False - else: - return True - - def main(): args = parse_args() base_branch = args.base_branch.split('/')[2] @@ -183,8 +169,6 @@ def main(): if not backport_labels: print(f'no backport label: {pr.number}') continue - if args.commits and not with_github_keyword_prefix(repo, pr): - continue commits = get_pr_commits(repo, pr, stable_branch, start_commit) logging.info(f"Found PR #{pr.number} with commit {commits} and the following labels: {backport_labels}") for backport_label in backport_labels: diff --git a/scripts/pull_github_pr.sh b/scripts/pull_github_pr.sh index 12dffebeef..b247794312 100755 --- a/scripts/pull_github_pr.sh +++ b/scripts/pull_github_pr.sh @@ -11,52 +11,10 @@ set -e gh_hosts=~/.config/gh/hosts.yml jenkins_url="https://jenkins.scylladb.com" +FORCE=$2 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") @@ -70,6 +28,11 @@ if [[ -z "$JENKINS_USERNAME" || -z "$JENKINS_API_TOKEN" ]]; then 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 @@ -101,6 +64,7 @@ set_jenkins_job() { next-enterprise) jenkins_job="scylla-enterprise/job/next";; next*) jenkins_job="$folder_prefix-$version/job/next";; *) echo "You are running the script from branch: $branch. Valid branches: next|next-enterprise|next-*" + exit 1 esac } @@ -118,17 +82,17 @@ check_jenkins_job_status() { if [[ "$lastCompleted" == "SUCCESS" ]]; then echo "$lastCompletedJobName is stable" else - echo -e "${ORANGE}WARNING:${NC} $lastCompletedJobName is not stable, To override run pull_github_pr.sh with --ignore-ci" - CI_STABLE=false + echo -e "${ORANGE}WARNING:${NC} $lastCompletedJobName is not stable" fi } -if [[ "${IGNORE_CI}" == "false" ]]; then +if [[ "$FORCE" != "--force" ]]; then check_jenkins_job_status fi NL=$'\n' +PR_NUM=$1 # convert full repo URL to its project/repo part, in case of failure default to origin/master: REMOTE_SLASH_BRANCH="$(git rev-parse --abbrev-ref --symbolic-full-name @{upstream} \ || git rev-parse --abbrev-ref --symbolic-full-name master@{upstream} \ @@ -140,22 +104,6 @@ PR_PREFIX=https://api.github.com/repos/$PROJECT/pulls echo "Fetching info on PR #$PR_NUM... " PR_DATA=$(curl -s $PR_PREFIX/$PR_NUM) -PR_LABELS=$(jq -r .labels[].name <<< "$PR_DATA") -PR_BODY=$(jq -r .body <<< "$PR_DATA") - -if [[ "${IGNORE_REF_CHECK}" == "false" ]]; then - if echo "$PR_LABELS" | grep -qE "^backport/[0-9]+\.[0-9]+$"; then - if [[ ! "$PR_BODY" =~ [Ff]ix|[Ff]ixes|[Ff]ixed ]]; then - echo -e "${ORANGE}\nWARNING:${NC} ${PR_NUM} is a candidate for backport but doesn't contain any Fixes reference to an issue. To override run pull_github_pr.sh with --ignore-ref-check" - VALID_REF=false - fi - fi -fi - -if [ "${VALID_REF}" == "false" ] || [ "${CI_STABLE}" == "false" ]; then - exit 1 -fi - MESSAGE=$(jq -r .message <<< $PR_DATA) if [ "$MESSAGE" != null ] then