-
Notifications
You must be signed in to change notification settings - Fork 1
141 lines (119 loc) · 4.74 KB
/
new-issue-or-pr.yml
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: Label Issues and PRs on Open/Reopen
on:
issues:
types: [opened, reopened] # Trigger when an issue is opened or reopened
pull_request:
types: [opened, reopened] # Trigger when a PR is opened or reopened
jobs:
labelIssuePR:
name: Apply Label to Issues and PRs
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Add Label to Issue or PR
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Check if it's an issue or a PR
if (context.eventName === 'issues') {
// Add label to issue
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['needs-team-review']
});
} else if (context.eventName === 'pull_request') {
// Add label to PR
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
labels: ['needs-team-review']
});
}
result-encoding: string
id: result
- name: Get result
run: echo "${{steps.result.outputs.result}}"
- name: Get Author Information
id: get_author
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const authorLogin = context.payload.pull_request ? context.payload.pull_request.user.login : context.payload.issue.user.login;
echo $authorLogin
return authorLogin;
- name: Get Organization Members
id: get_org_members
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const org = context.repo.owner; // Organization name
let allMembers = [];
let page = 1;
while (true) {
const membersPage = await github.orgs.members({
org: org,
page: page,
per_page: 100
});
allMembers = allMembers.concat(membersPage.data);
if (membersPage.data.length < 100) {
break; // No more pages to fetch
}
page++;
}
return allMembers.map(member => member.login);
- name: Determine if Author is External
run: |
echo "Author: ${{ steps.get_author.outputs.result }}"
echo "Organization Members: ${{ steps.get_org_members.outputs.result }}"
AUTHOR="${{ steps.get_author.outputs.result }}"
ORG_MEMBERS="${{ steps.get_org_members.outputs.result }}"
if echo "$ORG_MEMBERS" | grep -q "$AUTHOR"; then
echo "The author $AUTHOR is a member of the organization."
else
echo "The author $AUTHOR is an external contributor."
fi
- name: Check if author is external and label accordingly
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issueOrPr = context.payload.issue || context.payload.pull_request;
echo $issueOrPr
const author = issueOrPr.user.login; // Get the author of the issue or PR
echo $author
const authorLogin = context.payload.pull_request ? context.payload.pull_request.user.login : context.payload.issue.user.login;
echo $authorLogin
// Define a list of team members (replace with your team's GitHub usernames)
const teamMembers = ['member1', 'member2', 'member3'];
const author = context.event.pull_request.user.login;
const owner = context.repo.owner;
const repo = context.repo.repo;
let isCollaborator = false;
// Check if the author is a collaborator in the repository
try {
await github.rest.repos.checkCollaborator({
owner: owner,
repo: repo,
username: author
});
isCollaborator = true;
} catch (error) {
isCollaborator = false;
}
// If the author is not a collaborator, mark as "external"
if (!isCollaborator) {
await github.rest.issues.addLabels({
owner: owner,
repo: repo,
issue_number: context.payload.pull_request.number,
labels: ['external']
});
}