MCPcopy Create free account
hub / github.com/monitoror/monitoror / convertChecks

Function convertChecks

monitorables/github/api/usecase/github.go:205–249  ·  view source on GitHub ↗

convertChecks transform models.Checks to use it in computeRefChecks

(checks *models.Checks)

Source from the content-addressed store, hash-verified

203
204// convertChecks transform models.Checks to use it in computeRefChecks
205func convertChecks(checks *models.Checks) ([]coreModels.TileStatus, *time.Time, *time.Time, string) {
206 var statuses []coreModels.TileStatus
207 var startedAt *time.Time = nil
208 var finishedAt *time.Time = nil
209 var ids = ""
210
211 for _, run := range checks.Runs {
212 statuses = append(statuses, parseRun(&run))
213 if startedAt == nil || (run.StartedAt != nil && startedAt.After(*run.StartedAt)) {
214 startedAt = run.StartedAt
215 }
216 if finishedAt == nil || (run.CompletedAt != nil && finishedAt.Before(*run.CompletedAt)) {
217 finishedAt = run.CompletedAt
218 }
219 ids = fmt.Sprintf("%s-%d", ids, run.ID)
220 }
221
222 // Sort statues by created date and save every title to remove duplicate statues
223 // Some app add new status with the same name each time status change
224 sort.Slice(checks.Statuses, func(i, j int) bool {
225 return checks.Statuses[i].CreatedAt.After(checks.Statuses[j].CreatedAt)
226 })
227
228 titles := make(map[string]bool)
229 for _, status := range checks.Statuses {
230 if _, ok := titles[status.Title]; !ok {
231 statuses = append(statuses, parseStatus(&status))
232 titles[status.Title] = true
233 }
234
235 if startedAt == nil || startedAt.After(status.CreatedAt) {
236 startedAt = &status.CreatedAt
237 }
238 if finishedAt == nil || finishedAt.Before(status.UpdatedAt) {
239 finishedAt = &status.UpdatedAt
240 }
241 ids = fmt.Sprintf("%s-%d", ids, status.ID)
242 }
243
244 sort.Slice(statuses, func(i, j int) bool {
245 return orderedTileStatus[statuses[i]] < orderedTileStatus[statuses[j]]
246 })
247
248 return statuses, startedAt, finishedAt, hash.GetMD5Hash(ids)
249}
250
251func parseRun(run *models.Run) coreModels.TileStatus {
252 // Based on : https://developer.github.com/v3/checks/runs/

Callers 4

computeRefChecksMethod · 0.85
TestConvertChecks_StatusFunction · 0.85
TestConvertChecks_TimeFunction · 0.85
TestConvertChecks_IDFunction · 0.85

Calls 3

GetMD5HashFunction · 0.92
parseRunFunction · 0.85
parseStatusFunction · 0.70

Tested by 3

TestConvertChecks_StatusFunction · 0.68
TestConvertChecks_TimeFunction · 0.68
TestConvertChecks_IDFunction · 0.68