Skip to content

Classify mypy_primer diff #149

Classify mypy_primer diff

Classify mypy_primer diff #149

name: Classify mypy_primer diff
on: # zizmor: ignore[dangerous-triggers]
workflow_run:
workflows:
- Run mypy_primer
types:
- completed
permissions: {}
jobs:
classify:
name: Classify primer diff
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- uses: actions/checkout@v6
with:
sparse-checkout: scripts/primer_classifier
persist-credentials: false
- uses: actions/setup-python@v6
with:
python-version: "3.13"
- name: Download diffs
uses: actions/github-script@v8
with:
script: |
const fs = require('fs');
const artifacts = await github.rest.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.rest.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
- run: cat diff_*.txt | tee fulldiff.txt
- name: Fetch PR code diff and description
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const prNumber = parseInt(fs.readFileSync("pr_number.txt", { encoding: "utf8" }));
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
const description = `# ${pr.title}\n\n${pr.body || ''}`;
fs.writeFileSync("pr_description.txt", description);
console.log(`Fetched PR #${prNumber} description (${description.length} chars)`);
const { data: diff } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
mediaType: { format: 'diff' },
});
fs.writeFileSync("pr_code.diff", diff);
console.log(`Fetched PR #${prNumber} diff (${diff.length} chars)`);
- name: Classify diff
run: |
python -m scripts.primer_classifier \
--diff-file fulldiff.txt \
--pyrefly-diff pr_code.diff \
--pr-description pr_description.txt \
--suggest \
--output-format markdown \
| tee classification.md
env:
CLASSIFIER_API_KEY: ${{ secrets.PRIMER_CLASSIFIER_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Post classification comment
if: ${{ hashFiles('classification.md') != '' }}
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs')
const body = fs.readFileSync('classification.md', { encoding: 'utf8' })
if (body.trim()) {
const prNumber = parseInt(fs.readFileSync("pr_number.txt", { encoding: "utf8" }))
await github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body
})
}