Refactor PR author validation in workflow

Updated the GitHub Actions workflow to restrict PR authors by modifying the allowed users list and changing the validation logic.
This commit is contained in:
شركة خبير المحدودة 2025-11-21 22:44:17 +02:00 committed by GitHub
parent 6f7268073c
commit 4229f6ae4e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 19 deletions

View File

@ -1,6 +1,10 @@
# Author: Moutaz (restrict PR authors) # Author: Moutaz (restrict PR authors)
name: Restrict PR Authors name: Restrict PR Authors
permissions:
contents: read
pull-requests: write
on: on:
pull_request: pull_request:
types: [opened, reopened] types: [opened, reopened]
@ -28,36 +32,26 @@ on:
- dev_odex25_donation - dev_odex25_donation
jobs: jobs:
restrict-author: validate:
runs-on: linting_odex25-standard-modules_runner runs-on: linting_odex25-standard-modules_runner
steps: steps:
- name: Validate PR Author - name: Check PR Author
uses: actions/github-script@v7 uses: actions/github-script@v7
with: with:
github-token: ${{ secrets.PR_CLOSE_TOKEN }} # 👈 ضروري
script: | script: |
const allowedUsers = [ const allowed = ["ahmad-samir", "moutazmuhammad"];
"ahmad-samir", const author = context.payload.pull_request.user.login;
"expdevops",
"whatever-user"
];
const pr = context.payload.pull_request; core.info(`PR Author: ${author}`);
const author = pr.user.login;
console.log("PR Author:", author);
if (!allowedUsers.includes(author)) {
console.log(`❌ User '${author}' is NOT allowed to open PRs. Closing PR...`);
if (!allowed.includes(author)) {
core.error(`User '${author}' is NOT allowed. Closing PR...`);
await github.rest.pulls.update({ await github.rest.pulls.update({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
pull_number: pr.number, pull_number: context.payload.pull_request.number,
state: "closed" state: "closed"
}); });
core.setFailed("PR automatically closed. Unauthorized author.");
} else {
console.log("✅ Author is allowed to open PR.");
} }