Skip to content

[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
merged 14 commits into from
Jun 14, 2024
Merged
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 41 additions & 28 deletions .github/workflows/label-on-approval.yml
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

Copy link
Contributor

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.

- const collaborators = ['mxsm', 'TeslaRustor','SpaceXCN'];
+ const collaborators = ['mxsm', 'TeslaRustor', 'SpaceXCN'];
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const collaborators = ['mxsm', 'TeslaRustor','SpaceXCN']; // Replace with actual GitHub usernames
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']
});
Loading