@@ -2,6 +2,62 @@ import { Request, Response } from 'express';
22import app from '../index.js' ;
33import StatusService from '../services/status.service.js' ;
44import logger from '../services/logger.js' ;
5+ import { Endpoints } from '@octokit/types' ;
6+
7+ // Type definitions for the diagnostic response
8+ interface OctokitTestResult {
9+ success : boolean ;
10+ appName ?: string ;
11+ appOwner ?: string ;
12+ permissions ?: Record < string , string | undefined > ;
13+ error ?: string ;
14+ }
15+
16+ interface InstallationDiagnostic {
17+ index : number ;
18+ installationId : number ;
19+ accountLogin : string ;
20+ accountId : string | number ;
21+ accountType : string ;
22+ accountAvatarUrl : string ;
23+ appId : number ;
24+ appSlug : string ;
25+ targetType : string ;
26+ permissions : Record < string , string | undefined > ;
27+ events : string [ ] ;
28+ createdAt : string ;
29+ updatedAt : string ;
30+ suspendedAt : string | null ;
31+ suspendedBy : { login : string ; id : number } | null ;
32+ hasOctokit : boolean ;
33+ octokitTest : OctokitTestResult | null ;
34+ isValid : boolean ;
35+ validationErrors : string [ ] ;
36+ }
37+
38+ interface AppInfo {
39+ name : string ;
40+ description : string ;
41+ owner : string ;
42+ htmlUrl : string ;
43+ permissions : Record < string , string | undefined > ;
44+ events : string [ ] ;
45+ }
46+
47+ interface DiagnosticsResponse {
48+ timestamp : string ;
49+ appConnected : boolean ;
50+ totalInstallations : number ;
51+ installations : InstallationDiagnostic [ ] ;
52+ errors : string [ ] ;
53+ appInfo : AppInfo | null ;
54+ summary : {
55+ validInstallations : number ;
56+ invalidInstallations : number ;
57+ organizationNames : string [ ] ;
58+ accountTypes : Record < string , number > ;
59+ } ;
60+ }
561
662class SetupController {
763 async registrationComplete ( req : Request , res : Response ) {
@@ -114,18 +170,18 @@ class SetupController {
114170
115171 async validateInstallations ( req : Request , res : Response ) {
116172 try {
117- const diagnostics = {
173+ const diagnostics : DiagnosticsResponse = {
118174 timestamp : new Date ( ) . toISOString ( ) ,
119175 appConnected : ! ! app . github . app ,
120176 totalInstallations : app . github . installations . length ,
121- installations : [ ] as any [ ] ,
122- errors : [ ] as string [ ] ,
123- appInfo : null as any ,
177+ installations : [ ] ,
178+ errors : [ ] ,
179+ appInfo : null ,
124180 summary : {
125181 validInstallations : 0 ,
126182 invalidInstallations : 0 ,
127- organizationNames : [ ] as string [ ] ,
128- accountTypes : { } as Record < string , number >
183+ organizationNames : [ ] ,
184+ accountTypes : { }
129185 }
130186 } ;
131187
@@ -139,7 +195,7 @@ class SetupController {
139195 for ( let i = 0 ; i < app . github . installations . length ; i ++ ) {
140196 const { installation, octokit } = app . github . installations [ i ] ;
141197
142- const installationDiag = {
198+ const installationDiag : InstallationDiagnostic = {
143199 index : i ,
144200 installationId : installation . id ,
145201 accountLogin : installation . account ?. login || 'MISSING' ,
@@ -149,16 +205,16 @@ class SetupController {
149205 appId : installation . app_id ,
150206 appSlug : installation . app_slug ,
151207 targetType : installation . target_type ,
152- permissions : installation . permissions ,
153- events : installation . events ,
208+ permissions : installation . permissions || { } ,
209+ events : installation . events || [ ] ,
154210 createdAt : installation . created_at ,
155211 updatedAt : installation . updated_at ,
156212 suspendedAt : installation . suspended_at ,
157213 suspendedBy : installation . suspended_by ,
158214 hasOctokit : ! ! octokit ,
159- octokitTest : null as any ,
215+ octokitTest : null ,
160216 isValid : true ,
161- validationErrors : [ ] as string [ ]
217+ validationErrors : [ ]
162218 } ;
163219
164220 // Validate required fields
@@ -185,7 +241,7 @@ class SetupController {
185241 installationDiag . octokitTest = {
186242 success : true ,
187243 appName : authTest . data ?. name || 'Unknown' ,
188- appOwner : ( authTest . data ?. owner as any ) ?. login || 'Unknown' ,
244+ appOwner : ( authTest . data ?. owner && 'login' in authTest . data . owner ) ? authTest . data . owner . login : 'Unknown' ,
189245 permissions : authTest . data ?. permissions || { }
190246 } ;
191247 } catch ( error ) {
@@ -224,7 +280,7 @@ class SetupController {
224280 diagnostics . appInfo = {
225281 name : appInfo . data ?. name || 'Unknown' ,
226282 description : appInfo . data ?. description || 'No description' ,
227- owner : ( appInfo . data ?. owner as any ) ?. login || 'Unknown' ,
283+ owner : ( appInfo . data ?. owner && 'login' in appInfo . data . owner ) ? appInfo . data . owner . login : 'Unknown' ,
228284 htmlUrl : appInfo . data ?. html_url || 'Unknown' ,
229285 permissions : appInfo . data ?. permissions || { } ,
230286 events : appInfo . data ?. events || [ ]
0 commit comments