Skip to content

Commit fdac66e

Browse files
committed
Add feature to remove failure comment when issue is resolved
1 parent 8f6afa1 commit fdac66e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,36 @@ jobs:
259259
echo "Issue #$issue_number already referenced in PR #$pr_number body"
260260
fi
261261
262+
- name: Remove failure comment if issue is now resolved
263+
run: |
264+
pr_url="${{ inputs.pr_url }}"
265+
pr_number=$(echo "$pr_url" | grep -o '[0-9]*$')
266+
267+
# Check for existing failure comment
268+
existing_comments=$(curl -s \
269+
-H "Accept: application/vnd.github+json" \
270+
-H "Authorization: Bearer ${{ env.GH_TOKEN }}" \
271+
-H "X-GitHub-Api-Version: 2022-11-28" \
272+
"https://api.github.com/repos/${{ github.repository }}/issues/$pr_number/comments")
273+
274+
# Find failure comment by looking for the distinctive header
275+
failure_comment_id=$(echo "$existing_comments" | jq -r '.[] | select(.user.login == "github-actions[bot]" and (.body | contains("❌ Issue Linking Required"))) | .id' | head -1)
276+
277+
if [[ -n "$failure_comment_id" && "$failure_comment_id" != "null" ]]; then
278+
echo "Found existing failure comment: $failure_comment_id"
279+
280+
# Delete the failure comment since the issue is now resolved
281+
curl -X DELETE \
282+
-H "Accept: application/vnd.github+json" \
283+
-H "Authorization: Bearer ${{ env.GH_TOKEN }}" \
284+
-H "X-GitHub-Api-Version: 2022-11-28" \
285+
"https://api.github.com/repos/${{ github.repository }}/issues/comments/$failure_comment_id"
286+
287+
echo "Removed failure comment from PR #$pr_number (issue now resolved)"
288+
else
289+
echo "No failure comment found to remove"
290+
fi
291+
262292
- name: Add failure comment to PR
263293
if: failure() && steps.determine_issue.outputs.failure_detected == 'true'
264294
run: |

0 commit comments

Comments
 (0)