-
Notifications
You must be signed in to change notification settings - Fork 3
56 lines (50 loc) · 1.88 KB
/
check-external-contributor.yml
File metadata and controls
56 lines (50 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
name: Check External Contributor
on:
workflow_call:
inputs:
github_team_slug:
type: string
required: true
description: "GitHub team slug to check membership against (e.g., 'devs')"
label_name:
type: string
required: false
default: "external contributor"
description: "Label to add to PR if creator is not in the team"
secrets:
GITHUB_TOKEN:
required: true
permissions:
pull-requests: write
jobs:
check-contributor:
name: Check PR Creator Team Membership
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Check if PR creator is in team
id: check-team
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const { data: teams } = await github.rest.teams.listMembershipsForAuthenticatedUser();
const teamSlugs = teams.map(team => team.slug);
const teamSlug = '${{ inputs.github_team_slug }}';
const isMember = teamSlugs.includes(teamSlug);
console.log(`Looking for team: ${teamSlug}`);
console.log(`User's teams: ${teamSlugs.join(', ')}`);
console.log(`Is member: ${isMember}`);
core.setOutput('is_member', isMember);
- name: Add external contributor label
if: steps.check-team.outputs.is_member == 'false'
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const labelName = '${{ inputs.label_name }}';
github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: [labelName]
});
console.log(`Added label "${labelName}" to PR #${context.issue.number}`);