Skip to content

Commit 2f1c419

Browse files
authored
fix: Comment on PR only if the XL label is new (#83)
Signed-off-by: Leonardo Cencetti <cencetti.leonardo@gmail.com>
1 parent c7a55a0 commit 2f1c419

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/github.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ github::calculate_total_modifications() {
5252
echo $((additions + deletions))
5353
}
5454

55+
github::has_label() {
56+
local -r pr_number="${1}"
57+
local -r label_to_check="${2}"
58+
59+
local -r body=$(curl -sSL -H "Authorization: token $GITHUB_TOKEN" -H "$GITHUB_API_HEADER" "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/issues/$pr_number/labels")
60+
for label in $(echo "$body" | jq -r '.[] | @base64'); do
61+
if [ "$(echo ${label} | base64 -d | jq -r '.name')" = "$label_to_check" ]; then
62+
return 0
63+
fi
64+
done
65+
return 1
66+
}
67+
5568
github::add_label_to_pr() {
5669
local -r pr_number="${1}"
5770
local -r label_to_add="${2}"

src/labeler.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ labeler::label() {
2525
github::add_label_to_pr "$pr_number" "$label_to_add" "$xs_label" "$s_label" "$m_label" "$l_label" "$xl_label"
2626

2727
if [ "$label_to_add" == "$xl_label" ]; then
28-
if [ -n "$message_if_xl" ]; then
28+
if [ -n "$message_if_xl" ] && ! github::has_label "$pr_number" "$label_to_add"; then
2929
github::comment "$message_if_xl"
3030
fi
3131

0 commit comments

Comments
 (0)