From a8d392ea5346d2ad3c6bed4a6df7d617d0e4f7d8b0ff509614e30a16178986ed Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Fri, 2 Aug 2024 14:42:04 +0200 Subject: [PATCH] . --- obs-staging-bot/main.go | 76 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 7 deletions(-) diff --git a/obs-staging-bot/main.go b/obs-staging-bot/main.go index eec8f16..9144e90 100644 --- a/obs-staging-bot/main.go +++ b/obs-staging-bot/main.go @@ -10,7 +10,6 @@ import ( "path" "regexp" "slices" - "sort" "strconv" "strings" "time" @@ -74,8 +73,6 @@ const ( ) func processBuildStatus(h *common.RequestHandler, project, refProject *common.BuildResultList) BuildStatusSummary { - targetResults := project.Result - if _, finished := project.BuildResultSummary(); !finished { return BuildStatusSummaryBuilding } @@ -89,9 +86,6 @@ func processBuildStatus(h *common.RequestHandler, project, refProject *common.Bu // need to verify that packages that are building in `refProject` are not // failing in the `project` BuildResultSorter := func(a, b common.BuildResult) int { - if c := strings.Compare(a.Project, b.Project); c != 0 { - return c - } if c := strings.Compare(a.Repository, b.Repository); c != 0 { return c } @@ -104,7 +98,75 @@ func processBuildStatus(h *common.RequestHandler, project, refProject *common.Bu slices.SortFunc(project.Result, BuildResultSorter) slices.SortFunc(refProject.Result, BuildResultSorter) - return BuildStatusSummaryUnknown + j := 0 + for i := 0; i < len(project.Result); i++ { + for ; j < len(refProject.Result); j++ { + if project.Result[i].Repository != refProject.Result[j].Repository || + project.Result[i].Arch != refProject.Result[j].Arch { + continue + } + + res := processRepoBuildStatus(h, project.Result[i].Status, refProject.Result[j].Status) + switch res { + case BuildStatusSummarySuccess: + break + default: + return res + } + } + + if j >= len(refProject.Result) { + return BuildStatusSummaryUnknown + } + } + return BuildStatusSummarySuccess +} + +func processRepoBuildStatus(h *common.RequestHandler, results, ref []common.PackageBuildStatus) BuildStatusSummary { + PackageBuildStatusSorter := func(a, b common.PackageBuildStatus) int { + return strings.Compare(a.Package, b.Package) + } + + // compare build result + slices.SortFunc(results, PackageBuildStatusSorter) + slices.SortFunc(ref, PackageBuildStatusSorter) + + j := 0 + for i := 0; i < len(results); i++ { + res, ok := common.ObsBuildStatusDetails[results[i].Code] + if !ok { + h.LogError("unknown package result code: %s for package %s", results[i].Code, results[i].Package) + return BuildStatusSummaryUnknown + } + + if !res.Finished { + return BuildStatusSummaryBuilding + } + + if !res.Success { + // not failed if reference project also failed for same package here + for ; j < len(results) && strings.Compare(results[i].Package, ref[j].Package) < 0; j++ { + } + + if j < len(results) && results[i].Package == ref[j].Package { + refRes, ok := common.ObsBuildStatusDetails[ref[j].Code] + if !ok { + h.LogError("unknown package result code: %s for package %s", ref[j].Code, ref[j].Package) + return BuildStatusSummaryUnknown + } + + if !refRes.Finished { + h.LogError("not finished building in reference project?!") + } + + if refRes.Success { + return BuildStatusSummaryFailed + } + } + } + } + + return BuildStatusSummarySuccess } func startBuild(h *common.RequestHandler, pr *models.PullRequest, obsClient *common.ObsClient) error {