MCPcopy Create free account
hub / github.com/github/gh-aw / fetchWorkflowRuns

Function fetchWorkflowRuns

pkg/cli/health_command.go:174–228  ·  view source on GitHub ↗

fetchWorkflowRuns fetches workflow runs from GitHub for the specified time period

(workflowName, startDate, repoOverride string, verbose bool)

Source from the content-addressed store, hash-verified

172
173// fetchWorkflowRuns fetches workflow runs from GitHub for the specified time period
174func fetchWorkflowRuns(workflowName, startDate, repoOverride string, verbose bool) ([]WorkflowRun, error) {
175 healthLog.Printf("Fetching workflow runs: workflow=%s, startDate=%s", workflowName, startDate)
176
177 opts := ListWorkflowRunsOptions{
178 WorkflowName: workflowName,
179 StartDate: startDate,
180 Limit: 100,
181 RepoOverride: repoOverride,
182 Verbose: verbose,
183 }
184
185 allRuns := make([]WorkflowRun, 0)
186
187 // Fetch runs in batches
188 for i := range MaxIterations {
189 runs, totalCount, err := listWorkflowRunsWithPagination(opts)
190 if err != nil {
191 return nil, err
192 }
193
194 if len(runs) == 0 {
195 break
196 }
197
198 // Accumulate runs; duration calculation is done here since the GitHub API
199 // does not return a pre-computed duration field.
200 for _, run := range runs {
201 if run.Duration == 0 && !run.StartedAt.IsZero() && !run.UpdatedAt.IsZero() {
202 run.Duration = run.UpdatedAt.Sub(run.StartedAt)
203 }
204 allRuns = append(allRuns, run)
205 }
206
207 healthLog.Printf("Fetched batch %d: got %d runs, total agentic runs so far: %d", i+1, len(runs), len(allRuns))
208
209 // If we got fewer runs than requested, we've reached the end
210 if len(runs) < opts.Limit {
211 break
212 }
213
214 // Update pagination for next batch
215 if len(runs) > 0 {
216 lastRun := runs[len(runs)-1]
217 opts.BeforeDate = lastRun.CreatedAt.Format(time.RFC3339)
218 }
219
220 // Avoid fetching more than necessary
221 if totalCount > 0 && len(allRuns) >= totalCount {
222 break
223 }
224 }
225
226 healthLog.Printf("Total workflow runs fetched: %d", len(allRuns))
227 return allRuns, nil
228}
229
230// displayHealthSummary displays a summary of health metrics for all workflows
231func displayHealthSummary(runs []WorkflowRun, config HealthConfig) error {

Callers 1

RunHealthFunction · 0.85

Calls 2

PrintfMethod · 0.45

Tested by

no test coverage detected