ci: auto-label feature requests with the enhancement label (#28531)
This commit is contained in:
1 file changed
+70
@@ -67,3 +67,73 @@ jobs:
|
|||||||
issue_number: issue.number,
|
issue_number: issue.number,
|
||||||
labels: ['bug']
|
labels: ['bug']
|
||||||
});
|
});
|
||||||
|
|
||||||
|
label-feature-requests:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Add "enhancement" label to unlabeled feature requests
|
||||||
|
uses: actions/github-script@v7
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
const issue = context.payload.issue;
|
||||||
|
|
||||||
|
if (issue.labels.some((label) => label.name === 'enhancement')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A human (or the bug form) already classified this as a bug;
|
||||||
|
// do not stack a second, contradictory classification on it.
|
||||||
|
if (issue.labels.some((label) => label.name === 'bug')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isEdit = context.payload.action === 'edited';
|
||||||
|
const titleWasEdited = Boolean(context.payload.changes?.title);
|
||||||
|
|
||||||
|
if (isEdit && !titleWasEdited) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = issue.title ?? '';
|
||||||
|
const body = issue.body ?? '';
|
||||||
|
|
||||||
|
// Feature requests: "feat: ...", "feature: ...", "feature request: ...",
|
||||||
|
// "enhancement: ...", "enh: ...", "[Feature Request] ..." — the feature
|
||||||
|
// request form titles every submission "feat: ", so form submissions are
|
||||||
|
// covered by the same pattern.
|
||||||
|
const featureLikeTitle =
|
||||||
|
/^\s*(\[\s*(feat|feature|enhancement|enh)\b[^\]]*\]|(feat|feature( request)?|enhancement|enh)\s*[:/\-])/i.test(
|
||||||
|
title
|
||||||
|
);
|
||||||
|
|
||||||
|
// API/CLI-created issues that reproduce the feature request form structure.
|
||||||
|
// Only headings distinctive to that form.
|
||||||
|
const featureFormBody = /###\s*(Proposed Solution|Alternatives Considered)/i.test(body);
|
||||||
|
|
||||||
|
if (!featureLikeTitle && !featureFormBody) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isEdit) {
|
||||||
|
const events = await github.paginate(github.rest.issues.listEvents, {
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
issue_number: issue.number,
|
||||||
|
per_page: 100
|
||||||
|
});
|
||||||
|
|
||||||
|
const enhancementLabelWasRemoved = events.some(
|
||||||
|
(event) => event.event === 'unlabeled' && event.label?.name === 'enhancement'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (enhancementLabelWasRemoved) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await github.rest.issues.addLabels({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
issue_number: issue.number,
|
||||||
|
labels: ['enhancement']
|
||||||
|
});
|
||||||
Reference in new issue
Block a user