1919 - name : Install minimatch
2020 run : npm install minimatch
2121
22- - name : Label PR based on file changes
22+ - name : Label PR based on file changes and PR template
2323 uses : actions/github-script@v7
2424 with :
2525 script : |
@@ -30,17 +30,19 @@ jobs:
3030 const configPath = path.resolve(process.env.CONFIG_PATH);
3131 const fileContent = await fs.readFile(configPath, 'utf-8');
3232 const autolabelerConfig = JSON.parse(fileContent);
33-
33+
3434 const prNumber = context.payload.pull_request.number;
35+ const prBody = context.payload.pull_request.body.toLowerCase();
36+
37+ let labelsToAdd = new Set();
38+
3539 const prListFilesResponse = await github.rest.pulls.listFiles({
3640 owner: context.repo.owner,
3741 repo: context.repo.repo,
3842 pull_number: prNumber,
3943 });
4044 const prFiles = prListFilesResponse.data;
4145
42- let labelsToAdd = new Set();
43-
4446 for (const [label, rules] of Object.entries(autolabelerConfig)) {
4547 const shouldAddLabel = prFiles.some((prFile) => {
4648 return rules.some((rule) => {
@@ -57,34 +59,17 @@ jobs:
5759 }
5860 }
5961
60- if (labelsToAdd.size > 0) {
61- console.log(`Adding labels ${Array.from(labelsToAdd).join(", ")} to PR ${prNumber}`);
62- await github.rest.issues.addLabels({
63- owner : context.repo.owner,
64- repo : context.repo.repo,
65- issue_number : prNumber,
66- labels : Array.from(labelsToAdd),
67- });
68- }
69-
70- - name : Label PR based on PR template selections
71- uses : actions/github-script@v7
72- with :
73- script : |
74- const prBody = context.payload.pull_request.body.toLowerCase();
75- const prNumber = context.payload.pull_request.number;
76- const labelMappings = {
62+ const templateLabelMappings = {
7763 "🐞 bug fix": "bug fix",
7864 "✨ new feature": "new feature",
7965 "💥 breaking change": "breaking change",
8066 "🆕 new script": "new script"
8167 };
8268
83- let labelsToAdd = new Set();
84-
85- for (const [checkbox, label] of Object.entries(labelMappings)) {
69+ for (const [checkbox, label] of Object.entries(templateLabelMappings)) {
8670 const regex = new RegExp(`- \\[(.*?)\\] ${checkbox}`, "i");
87- if (regex.test(prBody)) {
71+ const match = prBody.match(regex);
72+ if (match && match[1].trim() !== "") { // Checkbox ist gesetzt
8873 labelsToAdd.add(label);
8974 }
9075 }
0 commit comments