-
Notifications
You must be signed in to change notification settings - Fork 122
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
[ISSUE #542]🔨Add auto add label for pr approval #543
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,41 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
name: Label on Approval | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
on: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pull_request_review: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
types: [ submitted ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
jobs: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
add-label-on-approval: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
steps: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- name: Checkout repository | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
uses: actions/checkout@v2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- name: Check for approval and add label | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
uses: actions/github-script@v6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
env: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
with: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
script: | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const github = require('@actions/github'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const context = github.context; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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'] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+26
to
+38
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. Ensure robustness by handling potential errors during API calls, such as when adding labels or fetching collaborators. + try {
await github.issues.addLabels({
owner,
repo,
issue_number: pull_number,
labels: ['approved','auto merge']
});
+ } catch (error) {
+ console.error('Failed to add labels:', error);
+ } Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
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.
Consider using
GITHUB_TOKEN
for authentication to follow best practices and ensure security.Committable suggestion