This commit is contained in:
Adam Majer 2024-07-27 20:57:18 +02:00
parent e47feaf5e8
commit ca7c9903d7

View File

@ -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: "<disable/>"}
@ -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
}
}