BuildDigest builds a digest report for the specified time range
(branch, workflowName string, days int)
| 198 | |
| 199 | // BuildDigest builds a digest report for the specified time range |
| 200 | func BuildDigest(branch, workflowName string, days int) (*DigestReport, error) { |
| 201 | // Calculate the start date |
| 202 | endDate := time.Now() |
| 203 | startDate := endDate.AddDate(0, 0, -days) |
| 204 | |
| 205 | // Fetch workflow runs |
| 206 | runs, err := GetWorkflowRuns(branch, workflowName, startDate) |
| 207 | if err != nil { |
| 208 | return nil, err |
| 209 | } |
| 210 | |
| 211 | // Filter to only completed runs |
| 212 | completedRuns := filterCompleted(runs) |
| 213 | |
| 214 | // Count successes and failures |
| 215 | var successCount, failureCount int |
| 216 | var durations []time.Duration |
| 217 | |
| 218 | for _, run := range completedRuns { |
| 219 | switch run.Conclusion { |
| 220 | case ConclusionSuccess: |
| 221 | successCount++ |
| 222 | default: |
| 223 | failureCount++ |
| 224 | } |
| 225 | |
| 226 | if run.Duration > 0 { |
| 227 | durations = append(durations, run.Duration) |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | totalRuns := len(completedRuns) |
| 232 | successRate := 0.0 |
| 233 | if totalRuns > 0 { |
| 234 | successRate = (float64(successCount) / float64(totalRuns)) * 100 |
| 235 | } |
| 236 | |
| 237 | // Calculate duration percentiles |
| 238 | under20 := calculatePercentUnder(durations, 20*time.Minute) |
| 239 | under25 := calculatePercentUnder(durations, 25*time.Minute) |
| 240 | under30 := calculatePercentUnder(durations, 30*time.Minute) |
| 241 | |
| 242 | return &DigestReport{ |
| 243 | Branch: branch, |
| 244 | WorkflowName: workflowName, |
| 245 | StartDate: startDate, |
| 246 | EndDate: endDate, |
| 247 | TotalRuns: totalRuns, |
| 248 | SuccessfulRuns: successCount, |
| 249 | FailedRuns: failureCount, |
| 250 | SuccessRate: successRate, |
| 251 | AverageDuration: calculateAverage(durations), |
| 252 | MedianDuration: calculateMedian(durations), |
| 253 | Under20MinutesPercent: under20, |
| 254 | Under25MinutesPercent: under25, |
| 255 | Under30MinutesPercent: under30, |
| 256 | Runs: completedRuns, |
| 257 | }, nil |
no test coverage detected