mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix(gha): consolidate PR check comments into single report (#66869)
This commit is contained in:
committed by
GitHub
parent
6f059e8259
commit
88044e6990
@@ -1,8 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const FOOTER =
|
||||
'\n\n---\nJoin us in our [chat room](https://discord.gg/PRyKn3Vbay) or our [forum](https://forum.freecodecamp.org/c/contributors/3) if you have any questions or need help with contributing.';
|
||||
|
||||
async function addDeprioritizedLabel(github, context) {
|
||||
await github.rest.issues.addLabels({
|
||||
owner: context.repo.owner,
|
||||
@@ -12,16 +9,7 @@ async function addDeprioritizedLabel(github, context) {
|
||||
});
|
||||
}
|
||||
|
||||
async function addComment(github, context, body) {
|
||||
await github.rest.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: context.payload.pull_request.number,
|
||||
body
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = async ({ github, context, isAllowListed }) => {
|
||||
module.exports = async ({ github, context, core, isAllowListed }) => {
|
||||
if (isAllowListed === 'true') return;
|
||||
|
||||
const result = await github.graphql(
|
||||
@@ -51,20 +39,9 @@ module.exports = async ({ github, context, isAllowListed }) => {
|
||||
const linkedIssues = pr.closingIssuesReferences.nodes;
|
||||
|
||||
if (linkedIssues.length === 0) {
|
||||
core.setOutput('failure_reason', 'no_linked_issue');
|
||||
core.setFailed('No linked issue found.');
|
||||
await addDeprioritizedLabel(github, context);
|
||||
await addComment(
|
||||
github,
|
||||
context,
|
||||
[
|
||||
'Hi there,',
|
||||
'',
|
||||
'Thanks for opening this pull request.',
|
||||
'',
|
||||
'We kindly ask that contributors open an issue before submitting a PR so the change can be discussed and approved before work begins. This helps avoid situations where significant effort goes into something we ultimately cannot merge.',
|
||||
'',
|
||||
'Please open an issue first and allow it to be triaged. Once the issue is open for contribution, you are welcome to update this pull request to reflect the issue consensus. Until then, we will not be able to review your pull request.'
|
||||
].join('\n') + FOOTER
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -72,18 +49,9 @@ module.exports = async ({ github, context, isAllowListed }) => {
|
||||
issue.labels.nodes.some(l => l.name === 'status: waiting triage')
|
||||
);
|
||||
if (hasWaitingTriage) {
|
||||
core.setOutput('failure_reason', 'waiting_triage');
|
||||
core.setFailed('Linked issue has not been triaged yet.');
|
||||
await addDeprioritizedLabel(github, context);
|
||||
await addComment(
|
||||
github,
|
||||
context,
|
||||
[
|
||||
'Hi there,',
|
||||
'',
|
||||
'Thanks for opening this pull request.',
|
||||
'',
|
||||
'The linked issue has not been triaged yet, and a solution has not been agreed upon. Once the issue is open for contribution, you are welcome to update this pull request to reflect the issue consensus. Until then, we will not be able to review your pull request.'
|
||||
].join('\n') + FOOTER
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -109,17 +77,8 @@ module.exports = async ({ github, context, isAllowListed }) => {
|
||||
)
|
||||
);
|
||||
if (!isOpenForContribution) {
|
||||
core.setOutput('failure_reason', 'not_open_for_contribution');
|
||||
core.setFailed('Linked issue is not open for contribution.');
|
||||
await addDeprioritizedLabel(github, context);
|
||||
await addComment(
|
||||
github,
|
||||
context,
|
||||
[
|
||||
'Hi there,',
|
||||
'',
|
||||
'Thanks for opening this pull request.',
|
||||
'',
|
||||
'The linked issue is not open for contribution. If you are looking for issues to contribute to, please check out issues labeled [`help wanted`](https://github.com/freeCodeCamp/freeCodeCamp/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) or [`first timers only`](https://github.com/freeCodeCamp/freeCodeCamp/issues?q=is%3Aissue+is%3Aopen+label%3A%22first+timers+only%22).'
|
||||
].join('\n') + FOOTER
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,32 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
const FOOTER =
|
||||
'\n\n---\nJoin us in our [chat room](https://discord.gg/PRyKn3Vbay) or our [forum](https://forum.freecodecamp.org/c/contributors/3) if you have any questions or need help with contributing.';
|
||||
|
||||
const TEMPLATE_BLOCK = [
|
||||
'```md',
|
||||
'Checklist:',
|
||||
'',
|
||||
'<!-- Please follow this checklist and put an x in each of the boxes, like this: [x]. It will ensure that our team takes your pull request seriously. -->',
|
||||
'',
|
||||
'- [ ] I have read and followed the [contribution guidelines](https://contribute.freecodecamp.org).',
|
||||
'- [ ] I have read and followed the [how to open a pull request guide](https://contribute.freecodecamp.org/how-to-open-a-pull-request/).',
|
||||
"- [ ] My pull request targets the `main` branch of freeCodeCamp.",
|
||||
'- [ ] I have tested these changes either locally on my machine, or GitHub Codespaces.',
|
||||
'',
|
||||
'<!--If your pull request closes a GitHub issue, replace the XXXXX below with the issue number.-->',
|
||||
'',
|
||||
'Closes #XXXXX',
|
||||
'',
|
||||
'<!-- Feel free to add any additional description of changes below this line -->',
|
||||
'```'
|
||||
].join('\n');
|
||||
|
||||
module.exports = async ({ github, context, isAllowListed }) => {
|
||||
module.exports = async ({ github, context, core, isAllowListed }) => {
|
||||
if (isAllowListed === 'true') return;
|
||||
|
||||
const body = (context.payload.pull_request.body || '').toLowerCase();
|
||||
const action = context.payload.action;
|
||||
|
||||
// The template must be present and the first 3 checkboxes must be
|
||||
// ticked. The last checkbox (tested locally) is acceptable to leave
|
||||
@@ -46,25 +23,12 @@ module.exports = async ({ github, context, isAllowListed }) => {
|
||||
normalizedBody.includes(`[x] ${item}`)
|
||||
);
|
||||
|
||||
if (templatePresent && allRequiredTicked) {
|
||||
// On edit, remove the deprioritized label if the check now passes.
|
||||
if (action === 'edited') {
|
||||
try {
|
||||
await github.rest.issues.removeLabel({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: context.payload.pull_request.number,
|
||||
name: 'deprioritized'
|
||||
});
|
||||
} catch {
|
||||
// Label may not exist — ignore.
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (templatePresent && allRequiredTicked) return;
|
||||
|
||||
// On edit, don't re-comment — the original comment is already there.
|
||||
if (action === 'edited') return;
|
||||
core.setOutput('failure_reason', 'incomplete_checklist');
|
||||
core.setFailed(
|
||||
'PR description is missing the required checklist or some items are incomplete.'
|
||||
);
|
||||
|
||||
await github.rest.issues.addLabels({
|
||||
owner: context.repo.owner,
|
||||
@@ -72,26 +36,4 @@ module.exports = async ({ github, context, isAllowListed }) => {
|
||||
issue_number: context.payload.pull_request.number,
|
||||
labels: ['deprioritized']
|
||||
});
|
||||
|
||||
await github.rest.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: context.payload.pull_request.number,
|
||||
body:
|
||||
[
|
||||
'Hi there,',
|
||||
'',
|
||||
'Thank you for the contribution.',
|
||||
'',
|
||||
'The automated checks found a few issues with the PR. Currently the PR description is missing the required checklist or some of its items are not completed:',
|
||||
'',
|
||||
'1. The `Checklist:` heading is present in the PR description.',
|
||||
'2. The checkbox items are ticked (changed from `[ ]` to `[x]`).',
|
||||
'3. You have actually completed the items in the checklist.',
|
||||
'',
|
||||
'Please edit your PR description to include the following template with the checklist items completed.',
|
||||
'',
|
||||
TEMPLATE_BLOCK
|
||||
].join('\n') + FOOTER
|
||||
});
|
||||
};
|
||||
|
||||
@@ -60,9 +60,12 @@ module.exports = async ({ github, context }) => {
|
||||
}
|
||||
}
|
||||
|
||||
// Fix 4: missing space after colon — "fix:desc" → "fix: desc"
|
||||
newTitle = newTitle.replace(/^(\w+(?:\([^)]+\))?):(\S)/, '$1: $2');
|
||||
|
||||
// Catch-all: prefix with "fix: " if still not a valid CC title
|
||||
if (!ccRegex.test(newTitle)) {
|
||||
newTitle = `fix: ${title}`;
|
||||
newTitle = `fix: ${newTitle}`;
|
||||
}
|
||||
|
||||
if (newTitle !== title) {
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
'use strict';
|
||||
|
||||
const FOOTER =
|
||||
'\n\n---\nJoin us in our [chat room](https://discord.gg/PRyKn3Vbay) or our [forum](https://forum.freecodecamp.org/c/contributors/3) if you have any questions or need help with contributing.';
|
||||
|
||||
const TEMPLATE_BLOCK = [
|
||||
'```md',
|
||||
'Checklist:',
|
||||
'',
|
||||
'<!-- Please follow this checklist and put an x in each of the boxes, like this: [x]. It will ensure that our team takes your pull request seriously. -->',
|
||||
'',
|
||||
'- [ ] I have read and followed the [contribution guidelines](https://contribute.freecodecamp.org).',
|
||||
'- [ ] I have read and followed the [how to open a pull request guide](https://contribute.freecodecamp.org/how-to-open-a-pull-request/).',
|
||||
"- [ ] My pull request targets the `main` branch of freeCodeCamp.",
|
||||
'- [ ] I have tested these changes either locally on my machine, or GitHub Codespaces.',
|
||||
'',
|
||||
'<!--If your pull request closes a GitHub issue, replace the XXXXX below with the issue number.-->',
|
||||
'',
|
||||
'Closes #XXXXX',
|
||||
'',
|
||||
'<!-- Feel free to add any additional description of changes below this line -->',
|
||||
'```'
|
||||
].join('\n');
|
||||
|
||||
const MESSAGES = {
|
||||
incomplete_checklist: [
|
||||
'**Checklist:** The PR description is missing the required checklist or some of its items are not completed:',
|
||||
'',
|
||||
'1. The `Checklist:` heading is present in the PR description.',
|
||||
'2. The checkbox items are ticked (changed from `[ ]` to `[x]`).',
|
||||
'3. You have actually completed the items in the checklist.',
|
||||
'',
|
||||
'Please edit your PR description to include the following template with the checklist items completed.',
|
||||
'',
|
||||
TEMPLATE_BLOCK
|
||||
].join('\n'),
|
||||
|
||||
no_linked_issue: [
|
||||
'**Linked Issue:** We kindly ask that contributors open an issue before submitting a PR so the change can be discussed and approved before work begins. This helps avoid situations where significant effort goes into something we ultimately cannot merge.',
|
||||
'',
|
||||
'Please open an issue first and allow it to be triaged. Once the issue is open for contribution, you are welcome to update this pull request to reflect the issue consensus. Until then, we will not be able to review your pull request.'
|
||||
].join('\n'),
|
||||
|
||||
waiting_triage: [
|
||||
'**Linked Issue:** The linked issue has not been triaged yet, and a solution has not been agreed upon. Once the issue is open for contribution, you are welcome to update this pull request to reflect the issue consensus. Until then, we will not be able to review your pull request.'
|
||||
].join('\n'),
|
||||
|
||||
not_open_for_contribution:
|
||||
'**Linked Issue:** The linked issue is not open for contribution. If you are looking for issues to contribute to, please check out issues labeled [`help wanted`](https://github.com/freeCodeCamp/freeCodeCamp/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) or [`first timers only`](https://github.com/freeCodeCamp/freeCodeCamp/issues?q=is%3Aissue+is%3Aopen+label%3A%22first+timers+only%22).'
|
||||
};
|
||||
|
||||
module.exports = async ({
|
||||
github,
|
||||
context,
|
||||
templateResult,
|
||||
templateReason,
|
||||
linkedIssueResult,
|
||||
linkedIssueReason
|
||||
}) => {
|
||||
const allPassed =
|
||||
templateResult === 'success' && linkedIssueResult === 'success';
|
||||
|
||||
if (allPassed) {
|
||||
try {
|
||||
await github.rest.issues.removeLabel({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: context.issue.number,
|
||||
name: 'deprioritized'
|
||||
});
|
||||
} catch {
|
||||
// Label may not exist — ignore.
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// On edit, don't re-comment — the original comment is already there.
|
||||
if (context.payload.action === 'edited') return;
|
||||
|
||||
const sections = [];
|
||||
if (templateResult === 'failure' && MESSAGES[templateReason]) {
|
||||
sections.push(MESSAGES[templateReason]);
|
||||
}
|
||||
if (linkedIssueResult === 'failure' && MESSAGES[linkedIssueReason]) {
|
||||
sections.push(MESSAGES[linkedIssueReason]);
|
||||
}
|
||||
|
||||
if (sections.length === 0) return;
|
||||
|
||||
const body =
|
||||
[
|
||||
'Hi there,',
|
||||
'',
|
||||
'Thanks for opening this pull request.',
|
||||
'',
|
||||
'The automated checks found some issues:',
|
||||
'',
|
||||
sections.join('\n\n')
|
||||
].join('\n') + FOOTER;
|
||||
|
||||
await github.rest.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: context.issue.number,
|
||||
body
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user