Skip to content

update config file

update config file #99

name: Add Label on Approval
on:
pull_request_target:
types: [opened, synchronize]
pull_request_review:
types: [submitted]
permissions:
issues: write
pull-requests: write
jobs:
setup:
if: github.event_name == 'pull_request_target'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Authenticate with GitHub App
id: auth
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.PRIVATE_KEY }}
- name: Set GitHub Token to environment
run: echo "GITHUB_TOKEN=${{ steps.auth.outputs.token }}" >> $GITHUB_ENV
add-label:
if: github.event_name == 'pull_request_review' && github.event.review.state == 'approved'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check if approval is from Collaborators
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }} # or ${{ env.GITHUB_TOKEN }} if using environment variable
script: |
const { owner, repo } = context.repo;
const { pull_request, review } = context.payload;
if (!review) {
console.log('No review found.');
return;
}
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);
if (isApprovedByCollaborator) {
await github.rest.issues.addLabels({
owner,
repo,
issue_number: pull_request.number,
labels: ['approved', 'auto merge']
});
}