Skip to content

Auto Label PR

Auto Label PR #714

Workflow file for this run

name: Auto Label PR
on:
workflow_run:
workflows: ["Code Formatting & Lint Validation"]
types:
- completed
permissions:
pull-requests: write
issues: write
jobs:
evaluate-and-writeback:
runs-on: ubuntu-latest
if: github.actor != 'copybara-service[bot]'
steps:
- name: Process Verification Outcome & Manage Dialogue
uses: actions/github-script@v8
with:
script: |
const pulls = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
});
const pr = pulls.data.find(p => p.head.sha === context.payload.workflow_run.head_sha);
if (!pr) {
console.log('No matching open PR found for head sha.');
return;
}
const issue_number = pr.number;
const conclusion = context.payload.workflow_run.conclusion;
if (conclusion === 'failure') {
console.log('Lint workflow failed. Posting guidance advice comment.');
await github.rest.issues.createComment({
issue_number: issue_number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '👋 Hello! Thank you for your contribution. Unfortunately, our pre-commit lint and style validation checks failed. In order for our internal review bots to import and process your Pull Request, please verify your code adheres to our formatting guidelines by running `pre-commit run --files $(git diff --name-only origin/main)` locally and pushing the adjustments. See [`CONTRIBUTING.md`](https://github.com/google/orbax/blob/main/CONTRIBUTING.md) for full instructions.'
});
return;
}
if (conclusion === 'success') {
console.log('Lint workflow succeeded. Cleaning up old failure comments and marking pull ready.');
const comments = await github.rest.issues.listComments({
issue_number: issue_number,
owner: context.repo.owner,
repo: context.repo.repo,
});
// Clean up past lint failure comments
for (const comment of comments.data) {
if (comment.user.type === 'Bot' && comment.body.includes('pre-commit lint and style validation checks failed')) {
await github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment.id,
});
}
}
if (!pr.labels.some(label => label.name === 'pull ready')) {
await github.rest.issues.addLabels({
issue_number: issue_number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['pull ready']
});
}
}