From 7f13bf6c4d6744dabf587744e547eb3c7ca2b077 Mon Sep 17 00:00:00 2001 From: Rakshith R Date: Tue, 23 Nov 2021 09:50:45 +0530 Subject: [PATCH] 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 --- actions/retest/main.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/actions/retest/main.go b/actions/retest/main.go index 0b34e4b59..fa595ca9e 100644 --- a/actions/retest/main.go +++ b/actions/retest/main.go @@ -142,7 +142,9 @@ func main() { 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()) if contains([]string{"failed", "failure"}, r.GetState()) { log.Printf("found failed test %s\n", r.GetContext()) @@ -233,3 +235,23 @@ func contains(s []string, e string) bool { 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 +}