Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 12 additions & 1 deletion .github/workflows/authorChecklist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,22 @@ on:
paths-ignore: ['docs/articles/**/*.md', 'docs/redirects.csv', 'docs/assets/images/**']

jobs:
validate:
uses: ./.github/workflows/contributorValidationGate.yml
with:
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
AUTHOR_ASSOCIATION: ${{ github.event.pull_request.author_association }}

# Note: PHP specifically looks for the name of this job, "checklist", so if the name of the job is changed,
# then you also need to go into PHP and update the name of this job in the GH_JOB_NAME_CHECKLIST constant
checklist:
needs: [validate]
runs-on: blacksmith-2vcpu-ubuntu-2404
if: github.actor != 'OSBotify' && github.actor != 'imgbot[bot]'
if: |
needs.validate.outputs.IS_AUTHORIZED == 'true'
&& github.actor != 'OSBotify'
&& github.actor != 'imgbot[bot]'
steps:
- name: Checkout
# v4
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/cla.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ on:
branches: [main]

jobs:
validate:
if: ${{ github.event_name == 'pull_request_target' }}
uses: ./.github/workflows/contributorValidationGate.yml
with:
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
AUTHOR_ASSOCIATION: ${{ github.event.pull_request.author_association }}

CLA:
needs: [validate]
if: |
always()
&& (github.event_name == 'issue_comment' || needs.validate.outputs.IS_AUTHORIZED == 'true')
Comment thread
MonilBhavsar marked this conversation as resolved.
Resolved
uses: Expensify/GitHub-Actions/.github/workflows/cla.yml@main
secrets: inherit
13 changes: 12 additions & 1 deletion .github/workflows/claude-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,19 @@ concurrency:
cancel-in-progress: true

jobs:
validate:
uses: ./.github/workflows/contributorValidationGate.yml

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Grant issue-read scope before calling contributor gate

Calling contributorValidationGate.yml from this workflow can misclassify legitimate external contributors as unauthorized, because the gate uses github.rest.issues.get to validate linked assigned issues, but this workflow only grants contents and pull-requests permissions. With GitHub Actions permissions, omitted scopes are none, so issue lookups fail and PRs that should pass via linked-issue assignment will skip Claude review.

Useful? React with 👍 / 👎.

with:
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
AUTHOR_ASSOCIATION: ${{ github.event.pull_request.author_association }}

review:
if: github.event.pull_request.draft != true && !contains(github.event.pull_request.title, 'Revert')
needs: [validate]
if: |
needs.validate.outputs.IS_AUTHORIZED == 'true'
&& github.event.pull_request.draft != true
&& !contains(github.event.pull_request.title, 'Revert')
runs-on: blacksmith-2vcpu-ubuntu-2404
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
Expand Down
129 changes: 129 additions & 0 deletions .github/workflows/contributorValidationGate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Reusable workflow that checks whether a PR author is authorized to contribute.
# Used by expensive PR workflows to skip CI for unauthorized contributors.
# The actual close/lock/comment logic lives in validateContributorPR.yml.

name: Contributor Validation Gate

on:
workflow_call:
inputs:
PR_NUMBER:
description: Pull request number
required: true
type: number
PR_AUTHOR:
description: Pull request author login
required: true
type: string
AUTHOR_ASSOCIATION:
description: "Author's association with the repository (MEMBER, OWNER, CONTRIBUTOR, etc.)"
required: true
type: string
outputs:
IS_AUTHORIZED:
description: "'true' if the contributor is authorized, 'false' otherwise"
value: ${{ jobs.check.outputs.IS_AUTHORIZED }}

jobs:
check:
runs-on: blacksmith-2vcpu-ubuntu-2404
outputs:
IS_AUTHORIZED: ${{ steps.gate.outputs.IS_AUTHORIZED }}
steps:
- name: Check contributor authorization
id: gate
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd
with:
script: |
const prNumber = ${{ inputs.PR_NUMBER }};
const prAuthor = '${{ inputs.PR_AUTHOR }}';
const authorAssociation = '${{ inputs.AUTHOR_ASSOCIATION }}';

if (['MEMBER', 'OWNER', 'CONTRIBUTOR'].includes(authorAssociation)) {
console.log(`${prAuthor} is ${authorAssociation}. Authorized.`);
core.setOutput('IS_AUTHORIZED', 'true');
return;
}

console.log(`${prAuthor} has association "${authorAssociation}". Checking linked issues/PRs...`);

const {data: pr} = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});

const prBody = pr.body || '';
const cleanBody = prBody.replace(/<!--[\s\S]*?-->/g, '');

const issuePattern = /https:\/\/github\.com\/(Expensify\/[^/]+)\/issues\/(\d+)/g;
let match;
while ((match = issuePattern.exec(cleanBody)) !== null) {
const [, repo, num] = match;
const issueNumber = parseInt(num);
try {
const [owner, repoName] = repo.split('/');
const {data: issue} = await github.rest.issues.get({
owner,
repo: repoName,
issue_number: issueNumber,
});
if (issue.assignees.some(a => a.login.toLowerCase() === prAuthor.toLowerCase())) {
console.log(`${prAuthor} is assigned to ${repo}#${issueNumber}. Authorized.`);
core.setOutput('IS_AUTHORIZED', 'true');
return;
}
console.log(`${prAuthor} is NOT assigned to ${repo}#${issueNumber}.`);
} catch (e) {
console.log(`Could not verify ${repo}#${issueNumber}: ${e.message}`);
}
}

const prUrlPattern = /https:\/\/github\.com\/(Expensify\/[^/]+)\/pull\/(\d+)/g;
while ((match = prUrlPattern.exec(cleanBody)) !== null) {
const [, repo, num] = match;
const linkedPRNumber = parseInt(num);
try {
const [owner, repoName] = repo.split('/');

const {data: linkedPR} = await github.rest.pulls.get({
owner,
repo: repoName,
pull_number: linkedPRNumber,
});
if (linkedPR.user.login.toLowerCase() === prAuthor.toLowerCase()) {
console.log(`${prAuthor} is the author of ${repo}#${linkedPRNumber}. Authorized.`);
core.setOutput('IS_AUTHORIZED', 'true');
return;
}

const {data: reviews} = await github.rest.pulls.listReviews({
owner,
repo: repoName,
pull_number: linkedPRNumber,
});
if (reviews.some(r => r.user?.login?.toLowerCase() === prAuthor.toLowerCase())) {
console.log(`${prAuthor} is a reviewer of ${repo}#${linkedPRNumber}. Authorized.`);
core.setOutput('IS_AUTHORIZED', 'true');
return;
}

const {data: requestedReviewers} = await github.rest.pulls.listRequestedReviewers({
owner,
repo: repoName,
pull_number: linkedPRNumber,
});
if (requestedReviewers.users.some(u => u.login.toLowerCase() === prAuthor.toLowerCase())) {
console.log(`${prAuthor} is a requested reviewer of ${repo}#${linkedPRNumber}. Authorized.`);
core.setOutput('IS_AUTHORIZED', 'true');
return;
}

console.log(`${prAuthor} is not author or reviewer of ${repo}#${linkedPRNumber}.`);
} catch (e) {
console.log(`Could not verify ${repo}#${linkedPRNumber}: ${e.message}`);
}
}

console.log(`No valid authorization found for ${prAuthor}.`);
core.setOutput('IS_AUTHORIZED', 'false');
66 changes: 23 additions & 43 deletions .github/workflows/validateContributorPR.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Validates that external contributors are authorized to submit PRs.
# Calls the reusable gate workflow, then closes + locks unauthorized PRs.

name: Validate Contributor PRs

on:
Expand All @@ -11,54 +14,24 @@ permissions:

jobs:
validate:
runs-on: blacksmith-2vcpu-ubuntu-2404
if: ${{ !github.event.pull_request.draft && github.event.pull_request.user.type != 'Bot' }}
uses: ./.github/workflows/contributorValidationGate.yml
with:
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
AUTHOR_ASSOCIATION: ${{ github.event.pull_request.author_association }}

close-if-unauthorized:
needs: [validate]
if: needs.validate.outputs.IS_AUTHORIZED == 'false'
runs-on: blacksmith-2vcpu-ubuntu-2404
steps:
- name: Validate contributor authorization
- name: Close PR and leave comment
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd
with:
script: |
const prNumber = context.payload.pull_request.number;
const prAuthor = context.payload.pull_request.user.login;
const authorAssociation = context.payload.pull_request.author_association;

// Step 1: Allow org members, non-first time contributors, and repo owners
if (['MEMBER', 'OWNER', 'CONTRIBUTOR'].includes(authorAssociation)) {
console.log(`${prAuthor} is an org ${authorAssociation}. No validation needed.`);
return;
}

console.log(`${prAuthor} has association "${authorAssociation}". Validating linked issues...`);

const prBody = context.payload.pull_request.body || '';
// Strip HTML comments to avoid matching template placeholders
const cleanBody = prBody.replace(/<!--[\s\S]*?-->/g, '');

// Step 2: Check linked issues — is the PR author assigned to any?
const issuePattern = /https:\/\/github\.com\/(Expensify\/[^/]+)\/issues\/(\d+)/g;
let match;
while ((match = issuePattern.exec(cleanBody)) !== null) {
const [, repo, num] = match;
const issueNumber = parseInt(num);
try {
const [owner, repoName] = repo.split('/');
const {data: issue} = await github.rest.issues.get({
owner,
repo: repoName,
issue_number: issueNumber,
});
if (issue.assignees.some(a => a.login.toLowerCase() === prAuthor.toLowerCase())) {
console.log(`${prAuthor} is assigned to ${repo}#${issueNumber}. PR is authorized.`);
return;
}
console.log(`${prAuthor} is NOT assigned to ${repo}#${issueNumber}.`);
} catch (e) {
console.log(`Could not verify ${repo}#${issueNumber}: ${e.message}`);
}
}

// Step 3: Validation failed — close the PR
console.log(`Closing PR #${prNumber} by ${prAuthor} — no valid authorization found.`);
const prNumber = ${{ github.event.pull_request.number }};
const prAuthor = '${{ github.event.pull_request.user.login }}';

await github.rest.issues.createComment({
owner: context.repo.owner,
Expand Down Expand Up @@ -90,3 +63,10 @@ jobs:
pull_number: prNumber,
state: 'closed',
});

await github.rest.issues.lock({
Comment thread
MonilBhavsar marked this conversation as resolved.
Resolved
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
lock_reason: 'spam',
});
Loading