@@ -22,10 +22,36 @@ jobs:
2222
2323 - name : Comment on PR
2424 if : contains(github.event.pull_request.head.ref, 'apm-') || contains(github.event.pull_request.head.ref, 'APM-') || contains(github.event.pull_request.head.ref, 'mesh-') || contains(github.event.pull_request.head.ref, 'MESH-') || contains(github.event.pull_request.head.ref, 'mesh2cloud-') || contains(github.event.pull_request.head.ref, 'MESH2CLOUD-') || contains(github.event.pull_request.head.ref, 'spii-') || contains(github.event.pull_request.head.ref, 'SPII-') || contains(github.event.pull_request.head.ref, 'spinecore-') || contains(github.event.pull_request.head.ref, 'SPINECORE-')
25- uses : unsplash/comment-on-pr@b5610c6125a7197eaec80072ea35ef53e1fc6035 # v1.3.1
26- env :
27- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
25+ uses : actions/github-script@v7
2826 with :
29- msg : |
30- This branch is work on a ticket in the NHS Digital AMB JIRA Project. Here's a handy link to the ticket:
31- # [${{ env.TICKET_NAME }}](https://jira.digital.nhs.uk/browse/${{ env.TICKET_NAME}})
27+ github-token : ${{ secrets.GITHUB_TOKEN }}
28+ script : |
29+ const marker = '<!-- jira-ticket-link -->';
30+ const body = `${marker}\nThis branch is work on a ticket in the NHS Digital AMB JIRA Project. Here's a handy link to the ticket:\n# [${process.env.TICKET_NAME}](https://jira.digital.nhs.uk/browse/${process.env.TICKET_NAME})`;
31+
32+ const { data: comments } = await github.rest.issues.listComments({
33+ owner: context.repo.owner,
34+ repo: context.repo.repo,
35+ issue_number: context.issue.number,
36+ per_page: 100,
37+ });
38+
39+ const existing = comments.find((comment) =>
40+ comment.user?.type === 'Bot' && comment.body?.includes(marker)
41+ );
42+
43+ if (existing) {
44+ await github.rest.issues.updateComment({
45+ owner: context.repo.owner,
46+ repo: context.repo.repo,
47+ comment_id: existing.id,
48+ body,
49+ });
50+ } else {
51+ await github.rest.issues.createComment({
52+ owner: context.repo.owner,
53+ repo: context.repo.repo,
54+ issue_number: context.issue.number,
55+ body,
56+ });
57+ }
0 commit comments