|
| 1 | +/* |
| 2 | +Copyright 2024 Google LLC. All Rights Reserved. |
| 3 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +you may not use this file except in compliance with the License. |
| 5 | +You may obtain a copy of the License at |
| 6 | +
|
| 7 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +
|
| 9 | + Unless required by applicable law or agreed to in writing, software |
| 10 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + See the License for the specific language governing permissions and |
| 13 | + limitations under the License. |
| 14 | +*/ |
| 15 | + |
| 16 | + |
| 17 | +/** |
| 18 | + * Invoked from labeler.yaml file to add |
| 19 | + * label 'Gemma' to the issue and PR for which have gemma keyword present. |
| 20 | + * @param {!Object.<string,!Object>} github contains pre defined functions. |
| 21 | + * context Information about the workflow run. |
| 22 | + */ |
| 23 | + |
| 24 | +module.exports = async ({ github, context }) => { |
| 25 | + const issue_title = context.payload.issue ? context.payload.issue.title : context.payload.pull_request.title |
| 26 | + let issue_description = context.payload.issue ? context.payload.issue.body : context.payload.pull_request.body |
| 27 | + const issue_number = context.payload.issue ? context.payload.issue.number : context.payload.pull_request.number |
| 28 | + const keyword_label = { |
| 29 | + gemma:'Gemma' |
| 30 | + } |
| 31 | + const labelsToAdd = [] |
| 32 | + console.log(issue_title,issue_description,issue_number) |
| 33 | + if (issue_description==null) |
| 34 | + { |
| 35 | + issue_description = '' |
| 36 | + } |
| 37 | + |
| 38 | + for(const [keyword, label] of Object.entries(keyword_label)){ |
| 39 | + if(issue_title.toLowerCase().indexOf(keyword) !=-1 || issue_description.toLowerCase().indexOf(keyword) !=-1 ){ |
| 40 | + console.log(`'${keyword}'keyword is present inside the title or description. Pushing label '${label}' to row.`) |
| 41 | + labelsToAdd.push(label) |
| 42 | + } |
| 43 | + } |
| 44 | + if(labelsToAdd.length > 0){ |
| 45 | + console.log(`Adding labels ${labelsToAdd} to the issue '#${issue_number}'.`) |
| 46 | + github.rest.issues.addLabels({ |
| 47 | + owner: context.repo.owner, |
| 48 | + repo: context.repo.repo, |
| 49 | + issue_number: context.issue.number, |
| 50 | + labels: labelsToAdd |
| 51 | + }) |
| 52 | + } |
| 53 | +}; |
0 commit comments