-
Notifications
You must be signed in to change notification settings - Fork 0
62 lines (56 loc) · 1.87 KB
/
triager.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
name: Triage Labeler
on:
issues:
types: [opened]
pull_request:
types: [opened]
jobs:
label-triage:
runs-on: ubuntu-latest
steps:
- name: Add triage label to new issues and PRs from non-collaborators
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const eventName = context.eventName;
let issueOrPR = eventName === 'issues' ? context.issue : context.payload.pull_request;
let username;
if (issueOrPR && issueOrPR.user && issueOrPR.user.login) {
username = issueOrPR.user.login;
} else {
console.log("Could not retrieve username from the event payload.");
return;
}
const repoOwner = context.repo.owner;
const repoName = context.repo.repo;
async function isCollaborator(username) {
try {
await github.rest.repos.checkCollaborator({
owner: repoOwner,
repo: repoName,
username: username,
});
return true;
} catch (error) {
return false;
}
}
if (!await isCollaborator(username)) {
const labels = ['triage'];
if (eventName === 'issues') {
await github.rest.issues.addLabels({
owner: repoOwner,
repo: repoName,
issue_number: issueOrPR.number,
labels: labels
});
} else {
await github.rest.issues.addLabels({
owner: repoOwner,
repo: repoName,
issue_number: issueOrPR.number,
labels: labels
});
}
}