Skip to content

Commit 31dcb0c

Browse files
committed
Add membership check to auto-approve workflows for org members
Signed-off-by: milinddethe15 <milinddethe15@gmail.com>
1 parent 34df218 commit 31dcb0c

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

.github/workflows/gh-workflow-approve.yaml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,35 @@ concurrency:
1616

1717
jobs:
1818
ok-to-test:
19-
if: contains(github.event.pull_request.labels.*.name, 'ok-to-test')
19+
if: contains(github.event.pull_request.labels.*.name, 'ok-to-test') || github.event_name == 'pull_request_target'
2020
runs-on: ubuntu-latest
2121
continue-on-error: true
2222

2323
steps:
24+
- name: Check if author is a Kubeflow GitHub member
25+
id: membership-check
26+
uses: actions/github-script@v7
27+
with:
28+
script: |
29+
const username = context.payload.pull_request.user.login;
30+
const org = context.repo.owner;
31+
try {
32+
const res = await github.rest.orgs.checkMembershipForUser({
33+
org,
34+
username
35+
});
36+
core.setOutput("is_member", true);
37+
} catch (error) {
38+
if (error.status === 404) {
39+
// User is not a member
40+
core.setOutput("is_member", false);
41+
} else {
42+
throw error;
43+
}
44+
}
45+
2446
- name: Approve Pending Workflow Runs
47+
if: steps.membership-check.outputs.is_member == 'true' || contains(github.event.pull_request.labels.*.name, 'ok-to-test')
2548
uses: actions/github-script@v7
2649
with:
2750
retries: 3

0 commit comments

Comments
 (0)