Repository navigation
54 lines (48 loc) · 1.83 KB
/
Copy pathcomment.yml
File metadata and controls
54 lines (48 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
name: Post a comment
on:
workflow_run:
workflows:
- Check for Duplicated Code
- Check for linter warnings / exceptions
- Check adapter naming conventions
- Build metadata
types:
- completed
permissions:
contents: read
pull-requests: write
issues: write
jobs:
comment:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
with:
ref: master
- name: Retrieve comment data
id: get-comment
uses: ./.github/actions/unzip-artifact
with:
name: comment
- name: 'Comment on PR'
if: ${{ steps.get-comment.outputs.exists == 'true' }}
uses: actions/github-script@v9
with:
script: |
const fs = require('fs');
const path = require('path');
const temp = '${{ runner.temp }}/artifacts';
let {issue_number, body} = JSON.parse(fs.readFileSync(path.join(temp, 'comment.json')));
const whoami = 'github-actions[bot]';
const tag = `<!-- Workflow: "${{ github.event.workflow_run.name }}" -->`;
body = body + '\n' + tag;
const request = (args) => Object.assign({owner: context.repo.owner, repo: context.repo.repo}, args);
const previousComment = (await github.rest.issues.listComments(request({issue_number, per_page: 100})))
.data
.find(comment => comment.user.login === whoami && comment.body.includes(tag));
if (previousComment == null ) {
await github.rest.issues.createComment(request({issue_number, body}));
} else if (previousComment.body !== body) {
await github.rest.issues.updateComment(request({comment_id: previousComment.id, body}));
}