Skip to content

Commit

Permalink
Update label-on-approval.yml (#571)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsm authored Jun 15, 2024
1 parent 28fc7b7 commit eca3015
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions .github/workflows/label-on-approval.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Add Label on Approval

on:
pull_request_target:
types: [ submitted,edited ]
types: [submitted, edited]
branches: [main]

permissions:
Expand All @@ -12,6 +12,9 @@ permissions:
jobs:
add-label:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write

steps:
- name: Checkout code
Expand All @@ -25,27 +28,19 @@ jobs:
script: |
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
console.log('state:', review.state);
console.log('review:', review.state === 'approved');
console.log('Collaborators:', collaborators);
console.log('User:', collaborators.includes(review.user.login));
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);
console.log('isApprovedByCollaborator:', isApprovedByCollaborator);
console.log('pull_request:', pull_request.number);
const isApprovedByCollaborator = review && review.state === 'approved' && collaborators.includes(review.user.login);
// Return the result to the workflow
if (isApprovedByCollaborator) {
if (isApprovedByCollaborator) {
await github.rest.issues.addLabels({
owner,
repo,
issue_number: pull_request.number,
labels: ['approved','auto merge']
labels: ['approved', 'auto merge']
});
}

0 comments on commit eca3015

Please sign in to comment.