Updated Changelog Workflow (#2632)

This commit is contained in:
Michel Roegl-Brunner
2025-02-25 12:27:31 +02:00
committed by GitHub
parent 599a518cc3
commit 3401b76c44
4 changed files with 99 additions and 56 deletions

View File

@@ -32,8 +32,8 @@ jobs:
const autolabelerConfig = JSON.parse(fileContent);
const prNumber = context.payload.pull_request.number;
const prBody = context.payload.pull_request.body;
const prBody = context.payload.pull_request.body.toLowerCase();
let labelsToAdd = new Set();
const prListFilesResponse = await github.rest.pulls.listFiles({
@@ -42,14 +42,35 @@ jobs:
pull_number: prNumber,
});
const prFiles = prListFilesResponse.data;
const templateLabelMappings = {
"🐞 **bug fix**": "bugfix",
"✨ **new feature**": "feature",
"💥 **breaking change**": "breaking change",
"🆕 **new script**": "new script"
};
for (const [checkbox, label] of Object.entries(templateLabelMappings)) {
const escapedCheckbox = checkbox.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
const regex = new RegExp(`- \\[(x|X)\\]\\s*.*${escapedCheckbox}`, "i");
const match = prBody.match(regex);
if (match) {
console.log(`Match: ${match}`);
labelsToAdd.add(label);
}
}
if (labelsToAdd.size === 0) {
labelsToAdd.add("general");
}
// Apply labels based on file changes
for (const [label, rules] of Object.entries(autolabelerConfig)) {
const shouldAddLabel = prFiles.some((prFile) => {
return rules.some((rule) => {
const isFileStatusMatch = rule.fileStatus ? rule.fileStatus === prFile.status : true;
const isIncludeGlobMatch = rule.includeGlobs.some((glob) => minimatch(prFile.filename, glob));
const isExcludeGlobMatch = rule.excludeGlobs.some((glob) => minimatch(prFile.filename, glob));
return isFileStatusMatch && isIncludeGlobMatch && !isExcludeGlobMatch;
});
});
@@ -58,21 +79,7 @@ jobs:
labelsToAdd.add(label);
}
}
const templateLabelMappings = {
"🐞 bug fix": "bugfix",
"✨ new feature": "feature",
"💥 breaking change": "breaking change",
"🆕 new script": "new script"
};
for (const [checkbox, label] of Object.entries(templateLabelMappings)) {
const regex = new RegExp(`- \\[x\\] ${checkbox}`, "i"); // Match only checked checkboxes
if (regex.test(prBody)) {
labelsToAdd.add(label);
}
}
console.log(`Labels to add: ${Array.from(labelsToAdd).join(", ")}`);
if (labelsToAdd.size > 0) {