-
Notifications
You must be signed in to change notification settings - Fork 813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Release Automation] Label PRs with GitHub Action #3151
Merged
markmandel
merged 17 commits into
googleforgames:main
from
Kalaiselvi84:issues/280492287
Jun 7, 2023
Merged
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
47e93f4
[Release Automation] Auto-Label PRs with GitHub Action
Kalaiselvi84 7542f99
copyright and description added
Kalaiselvi84 40d532f
[Release Automation] Auto-Label PRs with GitHub Action
Kalaiselvi84 0f04029
copyright and description added
Kalaiselvi84 1c5ee77
Merge branch 'main' into issues/280492287
Kalaiselvi84 c5dc5c8
Merge branch 'issues/280492287' of https://github.com/Kalaiselvi84/ag…
Kalaiselvi84 7d65f08
removed measuring size of code
Kalaiselvi84 21a5441
Merge branch 'main' into issues/280492287
Kalaiselvi84 e54a525
Write permission lines added
Kalaiselvi84 3205b14
Write permission lines added
Kalaiselvi84 95d30de
changed github-token to repo-token
Kalaiselvi84 7cbb806
Merge branch 'main' into issues/280492287
Kalaiselvi84 754f665
Replacing GITHUB_TOKEN with AGONES_BOT
Kalaiselvi84 3727d4d
Merge branch 'main' into issues/280492287
Kalaiselvi84 fcbe860
Checkout code step removed
Kalaiselvi84 5eef6fc
optimistic for the success
Kalaiselvi84 e02934b
Merge branch 'main' into issues/280492287
Kalaiselvi84 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,75 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# 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 utilizes https://github.com/actions/github-script in GitHub Actions to apply labels to pull requests. | ||
# | ||
|
||
name: Label PR | ||
|
||
on: | ||
pull_request: | ||
types: [opened] | ||
|
||
jobs: | ||
label: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write | ||
|
||
gongmax marked this conversation as resolved.
Show resolved
Hide resolved
|
||
steps: | ||
|
||
- name: Label PR | ||
uses: actions/github-script@v4 | ||
with: | ||
async: yes | ||
repo-token: ${{ secrets.AGONES_BOT }} | ||
script: | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's super cool you can do this. |
||
const keywords = { | ||
"breaking": "kind/breaking", | ||
"bug": "kind/bug", | ||
"feature": "kind/feature", | ||
"cleanup": "kind/cleanup", | ||
"documentation": "kind/documentation", | ||
"hotfix": "kind/hotfix" | ||
}; | ||
|
||
const prBody = context.payload.pull_request.body; | ||
const prLabels = []; | ||
|
||
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 { | ||
await github.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}`); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly? Just taking reference from: https://github.com/actions/labeler#create-workflow
It's also possible to try it with the GITHUB_TOKEN
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or try
permissions: read-all|write-all
as mentioned in https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idpermissions, just to see if it's a permissions issue.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@markmandel, please merge this PR. I was able to reproduce the error in my fork by not adding the write permission to the pull_request and issues - https://github.com/Kalaiselvi84/agones/actions/runs/5185413754/jobs/9345294118?pr=274
You can adjust the permission in Agones if there is any issues. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good! Merging!