-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port over latest GA mypy_primer changes (#10505)
This is mostly the same as typeshed. The biggest difference is that we don't post the "no effect" message. As a side effect, we also have to run the comment hider first. Co-authored-by: hauntsaninja <> Co-authored-by: Akuli <[email protected]>
- Loading branch information
1 parent
1e220b1
commit c3a600b
Showing
2 changed files
with
107 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
}) | ||
} |