Repository navigation
60 lines (51 loc) · 1.78 KB
/
Copy pathfailure-comment.yml
File metadata and controls
60 lines (51 loc) · 1.78 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
name: Failure Comment (Formatter)
on:
workflow_run:
workflows: ["Formatter"]
types: [completed]
permissions:
pull-requests: write
jobs:
comment:
if: >
github.event.workflow_run.conclusion == 'failure'
&& github.event.workflow_run.event == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v9
with:
script: |
const run = context.payload.workflow_run;
let prNumber = run.pull_requests?.[0]?.number;
if (!prNumber) {
const { data: pulls } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
head: `${run.head_repository.owner.login}:${run.head_branch}`,
});
if (!pulls.length) {
console.log('No PR found for this workflow run');
return;
}
prNumber = pulls[0].number;
}
const body = `### Formatting check failed
Please run the formatter locally and commit the resulting changes:
\`\`\`sh
uv run black .
\`\`\``;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const existing = comments.find(c => c.user.type === 'Bot' && c.body.includes('Formatting check failed'));
if (!existing) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body,
});
}