-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto-labels 'gemma' on 'gemma' issues/PRs. (#1490)
* Auto-labels 'gemma' on 'gemma' issues/PRs. * make labeling logic generic. * Update labeler.yaml with formatting fixes * Update labeler.js with formatting fixes * Update script reference. --------- Co-authored-by: Matt Watson <[email protected]>
- Loading branch information
1 parent
f70b1c0
commit c9ae49e
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Copyright 2024 Google LLC. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
# This workflow automatically identifies issues and pull requests (PRs) | ||
# related to Gemma. It searches for the keyword "Gemma" (case-insensitive) | ||
# in both the title and description of the issue/PR. If a match is found, | ||
# the workflow adds the label 'Gemma' to the issue/PR. | ||
|
||
name: 'Labeler' | ||
on: | ||
issues: | ||
types: [edited, opened] | ||
pull_request_target: | ||
types: [opened, edited] | ||
|
||
permissions: | ||
contents: read | ||
issues: write | ||
pull-requests: write | ||
|
||
jobs: | ||
welcome: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const script = require('./\.github/workflows/scripts/labeler.js') | ||
script({github, context}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
Copyright 2024 Google LLC. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
|
||
/** | ||
* Invoked from labeler.yaml file to add | ||
* label 'Gemma' to the issue and PR for which have gemma keyword present. | ||
* @param {!Object.<string,!Object>} github contains pre defined functions. | ||
* context Information about the workflow run. | ||
*/ | ||
|
||
module.exports = async ({ github, context }) => { | ||
const issue_title = context.payload.issue ? context.payload.issue.title : context.payload.pull_request.title | ||
const issue_discription = context.payload.issue ? context.payload.issue.body : context.payload.pull_request.body | ||
const issue_number = context.payload.issue ? context.payload.issue.number : context.payload.pull_request.number | ||
const keyword_label = { | ||
gemma:'Gemma' | ||
} | ||
const labelsToAdd = [] | ||
console.log(issue_title,issue_discription,issue_number) | ||
|
||
for(const [keyword, label] of Object.entries(keyword_label)){ | ||
if(issue_title.toLowerCase().indexOf(keyword) !=-1 || issue_discription.toLowerCase().indexOf(keyword) !=-1 ){ | ||
console.log(`'${keyword}'keyword is present inside the title or description. Pushing label '${label}' to row.`) | ||
labelsToAdd.push(label) | ||
} | ||
} | ||
if(labelsToAdd.length > 0){ | ||
console.log(`Adding labels ${labelsToAdd} to the issue '#${issue_number}'.`) | ||
github.rest.issues.addLabels({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: context.issue.number, | ||
labels: labelsToAdd | ||
}) | ||
} | ||
}; |