11using System . Net . Http . Headers ;
22using System . Text . Json ;
3+ using System . Text . Json . Serialization ;
34using GithubActionsOrchestrator . GitHub ;
45using Npgsql . Replication ;
56using Serilog ;
@@ -157,7 +158,7 @@ public static async Task<bool> RemoveRunnerFromRepo(string repoName, string orgG
157158
158159 }
159160
160- public static async Task < GitHubJob > GetJobInfoForOrg ( long stuckJobGithubJobId , string repoName , string orgGitHubToken )
161+ public static async Task < GitHubApiWorkflowRun > GetJobInfoForOrg ( long stuckJobGithubJobId , string repoName , string orgGitHubToken )
161162 {
162163 using HttpClient client = new ( ) ;
163164 client . DefaultRequestHeaders . Accept . Add ( new MediaTypeWithQualityHeaderValue ( "application/vnd.github+json" ) ) ;
@@ -170,15 +171,15 @@ public static async Task<GitHubJob> GetJobInfoForOrg(long stuckJobGithubJobId,st
170171 if ( response . IsSuccessStatusCode )
171172 {
172173 string content = await response . Content . ReadAsStringAsync ( ) ;
173- GitHubJob responseObject = JsonSerializer . Deserialize < GitHubJob > ( content ) ;
174+ GitHubApiWorkflowRun responseObject = JsonSerializer . Deserialize < GitHubApiWorkflowRun > ( content ) ;
174175
175176 return responseObject ;
176177 }
177178 Log . Warning ( $ "Unable to get GH job info for { repoName } /{ stuckJobGithubJobId } : [{ response . StatusCode } ] { response . ReasonPhrase } ") ;
178179
179180 return null ;
180181 }
181- public static async Task < GitHubJob > GetJobInfoForRepo ( long stuckJobGithubJobId , string repoName , string orgGitHubToken )
182+ public static async Task < GitHubApiWorkflowRun > GetJobInfoForRepo ( long stuckJobGithubJobId , string repoName , string orgGitHubToken )
182183 {
183184 using HttpClient client = new ( ) ;
184185 client . DefaultRequestHeaders . Accept . Add ( new MediaTypeWithQualityHeaderValue ( "application/vnd.github+json" ) ) ;
@@ -191,7 +192,7 @@ public static async Task<GitHubJob> GetJobInfoForRepo(long stuckJobGithubJobId,s
191192 if ( response . IsSuccessStatusCode )
192193 {
193194 string content = await response . Content . ReadAsStringAsync ( ) ;
194- GitHubJob responseObject = JsonSerializer . Deserialize < GitHubJob > ( content ) ;
195+ GitHubApiWorkflowRun responseObject = JsonSerializer . Deserialize < GitHubApiWorkflowRun > ( content ) ;
195196
196197 return responseObject ;
197198 }
@@ -201,42 +202,95 @@ public static async Task<GitHubJob> GetJobInfoForRepo(long stuckJobGithubJobId,s
201202 }
202203}
203204
204- public class GitHubJob
205+ public class GitHubApiWorkflowJob
205206{
207+ [ JsonPropertyName ( "name" ) ]
208+ public string Name { get ; set ; }
209+
210+ [ JsonPropertyName ( "status" ) ]
211+ public string Status { get ; set ; }
212+
213+ [ JsonPropertyName ( "conclusion" ) ]
214+ public string Conclusion { get ; set ; }
215+
216+ [ JsonPropertyName ( "number" ) ]
217+ public int ? Number { get ; set ; }
218+
219+ [ JsonPropertyName ( "started_at" ) ]
220+ public DateTime ? StartedAt { get ; set ; }
221+
222+ [ JsonPropertyName ( "completed_at" ) ]
223+ public DateTime ? CompletedAt { get ; set ; }
224+ }
206225
207- public int Id { get ; set ; }
208- public int RunId { get ; set ; }
226+ public class GitHubApiWorkflowRun
227+ {
228+ [ JsonPropertyName ( "id" ) ]
229+ public long ? Id { get ; set ; }
230+
231+ [ JsonPropertyName ( "run_id" ) ]
232+ public long ? RunId { get ; set ; }
233+
234+ [ JsonPropertyName ( "workflow_name" ) ]
235+ public string WorkflowName { get ; set ; }
236+
237+ [ JsonPropertyName ( "head_branch" ) ]
238+ public string HeadBranch { get ; set ; }
239+
240+ [ JsonPropertyName ( "run_url" ) ]
209241 public string RunUrl { get ; set ; }
210- public int RunAttempt { get ; set ; }
242+
243+ [ JsonPropertyName ( "run_attempt" ) ]
244+ public int ? RunAttempt { get ; set ; }
245+
246+ [ JsonPropertyName ( "node_id" ) ]
211247 public string NodeId { get ; set ; }
248+
249+ [ JsonPropertyName ( "head_sha" ) ]
212250 public string HeadSha { get ; set ; }
251+
252+ [ JsonPropertyName ( "url" ) ]
213253 public string Url { get ; set ; }
254+
255+ [ JsonPropertyName ( "html_url" ) ]
214256 public string HtmlUrl { get ; set ; }
257+
258+ [ JsonPropertyName ( "status" ) ]
215259 public string Status { get ; set ; }
260+
261+ [ JsonPropertyName ( "conclusion" ) ]
216262 public string Conclusion { get ; set ; }
217- public DateTime CreatedAt { get ; set ; }
218- public DateTime StartedAt { get ; set ; }
219- public DateTime ? CompletedAt { get ; set ; } // Nullable
263+
264+ [ JsonPropertyName ( "created_at" ) ]
265+ public DateTime ? CreatedAt { get ; set ; }
266+
267+ [ JsonPropertyName ( "started_at" ) ]
268+ public DateTime ? StartedAt { get ; set ; }
269+
270+ [ JsonPropertyName ( "completed_at" ) ]
271+ public DateTime ? CompletedAt { get ; set ; }
272+
273+ [ JsonPropertyName ( "name" ) ]
220274 public string Name { get ; set ; }
221- public List < GitHubJobStep > Steps { get ; set ; }
275+
276+ [ JsonPropertyName ( "steps" ) ]
277+ public List < GitHubApiWorkflowJob > Steps { get ; set ; }
278+
279+ [ JsonPropertyName ( "check_run_url" ) ]
222280 public string CheckRunUrl { get ; set ; }
281+
282+ [ JsonPropertyName ( "labels" ) ]
223283 public List < string > Labels { get ; set ; }
224- public int ? RunnerId { get ; set ; } // Nullable
225- public string RunnerName { get ; set ; } // Nullable
226- public int ? RunnerGroupId { get ; set ; } // Nullable
227- public string RunnerGroupName { get ; set ; } // Nullable
228- public string WorkflowName { get ; set ; } // Nullable
229- public string HeadBranch { get ; set ; } // Nullable
230284
231- }
285+ [ JsonPropertyName ( "runner_id" ) ]
286+ public long ? RunnerId { get ; set ; }
232287
233- public class GitHubJobStep
234- {
235- public string Status { get ; set ; }
236- public string Conclusion { get ; set ; }
237- public string Name { get ; set ; }
238- public int Number { get ; set ; }
239- public DateTime ? StartedAt { get ; set ; } // Nullable
240- public DateTime ? CompletedAt { get ; set ; } // Nullable
241- }
288+ [ JsonPropertyName ( "runner_name" ) ]
289+ public string RunnerName { get ; set ; }
242290
291+ [ JsonPropertyName ( "runner_group_id" ) ]
292+ public int ? RunnerGroupId { get ; set ; }
293+
294+ [ JsonPropertyName ( "runner_group_name" ) ]
295+ public string RunnerGroupName { get ; set ; }
296+ }
0 commit comments