|
1 | 1 | name: Check pull requests
|
2 | 2 | on:
|
3 | 3 | pull_request:
|
4 |
| - types: [opened, reopened, edited, labeled, unlabeled] |
| 4 | + types: [opened, edited, labeled, unlabeled] |
5 | 5 | branches:
|
6 | 6 | - master
|
7 | 7 | - release/v*
|
@@ -40,14 +40,36 @@ jobs:
|
40 | 40 | }
|
41 | 41 | // Add comment to the pull request
|
42 | 42 | 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' + |
48 | 46 | 'To help us review it, please make sure to:\n\n' +
|
49 | 47 | (labelsCheckFailed ? '* Add at least one type, and one component or instrumentation label to the pull request\n' : '') +
|
50 | 48 | (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 |
52 | 56 | })
|
| 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 | + } |
53 | 75 | }
|
0 commit comments