Skip to content

Commit 0424969

Browse files
fix(ci): Fix duplicate PR check comments (#7894)
1 parent 7680873 commit 0424969

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

.github/workflows/check-pull-requests.yaml

+29-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Check pull requests
22
on:
33
pull_request:
4-
types: [opened, reopened, edited, labeled, unlabeled]
4+
types: [opened, edited, labeled, unlabeled]
55
branches:
66
- master
77
- release/v*
@@ -40,14 +40,36 @@ jobs:
4040
}
4141
// Add comment to the pull request
4242
if (labelsCheckFailed || titleCheckFailed) {
43-
await github.rest.issues.createComment({
44-
issue_number: context.payload.pull_request.number,
45-
owner: context.repo.owner,
46-
repo: context.repo.repo,
47-
body: 'Hi! 👋 Thanks for your pull request! 🎉\n\n' +
43+
// Define comment body
44+
const commentMarker = '<!-- dd-trace-java-check-pull-requests-workflow -->'
45+
const commentBody = 'Hi! 👋 Thanks for your pull request! 🎉\n\n' +
4846
'To help us review it, please make sure to:\n\n' +
4947
(labelsCheckFailed ? '* Add at least one type, and one component or instrumentation label to the pull request\n' : '') +
5048
(titleCheckFailed ? '* Remove the tag from the pull request title\n' : '') +
51-
'\nIf you need help, please check our [contributing guidelines](https://github.com/DataDog/dd-trace-java/blob/master/CONTRIBUTING.md).'
49+
'\nIf you need help, please check our [contributing guidelines](https://github.com/DataDog/dd-trace-java/blob/master/CONTRIBUTING.md).' +
50+
'\n\n' + commentMarker
51+
// Look for previous comment
52+
const comments = await github.rest.issues.listComments({
53+
issue_number: context.payload.pull_request.number,
54+
owner: context.repo.owner,
55+
repo: context.repo.repo
5256
})
57+
const previousComment = comments.data.find(comment => comment.body.includes(commentMarker))
58+
if (previousComment) {
59+
// Update previous comment
60+
await github.rest.issues.updateComment({
61+
comment_id: previousComment.id,
62+
owner: context.repo.owner,
63+
repo: context.repo.repo,
64+
body: commentBody
65+
})
66+
} else {
67+
// Create new comment
68+
await github.rest.issues.createComment({
69+
issue_number: context.payload.pull_request.number,
70+
owner: context.repo.owner,
71+
repo: context.repo.repo,
72+
body: commentBody
73+
})
74+
}
5375
}

0 commit comments

Comments
 (0)