-
Notifications
You must be signed in to change notification settings - Fork 0
/
gh-invite.js
52 lines (48 loc) · 1.29 KB
/
gh-invite.js
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
export default async function (github, owner, user, core) {
core.info('Checking membership and invitation status...')
try {
// check failed invites
const failedInvites = await github.rest.orgs.listFailedInvitations({
org: owner,
per_page: 100
})
const failedInvite = failedInvites.data.find((i) => i.login === user.login)
if (failedInvite) {
core.debug('Invitation failed')
return
}
// check pending invites
const pendingInvites = await github.rest.orgs.listPendingInvitations({
org: owner,
per_page: 100
})
const pendingInvite = pendingInvites.data.find(
(i) => i.login === user.login
)
if (pendingInvite) {
core.debug('Invitation pending')
return
}
// check membership status
const isMember = await github.rest.orgs.getMembershipForUser({
org: owner,
username: user.login
})
if (isMember) {
return
}
// invite is not pending or failed, user is not a member, let's invite
core.info('Inviting user')
await github.rest.orgs.createInvitation({
org: owner,
invitee_id: user.id
})
} catch (err) {
if (err.status === 404) {
await github.rest.orgs.createInvitation({
org: owner,
invitee_id: user.id
})
}
}
}