Skip to content

Commit a694885

Browse files
committed
Fix comment parsing issue - improve PR list extraction and prevent duplicate headers
1 parent f270d55 commit a694885

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

.github/workflows/issue_comp_link-issue-to-pr.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,16 @@ jobs:
168168
# Get existing PR list from the comment if it exists
169169
if [[ -n "$existing_comment" && "$existing_comment" != "null" ]]; then
170170
existing_body=$(echo "$comments" | jq -r --arg id "$existing_comment" '.[] | select(.id == ($id | tonumber)) | .body')
171-
pr_list=$(echo "$existing_body" | grep -o "- \[.*\](.*).*" | sort -u)
171+
172+
# Extract existing PR lines (lines starting with "- [")
173+
existing_pr_lines=$(echo "$existing_body" | grep "^- \[" | sort -u)
172174
173175
# Check if current PR is already in the list
174-
if echo "$pr_list" | grep -q "$pr_url"; then
175-
echo "PR already exists in comment, using existing list"
176+
if echo "$existing_pr_lines" | grep -q "$pr_url"; then
177+
echo "PR already exists in comment, keeping existing list"
176178
{
177179
echo "pr_list<<EOF"
178-
echo "$existing_body"
180+
printf "## PRs linked to this issue\n\n%s" "$existing_pr_lines"
179181
echo "EOF"
180182
} >> "$GITHUB_OUTPUT"
181183
else
@@ -185,8 +187,9 @@ jobs:
185187
new_pr_line="$new_pr_line ✅"
186188
fi
187189
188-
updated_list=$(echo -e "$pr_list\n$new_pr_line" | sort -u)
189-
new_body=$(printf "## PRs linked to this issue\n\n%s" "$updated_list")
190+
# Combine existing and new PR lines
191+
all_pr_lines=$(echo -e "$existing_pr_lines\n$new_pr_line" | sort -u)
192+
new_body=$(printf "## PRs linked to this issue\n\n%s" "$all_pr_lines")
190193
{
191194
echo "pr_list<<EOF"
192195
echo "$new_body"

0 commit comments

Comments
 (0)