agones.dev/agones@v1.53.0/.github/workflows/label-pr.yml (about) 1 --- 2 # Copyright 2023 Google LLC 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 # 16 # This workflow utilizes https://github.com/actions/github-script in GitHub Actions to apply labels to pull requests. 17 # 18 name: Label PR 19 on: [pull_request_target] 20 jobs: 21 label: 22 runs-on: ubuntu-latest 23 permissions: 24 contents: read 25 pull-requests: write 26 steps: 27 - name: Label PR 28 uses: actions/github-script@v6 29 with: 30 script: |- 31 const keywords = { 32 "breaking": "kind/breaking", 33 "bug": "kind/bug", 34 "feature": "kind/feature", 35 "cleanup": "kind/cleanup", 36 "documentation": "kind/documentation", 37 "hotfix": "kind/hotfix", 38 "release": "kind/release" 39 }; 40 const prBody = context.payload.pull_request.body; 41 const prLabels = []; 42 if (prBody === null || prBody.trim() === "") { 43 console.log("Pull Request body is empty"); 44 prLabels.push("kind/other"); 45 } else { 46 const regex = /^\s*\/kind\s+(.+)$/m; 47 const match = prBody.match(regex); 48 console.log(`PR body: '${prBody}'`); 49 console.log(`Regex match: '${match}'`); 50 if (match && match[1] in keywords) { 51 const keyword = match[1]; 52 const label = keywords[keyword]; 53 console.log(`Adding label: '${label}' based on keyword '${keyword}'`); 54 prLabels.push(label); 55 } else { 56 console.log(`Adding label: 'kind/other' as no matching keyword found.`); 57 prLabels.push("kind/other"); 58 } 59 } 60 try { 61 github.rest.issues.addLabels({ 62 owner: context.repo.owner, 63 repo: context.repo.repo, 64 issue_number: context.payload.pull_request.number, 65 labels: prLabels 66 }); 67 } catch (error) { 68 console.error(`Error retrieving files: ${error}`); 69 }