From ca7c9903d75c4fbb9f467f219f6c54fe64bb7b0d104bf34764db2f21d59a37cd Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Sat, 27 Jul 2024 20:57:18 +0200 Subject: [PATCH] . --- obs-staging-bot/main.go | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/obs-staging-bot/main.go b/obs-staging-bot/main.go index 6efd33a..24b9bc4 100644 --- a/obs-staging-bot/main.go +++ b/obs-staging-bot/main.go @@ -3,11 +3,14 @@ package main import ( "fmt" "log" + "net/url" "os" "path" "regexp" + "slices" "strconv" "strings" + "time" "src.opensuse.org/autogits/common" "src.opensuse.org/autogits/common/gitea-generated/models" @@ -71,7 +74,12 @@ func processPullNotification(h *common.RequestHandler, notification *models.Noti return } - for _, review := range reviews { + slices.SortFunc(reviews, func(a, b *models.PullReview) int { + return time.Time(a.Submitted).Compare(time.Time(b.Submitted)) + }) + + for idx := len(reviews)-1; idx >= 0; idx-- { + review := reviews[idx] h.Log("state: %s, body: %s, id:%d\n", string(review.State), review.Body, review.ID) if review.User.UserName != "autogits_obs_staging_bot" { @@ -88,6 +96,13 @@ func processPullNotification(h *common.RequestHandler, notification *models.Noti headSubmodules := h.GitSubmoduleList(dir, pr.Head.Sha) baseSubmodules := h.GitSubmoduleList(dir, pr.Base.Sha) + modifiedOrNew := make([]string, 0, 16) + for pkg, headOid := range headSubmodules { + if baseOid, exists := baseSubmodules[pkg]; !exists || baseOid != headOid { + modifiedOrNew = append(modifiedOrNew, pkg) + } + } + // find modified submodules and new submodules -- build them h.Log("processing state...") @@ -107,7 +122,7 @@ func processPullNotification(h *common.RequestHandler, notification *models.Noti } buildPrj := strings.TrimSpace(string(buildPrjBytes)) - meta, err := obsClient.GetProjectMeta(string(buildPrj)) + meta, err := obsClient.GetProjectMeta(buildPrj) if err != nil { h.Log("error fetching project meta for %s: %v", buildPrj, err) return @@ -125,7 +140,11 @@ func processPullNotification(h *common.RequestHandler, notification *models.Noti ) meta.Description = fmt.Sprintf(`Pull request build job: %s%s PR#%d`, "https://src.opensuse.org", pr.Base.Repo.Name, pr.Index) - // meta.ScmSync = pr.Head.Repo.CloneURL + "?" + + urlPkg := make([]string, 0, len(modifiedOrNew)) + for _, pkg := range modifiedOrNew { + urlPkg = append(urlPkg, "onlybuild="+url.QueryEscape(pkg)) + } + meta.ScmSync = pr.Head.Repo.CloneURL + "?" + strings.Join(urlPkg, "&") meta.Title = fmt.Sprintf("PR#%d to %s", pr.Index, pr.Base.Name) meta.PublicFlags = common.Flags{Contents: ""} @@ -144,6 +163,9 @@ func processPullNotification(h *common.RequestHandler, notification *models.Noti if err != nil { h.LogError("cannot create meta project: %#v", err) } + + // set the review state to pending + case common.ReviewStatePending: // waiting for build results case common.ReviewStateApproved: @@ -152,6 +174,8 @@ func processPullNotification(h *common.RequestHandler, notification *models.Noti h.Log("processing request for failed request changes...") // build failures, nothing to do here, mark notification as read } + + break } }