From b69113dadae6fccb34b661cbc8e9326f061fc09a Mon Sep 17 00:00:00 2001 From: Leonardo Cencetti <37414873+leocencetti@users.noreply.github.com> Date: Wed, 11 Sep 2024 15:02:12 +0200 Subject: [PATCH] fix: Comment on PR only if the XL label is new Signed-off-by: Leonardo Cencetti --- src/github.sh | 13 +++++++++++++ src/labeler.sh | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/github.sh b/src/github.sh index 25d9d9a..a44f89d 100644 --- a/src/github.sh +++ b/src/github.sh @@ -52,6 +52,19 @@ github::calculate_total_modifications() { echo $((additions + deletions)) } +github::has_label() { + local -r pr_number="${1}" + local -r label_to_check="${2}" + + local -r body=$(curl -sSL -H "Authorization: token $GITHUB_TOKEN" -H "$GITHUB_API_HEADER" "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/issues/$pr_number/labels") + for label in $(echo "$body" | jq -r '.[] | @base64'); do + if [ "$(echo ${label} | base64 -d | jq -r '.name')" = "$label_to_check" ]; then + return 0 + fi + done + return 1 +} + github::add_label_to_pr() { local -r pr_number="${1}" local -r label_to_add="${2}" diff --git a/src/labeler.sh b/src/labeler.sh index 5a86820..add76b0 100644 --- a/src/labeler.sh +++ b/src/labeler.sh @@ -25,7 +25,7 @@ labeler::label() { github::add_label_to_pr "$pr_number" "$label_to_add" "$xs_label" "$s_label" "$m_label" "$l_label" "$xl_label" if [ "$label_to_add" == "$xl_label" ]; then - if [ -n "$message_if_xl" ]; then + if [ -n "$message_if_xl" ] && ! github::has_label "$pr_number" "$label_to_add"; then github::comment "$message_if_xl" fi