-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into typevar2
- Loading branch information
Showing
885 changed files
with
39,590 additions
and
12,979 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 |
---|---|---|
@@ -1,104 +1,99 @@ | ||
name: Comment with mypy_primer diff | ||
|
||
on: | ||
# pull_request_target gives us access to a write token which we need to post a comment | ||
# The presence of a write token means that we can't run any untrusted code (i.e. malicious PRs), | ||
# which is why this its own workflow. Github Actions doesn't make it easy for workflows to talk to | ||
# each other, so the approach here is to poll for workflow runs, find the mypy_primer run for our | ||
# commit, wait till it's completed, and download and post the diff. | ||
pull_request_target: | ||
paths-ignore: | ||
- 'docs/**' | ||
- '**/*.rst' | ||
- '**/*.md' | ||
- 'mypyc/**' | ||
workflow_run: | ||
workflows: | ||
- Run mypy_primer | ||
types: | ||
- completed | ||
|
||
permissions: | ||
contents: read | ||
pull-requests: write | ||
|
||
jobs: | ||
mypy_primer: | ||
name: Comment | ||
comment: | ||
name: Comment PR from mypy_primer | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Install dependencies | ||
run: npm install adm-zip | ||
- name: Post comment | ||
- name: Download diffs | ||
uses: actions/github-script@v3 | ||
with: | ||
github-token: ${{secrets.GITHUB_TOKEN}} | ||
script: | | ||
const AdmZip = require(`${process.env.GITHUB_WORKSPACE}/node_modules/adm-zip`) | ||
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"); | ||
// Because of pull_request_target, context.sha is the PR base branch | ||
// So we need to ask Github for the SHA of the PR's head commit | ||
const pull_request = await github.pulls.get({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
pull_number: context.issue.number, | ||
}) | ||
const pr_commit_sha = pull_request.data.head.sha | ||
console.log("Looking for mypy_primer run for commit:", pr_commit_sha) | ||
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)); | ||
// Find the mypy_primer run for our commit and wait till it's completed | ||
// We wait up to an hour before timing out | ||
async function check_mypy_primer() { | ||
// We're only looking at the first page, so in theory if we open enough PRs around | ||
// the same time, this will fail to find the run. | ||
const response = await github.actions.listWorkflowRuns({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
workflow_id: "mypy_primer.yml", | ||
}) | ||
if (response) { | ||
return response.data.workflow_runs.find(run => run.head_sha == pr_commit_sha) | ||
} | ||
return undefined | ||
} | ||
- run: unzip diff.zip | ||
|
||
const end_time = Number(new Date()) + 60 * 60 * 1000 | ||
let primer_run = await check_mypy_primer() | ||
while (!primer_run || primer_run.status != "completed") { | ||
if (Number(new Date()) > end_time) { | ||
throw Error("Timed out waiting for mypy_primer") | ||
} | ||
console.log("Waiting for mypy_primer to complete...") | ||
await new Promise(r => setTimeout(r, 10000)) | ||
primer_run = await check_mypy_primer() | ||
} | ||
console.log("Found mypy_primer run!") | ||
console.log(primer_run) | ||
# 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') | ||
// Download artifact(s) from the run | ||
const artifacts = await github.actions.listWorkflowRunArtifacts({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
run_id: primer_run.id, | ||
const response = await github.issues.listComments({ | ||
issue_number: fs.readFileSync("pr_number.txt", { encoding: "utf8" }), | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
}) | ||
const filtered_artifacts = artifacts.data.artifacts.filter( | ||
a => a.name.startsWith("mypy_primer_diff") | ||
) | ||
console.log("Artifacts from mypy_primer:") | ||
console.log(filtered_artifacts) | ||
const botCommentIds = response.data | ||
.filter(comment => comment.user.login === 'github-actions[bot]') | ||
.map(comment => comment.node_id) | ||
async function get_artifact_data(artifact) { | ||
const zip = await github.actions.downloadArtifact({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
artifact_id: artifact.id, | ||
archive_format: "zip", | ||
}) | ||
const adm = new AdmZip(Buffer.from(zip.data)) | ||
return adm.readAsText(adm.getEntry("diff.txt")) | ||
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) | ||
} | ||
} | ||
const all_data = await Promise.all(filtered_artifacts.map(get_artifact_data)) | ||
const data = all_data.join("\n") | ||
- 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: context.issue.number, | ||
issue_number: fs.readFileSync("pr_number.txt", { encoding: "utf8" }), | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
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 + '```' | ||
body | ||
}) | ||
} |
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
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
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
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 |
---|---|---|
@@ -1,4 +1,2 @@ | ||
-r mypy-requirements.txt | ||
types-typed-ast>=1.4.0,<1.5.0 | ||
types-toml>=0.0 | ||
types-enum34>=0.0; python_version == '3.5' |
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
Oops, something went wrong.