Improve AutoLabler
This commit is contained in:
parent
2ce64b5004
commit
e58ad9237a
27
.github/autolabeler-config.json
generated
vendored
27
.github/autolabeler-config.json
generated
vendored
@ -121,5 +121,32 @@
|
|||||||
],
|
],
|
||||||
"excludeGlobs": []
|
"excludeGlobs": []
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"addon": [
|
||||||
|
{
|
||||||
|
"fileStatus": null,
|
||||||
|
"includeGlobs": [
|
||||||
|
"tools/addon/**"
|
||||||
|
],
|
||||||
|
"excludeGlobs": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"pve-tool": [
|
||||||
|
{
|
||||||
|
"fileStatus": null,
|
||||||
|
"includeGlobs": [
|
||||||
|
"tools/pve/**"
|
||||||
|
],
|
||||||
|
"excludeGlobs": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"vm": [
|
||||||
|
{
|
||||||
|
"fileStatus": null,
|
||||||
|
"includeGlobs": [
|
||||||
|
"vm/**"
|
||||||
|
],
|
||||||
|
"excludeGlobs": []
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
30
.github/workflows/autolabeler.yml
generated
vendored
30
.github/workflows/autolabeler.yml
generated
vendored
@ -44,50 +44,50 @@ jobs:
|
|||||||
});
|
});
|
||||||
const prFiles = prListFilesResponse.data;
|
const prFiles = prListFilesResponse.data;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Apply labels based on file changes
|
|
||||||
for (const [label, rules] of Object.entries(autolabelerConfig)) {
|
for (const [label, rules] of Object.entries(autolabelerConfig)) {
|
||||||
const shouldAddLabel = prFiles.some((prFile) => {
|
const shouldAddLabel = prFiles.some((prFile) => {
|
||||||
return rules.some((rule) => {
|
return rules.some((rule) => {
|
||||||
const isFileStatusMatch = rule.fileStatus ? rule.fileStatus === prFile.status : true;
|
const isFileStatusMatch = rule.fileStatus ? rule.fileStatus === prFile.status : true;
|
||||||
const isIncludeGlobMatch = rule.includeGlobs.some((glob) => minimatch(prFile.filename, glob));
|
const isIncludeGlobMatch = rule.includeGlobs.some((glob) => minimatch(prFile.filename, glob));
|
||||||
const isExcludeGlobMatch = rule.excludeGlobs.some((glob) => minimatch(prFile.filename, glob));
|
const isExcludeGlobMatch = rule.excludeGlobs.some((glob) => minimatch(prFile.filename, glob));
|
||||||
|
|
||||||
return isFileStatusMatch && isIncludeGlobMatch && !isExcludeGlobMatch;
|
return isFileStatusMatch && isIncludeGlobMatch && !isExcludeGlobMatch;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (shouldAddLabel) {
|
if (shouldAddLabel) {
|
||||||
labelsToAdd.add(label);
|
labelsToAdd.add(label);
|
||||||
|
if (label === "update script") {
|
||||||
|
for (const prFile of prFiles) {
|
||||||
|
const filename = prFile.filename;
|
||||||
|
if (filename.startsWith("vm/")) labelsToAdd.add("vm");
|
||||||
|
if (filename.startsWith("tools/addon/")) labelsToAdd.add("addon");
|
||||||
|
if (filename.startsWith("tools/pve/")) labelsToAdd.add("pve-tool");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//if two labels or more are added, return
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (labelsToAdd.size < 2) {
|
if (labelsToAdd.size < 2) {
|
||||||
const templateLabelMappings = {
|
const templateLabelMappings = {
|
||||||
"🐞 **Bug fix**": "bugfix",
|
"🐞 **Bug fix**": "bugfix",
|
||||||
"✨ **New feature**": "feature",
|
"✨ **New feature**": "feature",
|
||||||
"💥 **Breaking change**": "breaking change",
|
"💥 **Breaking change**": "breaking change",
|
||||||
|
"🆕 **New script**": "new script",
|
||||||
|
"🌍 **Website update**": "website",
|
||||||
"🔧 **Refactoring / Code Cleanup**": "refactor",
|
"🔧 **Refactoring / Code Cleanup**": "refactor",
|
||||||
|
"📝 **Documentation update**": "documentation"
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const [checkbox, label] of Object.entries(templateLabelMappings)) {
|
for (const [checkbox, label] of Object.entries(templateLabelMappings)) {
|
||||||
const escapedCheckbox = checkbox.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
|
const escapedCheckbox = checkbox.replace(/([.*+?^=!:${}()|[\]\/\\])/g, "\\$1");
|
||||||
const regex = new RegExp(`- \\[(x|X)\\]\\s*.*${escapedCheckbox}`, "i");
|
const regex = new RegExp(`- \[(x|X)\]\s*.*${escapedCheckbox}`, "i");
|
||||||
const match = prBody.match(regex);
|
if (regex.test(prBody)) {
|
||||||
if (match) {
|
|
||||||
console.log(`Match: ${match}`);
|
|
||||||
labelsToAdd.add(label);
|
labelsToAdd.add(label);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
console.log(`Labels to add: ${Array.from(labelsToAdd).join(", ")}`);
|
|
||||||
|
|
||||||
if (labelsToAdd.size > 0) {
|
if (labelsToAdd.size > 0) {
|
||||||
console.log(`Adding labels ${Array.from(labelsToAdd).join(", ")} to PR ${prNumber}`);
|
|
||||||
await github.rest.issues.addLabels({
|
await github.rest.issues.addLabels({
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
repo: context.repo.repo,
|
repo: context.repo.repo,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user