This repository was archived by the owner on Mar 23, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 120
Expand file tree
/
Copy pathgraphql.ts
More file actions
119 lines (116 loc) · 4.92 KB
/
graphql.ts
File metadata and controls
119 lines (116 loc) · 4.92 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
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
import * as octokit from './octokit'
import { context } from '@actions/github'
import { CommittersDetails } from './interfaces'
import * as core from '@actions/core'
export default async function getCommitters(): Promise<CommittersDetails[]> {
try {
let client = (octokit.isPersonalAccessTokenPresent()) ? octokit.getPATOctokit() : octokit.octokit
let committers: CommittersDetails[] = []
let desiredSignatories: CommittersDetails[] = []
let response: any = await client.graphql(`
query($owner:String! $name:String! $number:Int! $cursor:String!){
organization(login: $owner) {
membersWithRole(first: 100) {
edges {
node {
login
}
}
}
}
repository(owner: $owner, name: $name) {
pullRequest(number: $number) {
commits(first: 100, after: $cursor) {
totalCount
edges {
node {
commit {
author {
email
name
user {
id
databaseId
login
organizations(first: 100) {
nodes {
login
}
}
}
}
committer {
name
user {
id
databaseId
login
organizations(first: 100) {
nodes {
login
}
}
}
}
}
}
cursor
}
pageInfo {
endCursor
hasNextPage
}
}
}
}
}`.replace(/ /g, ''), {
owner: context.repo.owner,
name: context.repo.repo,
number: context.issue.number,
cursor: ''
})
response.repository.pullRequest.commits.edges.forEach(edge => {
core.debug(JSON.stringify(response.organization, undefined, 2))
const committer = extractUserFromCommit(edge.node.commit)
let user = {
name: committer.login || committer.name,
id: committer.databaseId || '',
pullRequestNo: context.issue.number,
orgLogins: committer.organizations.nodes.map(org => {
return org.login
})
}
if (committers.length === 0 || committers.map((c) => {
return c.name
}).indexOf(user.name) < 0) {
committers.push(user)
}
})
desiredSignatories = committers.filter((committer) => {
if (committer.id === 41898282) { // Filter this one out.
return false
}
if (core.getInput('exemptRepoOrgMembers')) {
// The `exemptRepoOrgMembers` input determines whether
// we automatically "allowlist" the members of the org
// owning the repository we are working in. If so, we
// can filter those committers here, thus allowing them
// to bypass the check informing them they need to sign
// the CLA.
let members = response.organization.membersWithRole.edges.map(edge => {
return edge.node.login
})
core.debug("Filtering based on these members:")
core.debug(JSON.stringify(members, undefined, 2))
core.debug("Current committer name to check for filtering:")
return ! members.includes(committer.name) // Negate so `includes()` filters out, not in.
}
return true
})
core.debug(JSON.stringify(desiredSignatories, undefined, 2))
return desiredSignatories
} catch (e) {
throw new Error(`graphql call to get the committers details failed: ${e}`)
}
}
const extractUserFromCommit = (commit) => commit.author.user || commit.committer.user || commit.author || commit.committer