ci: use only latest version of test status in retest action

Github's list statuses returns list of all status, possibly
containing dupicates and previously failed statuses.
Use "UpdatedAt" timestamp to only get the latest status
for each test.

Signed-off-by: Rakshith R <rar@redhat.com>
This commit is contained in:
Rakshith R 2021-11-23 09:50:45 +05:30 committed by mergify[bot]
parent 636216445b
commit 7f13bf6c4d

View File

@ -142,7 +142,9 @@ func main() {
continue continue
} }
for _, r := range rs { statusList := filterStatusList(rs)
for _, r := range statusList {
log.Printf("found context %s with status %s\n", r.GetContext(), r.GetState()) log.Printf("found context %s with status %s\n", r.GetContext(), r.GetState())
if contains([]string{"failed", "failure"}, r.GetState()) { if contains([]string{"failed", "failure"}, r.GetState()) {
log.Printf("found failed test %s\n", r.GetContext()) log.Printf("found failed test %s\n", r.GetContext())
@ -233,3 +235,23 @@ func contains(s []string, e string) bool {
return false return false
} }
// filterStatusesList returns list of unique and recently updated github RepoStatuses.
// Raw github RepoStatus list may contain duplicate and older statuses.
func filterStatusList(rawStatusList []*github.RepoStatus) []*github.RepoStatus {
testStatus := make(map[string]*github.RepoStatus)
for _, r := range rawStatusList {
status, ok := testStatus[r.GetContext()]
if !ok || r.GetUpdatedAt().After(status.GetUpdatedAt()) {
testStatus[r.GetContext()] = r
}
}
statusList := make([]*github.RepoStatus, 0)
for _, rs := range testStatus {
statusList = append(statusList, rs)
}
return statusList
}