@@ -3,40 +3,39 @@ import { context } from '@actions/github'
33import type { ICommittersDetails } from './interfaces.js'
44
55interface IGraphQlUser {
6- id : string
7- databaseId : number
8- login : string
6+ id : string
7+ databaseId : number
8+ login : string
99}
1010
1111interface IGraphQlCommit {
12- author : { email : string ; name : string ; user : IGraphQlUser | null }
13- committer : { name : string ; user : IGraphQlUser | null }
12+ author : { email : string ; name : string ; user : IGraphQlUser | null }
13+ committer : { name : string ; user : IGraphQlUser | null }
1414}
1515
1616interface IGraphQlEdge {
17- node : { commit : IGraphQlCommit }
18- cursor : string
17+ node : { commit : IGraphQlCommit }
18+ cursor : string
1919}
2020
2121interface IGraphQlResponse {
22- repository : {
23- pullRequest : {
24- commits : {
25- totalCount : number
26- edges : IGraphQlEdge [ ]
27- pageInfo : { endCursor : string ; hasNextPage : boolean }
28- }
29- }
22+ repository : {
23+ pullRequest : {
24+ commits : {
25+ totalCount : number
26+ edges : IGraphQlEdge [ ]
27+ pageInfo : { endCursor : string ; hasNextPage : boolean }
28+ }
3029 }
30+ }
3131}
3232
33-
34-
3533export default async function getCommitters ( ) : Promise < ICommittersDetails [ ] > {
36- try {
37- const committers : ICommittersDetails [ ] = [ ]
38- let filteredCommitters : ICommittersDetails [ ] = [ ]
39- const response = await octokit . graphql < IGraphQlResponse > ( `
34+ try {
35+ const committers : ICommittersDetails [ ] = [ ]
36+ let filteredCommitters : ICommittersDetails [ ] = [ ]
37+ const response = await octokit . graphql < IGraphQlResponse > (
38+ `
4039 query($owner:String! $name:String! $number:Int! $cursor:String!){
4140 repository(owner: $owner, name: $name) {
4241 pullRequest(number: $number) {
@@ -73,33 +72,44 @@ export default async function getCommitters(): Promise<ICommittersDetails[]> {
7372 }
7473 }
7574 }
76- }` . replace ( / / g, '' ) , {
77- owner : context . repo . owner ,
78- name : context . repo . repo ,
79- number : context . issue . number ,
80- cursor : ''
81- } )
82- response . repository . pullRequest . commits . edges . forEach ( ( edge : IGraphQlEdge ) => {
83- const committer = extractUserFromCommit ( edge . node . commit )
84- const user = {
85- name : committer . login || committer . name ,
86- id : committer . databaseId || '' ,
87- pullRequestNo : context . issue . number
88- }
89- if ( committers . length === 0 || committers . map ( ( c ) => {
90- return c . name
91- } ) . indexOf ( user . name ) < 0 ) {
92- committers . push ( user )
93- }
94- } )
95- filteredCommitters = committers . filter ( ( committer ) => {
96- return committer . id !== 41898282
97- } )
98- return filteredCommitters
99-
100- } catch ( e ) {
101- throw new Error ( `graphql call to get the committers details failed: ${ e } ` )
102- }
103-
75+ }` . replace ( / / g, '' ) ,
76+ {
77+ owner : context . repo . owner ,
78+ name : context . repo . repo ,
79+ number : context . issue . number ,
80+ cursor : ''
81+ }
82+ )
83+ response . repository . pullRequest . commits . edges . forEach (
84+ ( edge : IGraphQlEdge ) => {
85+ const committer = extractUserFromCommit ( edge . node . commit )
86+ const user = {
87+ name : committer . login || committer . name ,
88+ id : committer . databaseId || '' ,
89+ pullRequestNo : context . issue . number
90+ }
91+ if (
92+ committers . length === 0 ||
93+ committers
94+ . map ( c => {
95+ return c . name
96+ } )
97+ . indexOf ( user . name ) < 0
98+ ) {
99+ committers . push ( user )
100+ }
101+ }
102+ )
103+ filteredCommitters = committers . filter ( committer => {
104+ return committer . id !== 41898282
105+ } )
106+ return filteredCommitters
107+ } catch ( e ) {
108+ throw new Error ( `graphql call to get the committers details failed: ${ e } ` )
109+ }
104110}
105- const extractUserFromCommit = ( commit ) => commit . author . user || commit . committer . user || commit . author || commit . committer
111+ const extractUserFromCommit = commit =>
112+ commit . author . user ||
113+ commit . committer . user ||
114+ commit . author ||
115+ commit . committer
0 commit comments