@@ -5,8 +5,8 @@ import { hideBin } from 'yargs/helpers';
55import fs from 'fs' ;
66import util from 'util' ;
77
8- import { CommitData , PushData } from '@finos/git-proxy/types' ;
98import { PushQuery } from '@finos/git-proxy/db' ;
9+ import { Action } from '@finos/git-proxy/proxy/actions' ;
1010
1111const GIT_PROXY_COOKIE_FILE = 'git-proxy-cookie' ;
1212// GitProxy UI HOST and PORT (configurable via environment variable)
@@ -88,74 +88,86 @@ async function getGitPushes(filters: Partial<PushQuery>) {
8888
8989 try {
9090 const cookies = JSON . parse ( fs . readFileSync ( GIT_PROXY_COOKIE_FILE , 'utf8' ) ) ;
91-
92- const response = await axios . get ( `${ baseUrl } /api/v1/push/` , {
91+ const { data } = await axios . get < Action [ ] > ( `${ baseUrl } /api/v1/push/` , {
9392 headers : { Cookie : cookies } ,
9493 params : filters ,
9594 } ) ;
9695
97- const records : PushData [ ] = [ ] ;
98- response . data . forEach ( ( push : PushData ) => {
99- const record : PushData = {
100- id : push . id ,
101- repo : push . repo ,
102- branch : push . branch ,
103- commitFrom : push . commitFrom ,
104- commitTo : push . commitTo ,
105- commitData : push . commitData ,
106- diff : push . diff ,
107- error : push . error ,
108- canceled : push . canceled ,
109- rejected : push . rejected ,
110- blocked : push . blocked ,
111- authorised : push . authorised ,
112- attestation : push . attestation ,
113- autoApproved : push . autoApproved ,
114- timestamp : push . timestamp ,
115- url : push . url ,
116- allowPush : push . allowPush ,
96+ const records = data . map ( ( push : Action ) => {
97+ const {
98+ id,
99+ repo,
100+ branch,
101+ commitFrom,
102+ commitTo,
103+ commitData,
104+ error,
105+ canceled,
106+ rejected,
107+ blocked,
108+ authorised,
109+ attestation,
110+ autoApproved,
111+ timestamp,
112+ url,
113+ allowPush,
114+ lastStep,
115+ } = push ;
116+
117+ return {
118+ id,
119+ repo,
120+ branch,
121+ commitFrom,
122+ commitTo,
123+ commitData : commitData ?. map (
124+ ( {
125+ message,
126+ committer,
127+ committerEmail,
128+ author,
129+ authorEmail,
130+ commitTimestamp,
131+ tree,
132+ parent,
133+ } ) => ( {
134+ message,
135+ committer,
136+ committerEmail,
137+ author,
138+ authorEmail,
139+ commitTimestamp,
140+ tree,
141+ parent,
142+ } ) ,
143+ ) ,
144+ error,
145+ canceled,
146+ rejected,
147+ blocked,
148+ authorised,
149+ attestation,
150+ autoApproved,
151+ timestamp,
152+ url,
153+ allowPush,
154+ lastStep : lastStep && {
155+ id : lastStep . id ,
156+ content : lastStep . content ,
157+ logs : lastStep . logs ,
158+ stepName : lastStep . stepName ,
159+ error : lastStep . error ,
160+ errorMessage : lastStep . errorMessage ,
161+ blocked : lastStep . blocked ,
162+ blockedMessage : lastStep . blockedMessage ,
163+ } ,
117164 } ;
118-
119- if ( push . lastStep ) {
120- record . lastStep = {
121- id : push . lastStep ?. id ,
122- content : push . lastStep ?. content ,
123- logs : push . lastStep ?. logs ,
124- stepName : push . lastStep ?. stepName ,
125- error : push . lastStep ?. error ,
126- errorMessage : push . lastStep ?. errorMessage ,
127- blocked : push . lastStep ?. blocked ,
128- blockedMessage : push . lastStep ?. blockedMessage ,
129- } ;
130- }
131-
132- if ( push . commitData ) {
133- const commitData : CommitData [ ] = [ ] ;
134- push . commitData . forEach ( ( pushCommitDataRecord : CommitData ) => {
135- commitData . push ( {
136- message : pushCommitDataRecord . message ,
137- committer : pushCommitDataRecord . committer ,
138- committerEmail : pushCommitDataRecord . committerEmail ,
139- author : pushCommitDataRecord . author ,
140- authorEmail : pushCommitDataRecord . authorEmail ,
141- commitTimestamp : pushCommitDataRecord . commitTimestamp ,
142- tree : pushCommitDataRecord . tree ,
143- parent : pushCommitDataRecord . parent ,
144- commitTs : pushCommitDataRecord . commitTs ,
145- } ) ;
146- } ) ;
147- record . commitData = commitData ;
148- }
149-
150- records . push ( record ) ;
151165 } ) ;
152166
153- console . log ( ` ${ util . inspect ( records , false , null , false ) } ` ) ;
167+ console . log ( util . inspect ( records , false , null , false ) ) ;
154168 } catch ( error : any ) {
155- // default error
156- const errorMessage = `Error: List: '${ error . message } '` ;
169+ console . error ( `Error: List: '${ error . message } '` ) ;
157170 process . exitCode = 2 ;
158- console . error ( errorMessage ) ;
159171 }
160172}
161173
0 commit comments