|
1 | | -// pkg/api/handlers.go |
2 | | - |
3 | 1 | package api |
4 | 2 |
|
5 | 3 | import ( |
@@ -80,37 +78,55 @@ func GetWorkflowStats(c *gin.Context) { |
80 | 78 | return |
81 | 79 | } |
82 | 80 |
|
83 | | - // Calculate statistics |
| 81 | + // Initialize counters |
84 | 82 | totalRuns := len(runs) |
85 | 83 | successCount := 0 |
86 | 84 | failureCount := 0 |
| 85 | + cancelledCount := 0 |
| 86 | + timedOutCount := 0 |
| 87 | + actionRequiredCount := 0 |
87 | 88 |
|
88 | 89 | for _, run := range runs { |
89 | 90 | switch run.Conclusion { |
90 | 91 | case "success": |
91 | 92 | successCount++ |
92 | 93 | case "failure": |
93 | 94 | failureCount++ |
| 95 | + case "cancelled": |
| 96 | + cancelledCount++ |
| 97 | + case "timed_out": |
| 98 | + timedOutCount++ |
| 99 | + case "action_required": |
| 100 | + actionRequiredCount++ |
94 | 101 | } |
95 | 102 | } |
96 | 103 |
|
97 | 104 | // Calculate percentages |
98 | | - var successRate, failureRate float64 |
| 105 | + var successRate, failureRate, cancelledRate, timedOutRate, actionRequiredRate float64 |
99 | 106 | if totalRuns > 0 { |
100 | 107 | successRate = float64(successCount) / float64(totalRuns) * 100 |
101 | 108 | failureRate = float64(failureCount) / float64(totalRuns) * 100 |
| 109 | + cancelledRate = float64(cancelledCount) / float64(totalRuns) * 100 |
| 110 | + timedOutRate = float64(timedOutCount) / float64(totalRuns) * 100 |
| 111 | + actionRequiredRate = float64(actionRequiredCount) / float64(totalRuns) * 100 |
102 | 112 | } |
103 | 113 |
|
104 | 114 | // Respond with statistics |
105 | 115 | c.JSON(http.StatusOK, gin.H{ |
106 | | - "workflow_id": workflowID, |
107 | | - "workflow_name": workflow.Name, |
108 | | - "total_runs": totalRuns, |
109 | | - "success_count": successCount, |
110 | | - "failure_count": failureCount, |
111 | | - "success_rate": successRate, |
112 | | - "failure_rate": failureRate, |
113 | | - "start_time": startTime.Format(time.RFC3339), |
114 | | - "end_time": endTime.Format(time.RFC3339), |
| 116 | + "workflow_id": workflowID, //The unique identifier of the workflow (e.g., 123). |
| 117 | + "workflow_name": workflow.Name, //The name of the workflow (e.g., "CI Build and Test"). |
| 118 | + "total_runs": totalRuns, //The total number of workflow runs within the specified time range (e.g., 200). |
| 119 | + "success_count": successCount, //The number of runs that concluded with a success status (e.g., 150). |
| 120 | + "failure_count": failureCount, //The number of runs that concluded with a failure status (e.g., 30). |
| 121 | + "cancelled_count": cancelledCount, //The number of runs that were cancelled (e.g., 10). |
| 122 | + "timed_out_count": timedOutCount, //The number of runs that timed out (e.g., 5). |
| 123 | + "action_required_count": actionRequiredCount, //The number of runs that required action (e.g., 5). |
| 124 | + "success_rate": successRate, //The percentage of runs that were successful (success_count / total_runs * 100, e.g., 75.0). |
| 125 | + "failure_rate": failureRate, //The percentage of runs that failed (failure_count / total_runs * 100, e.g., 15.0). |
| 126 | + "cancelled_rate": cancelledRate, //The percentage of runs that were cancelled (cancelled_count / total_runs * 100, e.g., 5.0). |
| 127 | + "timed_out_rate": timedOutRate, //The percentage of runs that timed out (timed_out_count / total_runs * 100, e.g., 2.5). |
| 128 | + "action_required_rate": actionRequiredRate, //The percentage of runs that required action (action_required_count / total_runs * 100, e.g., 2.5). |
| 129 | + "start_time": startTime.Format(time.RFC3339), //The start of the time range for the statistics (e.g., "2023-09-01T00:00:00Z"). |
| 130 | + "end_time": endTime.Format(time.RFC3339), //The end of the time range for the statistics (e.g., "2023-09-30T23:59:59Z"). |
115 | 131 | }) |
116 | 132 | } |
0 commit comments