1- // @ts -nocheck
21// @ts -ignore
32import blessed from 'blessed'
43import contrib from 'blessed-contrib'
@@ -39,7 +38,7 @@ export const analytics: CliSubcommand = {
3938 }
4039}
4140
42- const analyticsFlags : { [ key : string ] : any } = {
41+ const analyticsFlags = {
4342 scope : {
4443 type : 'string' ,
4544 shortFlag : 's' ,
@@ -161,9 +160,7 @@ type AnalyticsData = {
161160
162161type FormattedAnalyticsData = {
163162 [ key : string ] : {
164- [ key : string ] : number | {
165- [ key : string ] : number
166- }
163+ [ key : string ] : number
167164 }
168165}
169166
@@ -183,8 +180,6 @@ async function fetchOrgAnalyticsData (time: number, spinner: Ora, apiKey: string
183180
184181 const data = formatData ( result . data , 'org' )
185182
186- console . log ( data )
187-
188183 if ( outputJson ) {
189184 return console . log ( result . data )
190185 }
@@ -211,24 +206,24 @@ const formatDate = (date: string) => {
211206 return `${ months [ new Date ( date ) . getMonth ( ) ] } ${ new Date ( date ) . getDate ( ) } `
212207}
213208
214- const formatData = ( data : AnalyticsData [ ] , scope : string ) => {
209+ const formatData = ( data : any , scope : string ) => {
215210 let formattedData , sortedTopFivealerts
216211
217212 if ( scope === 'org' ) {
218- const topFiveAlerts = data . map ( d => d . top_five_alert_types || { } )
213+ const topFiveAlerts = data . map ( ( d : { [ k : string ] : any } ) => d [ ' top_five_alert_types' ] )
219214
220- const totalTopAlerts = topFiveAlerts . reduce ( ( acc , current : { [ key : string ] : number } ) => {
215+ const totalTopAlerts : { [ key : string ] : number } = topFiveAlerts . reduce ( ( acc : { [ k : string ] : number } , current : { [ key : string ] : number } ) => {
221216 const alertTypes = Object . keys ( current )
222217 alertTypes . map ( ( type : string ) => {
223218 if ( ! acc [ type ] ) {
224- acc [ type ] = current [ type ]
219+ acc [ type ] = current [ type ] !
225220 } else {
226- acc [ type ] += current [ type ]
221+ acc [ type ] += current [ type ] !
227222 }
228223 return acc
229224 } )
230225 return acc
231- } , { } as { [ k : string ] : any } )
226+ } , { } as { [ k : string ] : number } )
232227
233228
234229 sortedTopFivealerts = Object . entries ( totalTopAlerts )
@@ -237,32 +232,32 @@ const formatData = (data: AnalyticsData[], scope: string) => {
237232 . reduce ( ( r , [ k , v ] ) => ( { ...r , [ k ] : v } ) , { } )
238233
239234 const formatData = ( label : string ) => {
240- return data . reduce ( ( acc , current ) => {
241- const date : string = formatDate ( current . created_at )
235+ return data . reduce ( ( acc : { [ k : string ] : number } , current : { [ key : string ] : any } ) => {
236+ const date : string = formatDate ( current [ ' created_at' ] )
242237 if ( ! acc [ date ] ) {
243- acc [ date ] = current [ label ]
238+ acc [ date ] = current [ label ] !
244239 } else {
245- acc [ date ] += current [ label ]
240+ acc [ date ] += current [ label ] !
246241 }
247242 return acc
248- } , { } as { [ k : string ] : number } )
243+ } , { } )
249244 }
250245
251246 formattedData = METRICS . reduce ( ( acc , current : string ) => {
252247 acc [ current ] = formatData ( current )
253248 return acc
254- } , { } as { [ k : string ] : any } )
249+ } , { } as { [ k : string ] : number } )
255250
256251 } else if ( scope === 'repo' ) {
257252
258- const topAlerts = data . reduce ( ( acc , current ) => {
259- const alertTypes = Object . keys ( current . top_five_alert_types )
253+ const topAlerts : { [ key : string ] : number } = data . reduce ( ( acc : { [ key : string ] : number } , current : { [ key : string ] : any } ) => {
254+ const alertTypes = Object . keys ( current [ ' top_five_alert_types' ] )
260255 alertTypes . map ( type => {
261256 if ( ! acc [ type ] ) {
262- acc [ type ] = current . top_five_alert_types [ type ]
257+ acc [ type ] = current [ ' top_five_alert_types' ] [ type ]
263258 } else {
264- if ( current . top_five_alert_types [ type ] > acc [ type ] ) {
265- acc [ type ] = current . top_five_alert_types [ type ]
259+ if ( current [ ' top_five_alert_types' ] [ type ] > ( acc [ type ] || 0 ) ) {
260+ acc [ type ] = current [ ' top_five_alert_types' ] [ type ]
266261 }
267262 }
268263 return acc
@@ -271,20 +266,20 @@ const formatData = (data: AnalyticsData[], scope: string) => {
271266 } , { } as { [ key : string ] : number } )
272267
273268 sortedTopFivealerts = Object . entries ( topAlerts )
274- . sort ( ( [ , a ] : [ string , number ] , [ , b ] : [ string , number ] ) => b - a )
269+ . sort ( ( [ , a ] , [ , b ] ) => b - a )
275270 . slice ( 0 , 5 )
276271 . reduce ( ( r , [ k , v ] ) => ( { ...r , [ k ] : v } ) , { } )
277272
278- formattedData = data . reduce ( ( acc , current ) => {
279- METRICS . forEach ( ( m : string ) => {
280- if ( ! acc [ m ] ) {
281- acc [ m ] = { }
282- }
283- acc [ m ] [ formatDate ( current . created_at ) ] = current [ m ]
273+ formattedData = data . reduce ( ( acc : any , current : { [ key : string ] : any } ) => {
274+ METRICS . forEach ( ( m : string ) => {
275+ if ( ! acc [ m ] ) {
276+ acc [ m ] = { }
277+ }
278+ acc [ m ] [ formatDate ( current [ 'created_at' ] ) ] = current [ m ]
279+ return acc
280+ } )
284281 return acc
285- } )
286- return acc
287- } , { } as { [ k : string ] : any } )
282+ } , { } as { [ k : string ] : number } )
288283 }
289284
290285 return { ...formattedData , top_five_alert_types : sortedTopFivealerts }
@@ -312,7 +307,7 @@ async function fetchRepoAnalyticsData (repo: string, time: number, spinner: Ora,
312307 return displayAnalyticsScreen ( data )
313308}
314309
315- const displayAnalyticsScreen = ( data : FormattedAnalyticsData ) => {
310+ const displayAnalyticsScreen = ( data : any ) => {
316311 const screen = blessed . screen ( )
317312 // eslint-disable-next-line
318313 const grid = new contrib . grid ( { rows : 5 , cols : 4 , screen} )
0 commit comments