diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 05a75ca5f..81d448f25 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,6 +1,7 @@ _Please read the [contributing guidelines](https://github.com/blakeblackshear/frigate/blob/dev/CONTRIBUTING.md) before submitting a PR._ ## Proposed change + \s*)?([\s\S]*?)(?=\n## )/ + ); + const proposedContent = proposedChangeMatch + ? proposedChangeMatch[1].trim() + : ''; + if (!proposedContent) { + errors.push( + 'The **Proposed change** section is empty. Please describe what this PR does.' + ); + } + + // Check that at least one "Type of change" checkbox is checked + const typeSection = body.match( + /## Type of change\s*([\s\S]*?)(?=\n## )/ + ); + if (typeSection && !/- \[x\]/i.test(typeSection[1])) { + errors.push( + 'No **Type of change** selected. Please check at least one option.' + ); + } + + // Check that at least one AI disclosure checkbox is checked + const aiSection = body.match( + /## AI disclosure\s*([\s\S]*?)(?=\n## )/ + ); + if (aiSection && !/- \[x\]/i.test(aiSection[1])) { + errors.push( + 'No **AI disclosure** option selected. Please indicate whether AI tools were used.' + ); + } + + // Check that at least one checklist item is checked + const checklistSection = body.match( + /## Checklist\s*([\s\S]*?)$/ + ); + if (checklistSection && !/- \[x\]/i.test(checklistSection[1])) { + errors.push( + 'No **Checklist** items checked. Please review and check the items that apply.' + ); + } + + if (errors.length === 0) { + console.log('PR description passes template validation.'); + return; + } + + const prNumber = context.payload.pull_request.number; + const message = [ + '## PR template validation failed', + '', + 'This PR was automatically closed because the description does not follow the [pull request template](https://github.com/blakeblackshear/frigate/blob/dev/.github/pull_request_template.md).', + '', + '**Issues found:**', + ...errors.map((e) => `- ${e}`), + '', + 'Please update your PR description to include all required sections from the template, then reopen this PR.', + '', + '> If you used an AI tool to generate this PR, please see our [contributing guidelines](https://github.com/blakeblackshear/frigate/blob/dev/CONTRIBUTING.md) for details.', + ].join('\n'); + + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body: message, + }); + + await github.rest.pulls.update({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: prNumber, + state: 'closed', + }); + + core.setFailed('PR description does not follow the template.');