Repository navigation
68 lines (58 loc) · 2.27 KB
/
Copy pathpr-comment.yml
File metadata and controls
68 lines (58 loc) · 2.27 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# .github/workflows/pr-comment.yml
name: PR Status Comment
on:
pull_request_target:
types: [opened, synchronize, reopened]
permissions:
contents: read
issues: write
pull-requests: write
checks: read
concurrency:
group: pr-comment-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
comment:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Post or update status comment
uses: actions/github-script@v8
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const pr = context.payload.pull_request;
const sha = pr.head.sha;
// Retry a few times in case checks are still running
async function getCompletedQuickChecks(maxTries = 6, delayMs = 10000) {
for (let i = 0; i < maxTries; i++) {
const { data } = await github.rest.checks.listForRef({ owner, repo, ref: sha });
const run = data.check_runs.find(r => r.name === 'Quick Checks');
if (run && run.status === 'completed') return run;
await new Promise(r => setTimeout(r, delayMs));
}
return null;
}
const run = await getCompletedQuickChecks();
if (!run) {
core.info('No completed "Quick Checks" run found. Skipping comment.');
return;
}
const outcome = run.conclusion; // success | failure | neutral | cancelled | timed_out | action_required | stale | skipped
const message = `${outcome === 'success' ? '✅' : '❌'} Quick checks ${outcome}`;
const { data: comments } = await github.rest.issues.listComments({
owner, repo, issue_number: pr.number,
});
const botComment = comments.find(c =>
c.user.type === 'Bot' && /Quick checks/.test(c.body)
);
if (botComment) {
await github.rest.issues.updateComment({
owner, repo, comment_id: botComment.id, body: message
});
} else {
await github.rest.issues.createComment({
owner, repo, issue_number: pr.number, body: message
});
}