-
Notifications
You must be signed in to change notification settings - Fork 144
[ISSUE #545]🔧Update label-on-approval.yml #546
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
Merged
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5d4bece
[ISSUE #545]🔧Update label-on-approval.yml
mxsm 6c3bb33
fix ci error
mxsm 7654b94
fix ci error
mxsm bebf709
fix ci error
mxsm 2b498c7
fix error
mxsm 80dc8f6
fix error
mxsm dc7ff3f
fix ci error
mxsm f3eb6bc
fix error
mxsm e7e3625
fix error
mxsm e5fb952
ttt
mxsm ba3a135
ttt
mxsm 4d3fa24
ttt
mxsm ce3d8bd
ttt
mxsm fe73cc5
ttt
mxsm 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 hidden or 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 |
---|---|---|
@@ -1,39 +1,52 @@ | ||
name: Label on Approval | ||
name: Add Label on Approval | ||
|
||
on: | ||
pull_request_review: | ||
types: [ submitted ] | ||
types: [ submitted,edited ] | ||
|
||
jobs: | ||
add-label-on-approval: | ||
add-label: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Check for approval and add label | ||
uses: actions/github-script@v6 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} | ||
- name: Check if approval is from Collaborators | ||
if: github.event.review.state == 'APPROVED' | ||
id: check_approval | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ secrets.PAT_TOKEN }} | ||
script: | | ||
const approved = context.payload.review.state === 'approved'; | ||
const owner = context.repo.owner; | ||
const repo = context.repo.repo; | ||
const pull_number = context.payload.pull_request.number; | ||
|
||
if (approved) { | ||
const { data: collaborators } = await github.repos.listCollaborators({ owner, repo }); | ||
const reviewer = context.payload.review.user.login; | ||
const isOwner = collaborators.some(collab => collab.login === reviewer && collab.permissions.admin); | ||
|
||
if (isOwner) { | ||
await github.issues.addLabels({ | ||
owner, | ||
repo, | ||
issue_number: pull_number, | ||
labels: ['approved','auto merge'] | ||
}); | ||
} | ||
} | ||
const { owner, repo } = context.repo; | ||
const { pull_request, review } = context.payload; | ||
|
||
// Define your list of collaborators | ||
const collaborators = ['mxsm', 'TeslaRustor','SpaceXCN']; // Replace with actual GitHub usernames | ||
|
||
// Check if the review is approved and from a collaborator | ||
const isApprovedByCollaborator = review.state === 'approved' && collaborators.includes(review.user.login); | ||
|
||
// Return the result to the workflow | ||
return { approvedByCollaborator: isApprovedByCollaborator, pullRequestNumber: pull_request.number }; | ||
|
||
- name: Add label if approved by Collaborators | ||
if: steps.check_approval.outputs.approvedByCollaborator == true | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ secrets.PAT_TOKEN }} | ||
script: | | ||
const { owner, repo } = context.repo; | ||
const { pullRequestNumber } = steps.check_approval.outputs; | ||
|
||
// Add your label here | ||
const labelToAdd = 'approved-by-collaborator'; | ||
|
||
// Add the label to the pull request | ||
await github.rest.issues.addLabels({ | ||
owner, | ||
repo, | ||
issue_number: pullRequestNumber, | ||
labels: ['approved','auto merge'] | ||
}); |
Oops, something went wrong.
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.
Typographical error in collaborators list, missing a comma.
Committable suggestion