From a420b46913758d30360adeacbbad3f324f576a28 Mon Sep 17 00:00:00 2001 From: Alexander Schwartz Date: Thu, 21 Dec 2023 13:49:07 +0100 Subject: [PATCH] Adding parsing of "fixes"/"fixed" Keyword and the colon (#25634) Closes #25633 Signed-off-by: Alexander Schwartz --- .github/scripts/pr-find-issues-test.sh | 24 ++++++++++++++++++++ .github/scripts/pr-find-issues.sh | 31 +++++++++++++------------- 2 files changed, 40 insertions(+), 15 deletions(-) create mode 100755 .github/scripts/pr-find-issues-test.sh diff --git a/.github/scripts/pr-find-issues-test.sh b/.github/scripts/pr-find-issues-test.sh new file mode 100755 index 00000000000..705d8adcc4a --- /dev/null +++ b/.github/scripts/pr-find-issues-test.sh @@ -0,0 +1,24 @@ +#!/bin/bash -e +# Use this script to test different variants of a PR body. + +source ./pr-find-issues.sh + +function testParsing() { + echo -n "$1 -> $2 " + if [ $(parse_issues "$1") != "$2" ]; then + echo "(failure)" + return 1 + fi + echo "(success)" + return 0 +} + +function testFailed() { + echo "Test Failed!" +} + +trap 'testFailed' ERR + +testParsing "Closes #123" "123" +testParsing "Fixes #123" "123" +testParsing "Fixes: #123" "123" diff --git a/.github/scripts/pr-find-issues.sh b/.github/scripts/pr-find-issues.sh index 389b716c01c..c91ccd85dce 100755 --- a/.github/scripts/pr-find-issues.sh +++ b/.github/scripts/pr-find-issues.sh @@ -4,26 +4,27 @@ PR="$1" REPO="$2" if [ "$REPO" == "" ]; then - REPO="keycloak/keycloak" + REPO="keycloak/keycloak" fi function parse_issues() { - echo "$1" | grep -i -P -o "(close|closes|closed|resolve|resolves|resolved) #[[:digit:]]*" | cut -d '#' -f 2 | sort -n + echo "$1" | grep -i -P -o "(close|closes|closed|resolve|resolves|resolved|fixes|fixed):? #[[:digit:]]*" | cut -d '#' -f 2 | sort -n } -PR_JSON=$(gh api "/repos/$REPO/pulls/$PR") -PR_BODY=$(echo "$PR_JSON" | jq -r .body) -PR_MERGE_COMMIT_SHA=$(echo "$PR_JSON" | jq -r .merge_commit_sha) +if [ "$PR" != "" ]; then + PR_JSON=$(gh api "/repos/$REPO/pulls/$PR") + PR_BODY=$(echo "$PR_JSON" | jq -r .body) + PR_MERGE_COMMIT_SHA=$(echo "$PR_JSON" | jq -r .merge_commit_sha) -ISSUES=$(parse_issues "$PR_BODY") -if [ "$ISSUES" == "" ]; then - COMMIT_JSON=$(gh api "/repos/$REPO/commits/$PR_MERGE_COMMIT_SHA") - COMMIT_MESSAGE=$(echo "$COMMIT_JSON" | jq -r .commit.message) + ISSUES=$(parse_issues "$PR_BODY") + if [ "$ISSUES" == "" ]; then + COMMIT_JSON=$(gh api "/repos/$REPO/commits/$PR_MERGE_COMMIT_SHA") + COMMIT_MESSAGE=$(echo "$COMMIT_JSON" | jq -r .commit.message) - ISSUES=$(parse_issues "$COMMIT_MESSAGE") + ISSUES=$(parse_issues "$COMMIT_MESSAGE") + fi + + for i in $ISSUES; do + echo "$i" + done fi - -for i in $ISSUES; do - echo "$i" -done -