|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| name: PR Template Check
|
|
|
| on:
|
| pull_request_target:
|
| types: [opened]
|
|
|
| permissions:
|
| pull-requests: write
|
| issues: write
|
| statuses: write
|
|
|
| jobs:
|
| check-pr-template:
|
| runs-on: ubuntu-latest
|
| if: >
|
| github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR' ||
|
| github.event.pull_request.author_association == 'FIRST_TIMER' ||
|
| github.event.pull_request.author_association == 'NONE'
|
| steps:
|
| - name: Check PR body follows template
|
| id: check
|
| uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b
|
| env:
|
| PR_BODY: ${{ github.event.pull_request.body }}
|
| with:
|
| script: |
|
| const body = process.env.PR_BODY || "";
|
|
|
| const errors = [];
|
|
|
| // 1. Must have a non-placeholder description (the "What does this PR do?" section)
|
| const descriptionSection = body.split("## Before submitting")[0] || "";
|
| const strippedDescription = descriptionSection
|
| .replace(/<!--[\s\S]*?-->/g, "") // remove HTML comments
|
| .replace(/Fixes\s*#\s*\(issue\)/gi, "") // remove placeholder issue line
|
| .trim();
|
|
|
| if (strippedDescription.length < 20) {
|
| errors.push("- Missing PR description: please explain what this PR does and why.");
|
| }
|
|
|
| // 2. Must have the "Before submitting" checklist
|
| if (!body.includes("## Before submitting")) {
|
| errors.push("- Missing '## Before submitting' checklist section.");
|
| }
|
|
|
| // 3. At least one checkbox must be checked
|
| const checkedBoxes = (body.match(/- \[x\]/gi) || []).length;
|
| if (checkedBoxes === 0) {
|
| errors.push("- No checkboxes are checked in the 'Before submitting' section. Please review and check the relevant items.");
|
| }
|
|
|
| if (errors.length > 0) {
|
| const comment = "Your PR has been closed because it does not follow the required [PR template](https://github.com/huggingface/trl/blob/main/.github/PULL_REQUEST_TEMPLATE.md). Please open a new PR following the template. See [CONTRIBUTING.md](https://github.com/huggingface/trl/blob/main/CONTRIBUTING.md#submitting-a-pull-request-pr) for guidance.";
|
|
|
| await github.rest.issues.createComment({
|
| owner: context.repo.owner,
|
| repo: context.repo.repo,
|
| issue_number: context.payload.pull_request.number,
|
| body: comment,
|
| });
|
|
|
| await github.rest.pulls.update({
|
| owner: context.repo.owner,
|
| repo: context.repo.repo,
|
| pull_number: context.payload.pull_request.number,
|
| state: "closed",
|
| });
|
|
|
| core.setFailed("PR does not follow the required template.");
|
| } else {
|
| console.log("PR template check passed.");
|
| }
|
|
|