Update pull_workflow.yaml #9
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Label PR | |
on: [pull_request_target] | |
jobs: | |
label: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
pull-requests: write | |
steps: | |
- name: Label PR | |
uses: actions/github-script@v6 | |
with: | |
script: |- | |
const keywords = { | |
"breaking": "kind/breaking", | |
"bug": "kind/bug", | |
"feature": "kind/feature", | |
"cleanup": "kind/cleanup", | |
"documentation": "kind/documentation", | |
"hotfix": "kind/hotfix", | |
"release": "kind/release" | |
}; | |
const prBody = context.payload.pull_request.body; | |
const prLabels = []; | |
if (prBody === null || prBody.trim() === "") { | |
console.log("Pull Request body is empty"); | |
prLabels.push("kind/other"); | |
} else { | |
const regex = /^\s*\/kind\s+(.+)$/m; | |
const match = prBody.match(regex); | |
console.log(`PR body: '${prBody}'`); | |
console.log(`Regex match: '${match}'`); | |
if (match && match[1] in keywords) { | |
const keyword = match[1]; | |
const label = keywords[keyword]; | |
console.log(`Adding label: '${label}' based on keyword '${keyword}'`); | |
prLabels.push(label); | |
} else { | |
console.log(`Adding label: 'kind/other' as no matching keyword found.`); | |
prLabels.push("kind/other"); | |
} | |
} | |
try { | |
github.rest.issues.addLabels({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.payload.pull_request.number, | |
labels: prLabels | |
}); | |
} catch (error) { | |
console.error(`Error retrieving files: ${error}`); | |
} |