diff --git a/.github/workflows/autolabeler.yml b/.github/workflows/autolabeler.yml index 4ef4f162c..ee715d838 100644 --- a/.github/workflows/autolabeler.yml +++ b/.github/workflows/autolabeler.yml @@ -19,7 +19,7 @@ jobs: - name: Install minimatch run: npm install minimatch - - name: Label PR based on file changes + - name: Label PR based on file changes and PR template uses: actions/github-script@v7 with: script: | @@ -30,8 +30,12 @@ jobs: const configPath = path.resolve(process.env.CONFIG_PATH); const fileContent = await fs.readFile(configPath, 'utf-8'); const autolabelerConfig = JSON.parse(fileContent); - + const prNumber = context.payload.pull_request.number; + const prBody = context.payload.pull_request.body.toLowerCase(); + + let labelsToAdd = new Set(); + const prListFilesResponse = await github.rest.pulls.listFiles({ owner: context.repo.owner, repo: context.repo.repo, @@ -39,8 +43,6 @@ 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) => { @@ -57,34 +59,17 @@ jobs: } } - 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 = { + const templateLabelMappings = { "🐞 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)) { + for (const [checkbox, label] of Object.entries(templateLabelMappings)) { const regex = new RegExp(`- \\[(.*?)\\] ${checkbox}`, "i"); - if (regex.test(prBody)) { + const match = prBody.match(regex); + if (match && match[1].trim() !== "") { // Checkbox ist gesetzt labelsToAdd.add(label); } }