[gh] better handling of labels (#2517)

* Update autolabeler.yml

* Update changelog-pr-config.json
This commit is contained in:
CanbiZ 2025-02-20 14:01:33 +01:00 committed by GitHub
parent 1fe8bc05b3
commit 20414d9659
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 66 additions and 24 deletions

View File

@ -1,34 +1,38 @@
[
{
"title": "💥 Breaking Changes",
"labels": ["breaking change"]
"title": "💥 Breaking Changes",
"labels": ["breaking change"]
},
{
"title": "✨ New Scripts",
"labels": ["new script"]
"title": "✨ New Scripts",
"labels": ["new script"]
},
{
"title": "🚀 Updated Scripts",
"labels": ["update script"]
"title": "🚀 Updated Scripts",
"labels": ["update script"]
},
{
"title": "🌐 Website",
"labels": ["website"]
"title": "🆕 Features",
"labels": ["new feature"]
},
{
"title": "🐞 Bug Fixes",
"labels": ["bug fix"]
"title": "🌐 Website",
"labels": ["website"]
},
{
"title": "🧰 Maintenance",
"labels": ["maintenance"]
"title": "🐞 Bug Fixes",
"labels": ["bug fix"]
},
{
"title": "📡 API",
"labels": ["api"]
"title": "🧰 Maintenance",
"labels": ["maintenance"]
},
{
"title": "❔ Unlabelled",
"labels": []
"title": "📡 API",
"labels": ["api"]
},
{
"title": "❔ Unlabelled",
"labels": []
}
]

View File

@ -19,7 +19,7 @@ jobs:
- name: Install minimatch
run: npm install minimatch
- name: Label PR based on config rules
- name: Label PR based on file changes
uses: actions/github-script@v7
with:
script: |
@ -39,6 +39,8 @@ jobs:
});
const prFiles = prListFilesResponse.data;
let labelsToAdd = new Set();
for (const [label, rules] of Object.entries(autolabelerConfig)) {
const shouldAddLabel = prFiles.some((prFile) => {
return rules.some((rule) => {
@ -51,12 +53,48 @@ jobs:
});
if (shouldAddLabel) {
console.log(`Adding label ${label} to PR ${prNumber}`);
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: [label],
});
labelsToAdd.add(label);
}
}
if (labelsToAdd.size > 0) {
console.log(`Adding labels ${Array.from(labelsToAdd).join(", ")} to PR ${prNumber}`);
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: Array.from(labelsToAdd),
});
}
- name: Label PR based on PR template selections
uses: actions/github-script@v7
with:
script: |
const prBody = context.payload.pull_request.body.toLowerCase();
const prNumber = context.payload.pull_request.number;
const labelMappings = {
"🐞 bug fix": "bug fix",
"✨ new feature": "new feature",
"💥 breaking change": "breaking change",
"🆕 new script": "new script"
};
let labelsToAdd = new Set();
for (const [checkbox, label] of Object.entries(labelMappings)) {
const regex = new RegExp(`- \\[(.*?)\\] ${checkbox}`, "i");
if (regex.test(prBody)) {
labelsToAdd.add(label);
}
}
if (labelsToAdd.size > 0) {
console.log(`Adding labels ${Array.from(labelsToAdd).join(", ")} to PR ${prNumber}`);
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: Array.from(labelsToAdd),
});
}