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 119
Expand file tree
/
Copy pathgraphql.ts
More file actions
76 lines (73 loc) · 2.83 KB
/
graphql.ts
File metadata and controls
76 lines (73 loc) · 2.83 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
import { octokit } from './octokit'
import { context } from '@actions/github'
import { CommittersDetails } from './interfaces'
import { getPrNumber } from './shared/getInputs'
export default async function getCommitters(): Promise<CommittersDetails[]> {
try {
let committers: CommittersDetails[] = []
let filteredCommitters: CommittersDetails[] = []
let response: any = await octokit.graphql(`
query($owner:String! $name:String! $number:Int! $cursor:String!){
repository(owner: $owner, name: $name) {
pullRequest(number: $number) {
commits(first: 100, after: $cursor) {
totalCount
edges {
node {
commit {
author {
email
name
user {
id
databaseId
login
}
}
committer {
name
user {
id
databaseId
login
}
}
}
}
cursor
}
pageInfo {
endCursor
hasNextPage
}
}
}
}
}`.replace(/ /g, ''), {
owner: context.repo.owner,
name: context.repo.repo,
number: getPrNumber(context.issue.number),
cursor: ''
})
response.repository.pullRequest.commits.edges.forEach(edge => {
const committer = extractUserFromCommit(edge.node.commit)
let user = {
name: committer.login || committer.name,
id: committer.databaseId || '',
pullRequestNo: getPrNumber(context.issue.number)
}
if (committers.length === 0 || committers.map((c) => {
return c.name
}).indexOf(user.name) < 0) {
committers.push(user)
}
})
filteredCommitters = committers.filter((committer) => {
return committer.id !== 41898282
})
return filteredCommitters
} 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