From 65d821d38859c709f7ca530a98b8991f342b48bdc528b4a6b4288e791387ebcc Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Sun, 28 Jul 2024 21:25:44 +0200 Subject: [PATCH] . --- obs-staging-bot/main.go | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/obs-staging-bot/main.go b/obs-staging-bot/main.go index 24b9bc4..57a481f 100644 --- a/obs-staging-bot/main.go +++ b/obs-staging-bot/main.go @@ -20,6 +20,8 @@ const ( GitAuthor = "GiteaBot - Obs Staging" BotName = "ObsStaging" ObsBuildBot = "/obsbuild" + + Username = "autogits_obs_staging_bot" ) var GiteaToken string @@ -64,21 +66,37 @@ func processPullNotification(h *common.RequestHandler, notification *models.Noti return } - for _, reviewer := range pr.RequestedReviewers { - h.Log(reviewer.UserName) - } - obsClient, err := common.NewObsClient("api.opensuse.org") if err != nil { h.LogPlainError(err) return } + reviewRequested := false + for _, reviewer := range pr.RequestedReviewers { + if reviewer.UserName == Username { + reviewRequested = true + break + } + } + + if !reviewRequested { + return + } + + newReviews := make([]*models.PullReview, 0, len(reviews)) + for _, review := range reviews { + if review.User.UserName == Username { + newReviews = append(newReviews, review) + } + } + reviews = newReviews + 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-- { + 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)