[gh] Update Changelog Workflow (#2621)

* Update Workflow

* Update Workflow
This commit is contained in:
Michel Roegl-Brunner
2025-02-25 09:55:17 +02:00
committed by GitHub
parent bef3ccd164
commit 893bff1b59
4 changed files with 100 additions and 32 deletions

View File

@@ -32,8 +32,9 @@ 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 +43,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;
});
});