forked from python/mypy
-
Notifications
You must be signed in to change notification settings - Fork 1
99 lines (88 loc) · 3.27 KB
/
mypy_primer_comment.yml
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: Comment with mypy_primer diff
on:
workflow_run:
workflows:
- Run mypy_primer
types:
- completed
permissions:
contents: read
pull-requests: write
jobs:
comment:
name: Comment PR from mypy_primer
runs-on: ubuntu-latest
steps:
- name: Download diffs
uses: actions/github-script@v3
with:
script: |
const fs = require('fs');
const artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});
const [matchArtifact] = artifacts.data.artifacts.filter((artifact) =>
artifact.name == "mypy_primer_diffs");
const download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: "zip",
});
fs.writeFileSync("diff.zip", Buffer.from(download.data));
- run: unzip diff.zip
# Based on https://github.com/kanga333/comment-hider
- name: Hide old comments
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs')
const response = await github.issues.listComments({
issue_number: fs.readFileSync("pr_number.txt", { encoding: "utf8" }),
owner: context.repo.owner,
repo: context.repo.repo,
})
const botCommentIds = response.data
.filter(comment => comment.user.login === 'github-actions[bot]')
.map(comment => comment.node_id)
for (const id of botCommentIds) {
const resp = await github.graphql(`
mutation {
minimizeComment(input: {classifier: OUTDATED, subjectId: "${id}"}) {
minimizedComment {
isMinimized
}
}
}
`)
if (resp.errors) {
throw new Error(resp.errors)
}
}
- name: Post comment
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs')
// Keep in sync with shards produced by mypy_primer workflow
const data = (
['diff_0.txt', 'diff_1.txt', 'diff_2.txt']
.map(fileName => fs.readFileSync(fileName, { encoding: 'utf8' }))
.join('')
.substr(0, 30000) // About 300 lines
)
console.log("Diff from mypy_primer:")
console.log(data)
if (data.trim()) {
const body = 'Diff from [mypy_primer](https://github.com/hauntsaninja/mypy_primer), showing the effect of this PR on open source code:\n```diff\n' + data + '```'
await github.issues.createComment({
issue_number: fs.readFileSync("pr_number.txt", { encoding: "utf8" }),
owner: context.repo.owner,
repo: context.repo.repo,
body
})
}