diff --git a/bots-common/gitea_utils.go b/bots-common/gitea_utils.go index 20c334c..b8ffbaa 100644 --- a/bots-common/gitea_utils.go +++ b/bots-common/gitea_utils.go @@ -85,7 +85,7 @@ func (h *RequestHandler) GetPullRequestAndReviews(org, project string, num int64 return pr.Payload, reviews.Payload, nil } -func (h *RequestHandler) GetNotifications(since *time.Time) ([]*models.NotificationThread, error) { +func (h *RequestHandler) GetPullNotifications(since *time.Time) ([]*models.NotificationThread, error) { if h.HasError() { return nil, h.Error } @@ -95,6 +95,8 @@ func (h *RequestHandler) GetNotifications(since *time.Time) ([]*models.Notificat params := notification.NewNotifyGetListParams(). WithDefaults(). + WithSubjectType([]string{"Pull"}). + WithStatusTypes([]string{"unread"}). WithLimit(&bigLimit) if since != nil { @@ -125,11 +127,12 @@ func (h *RequestHandler) SetNotificationRead(notificationId int64) error { list, err := client.Notification.NotifyReadThread( notification.NewNotifyReadThreadParams(). WithDefaults(). - WithID(fmt.Sprint(id)), + WithID(fmt.Sprint(notificationId)), transport.DefaultAuthentication, ) if err != nil { + h.LogError("Error setting notification: %d: %v", notificationId, err) h.Error = err return err } diff --git a/obs-staging-bot/main.go b/obs-staging-bot/main.go index 3a2f1f1..361124c 100644 --- a/obs-staging-bot/main.go +++ b/obs-staging-bot/main.go @@ -303,6 +303,7 @@ func processPullNotification(h *common.RequestHandler, thread *models.Notificati pr, reviews, err := h.GetPullRequestAndReviews(org, repo, id) if err != nil { + h.LogError("No PR associated with review: %s. Error: %v", notification.URL, err) return } @@ -321,6 +322,8 @@ func processPullNotification(h *common.RequestHandler, thread *models.Notificati } if !reviewRequested { + h.Log("Review not requested in notification. Setting to status 'read'") + h.SetNotificationRead(thread.ID) return } @@ -430,12 +433,12 @@ func processPullNotification(h *common.RequestHandler, thread *models.Notificati case common.ReviewStateApproved: // done, mark notification as read h.Log("processing request for success build ...") - // h.SetNotificationRead(thread.ID) + h.SetNotificationRead(thread.ID) case common.ReviewStateRequestChanges: // build failures, nothing to do here, mark notification as read h.Log("processing request for failed request changes...") - // h.SetNotificationRead(thread.ID) + h.SetNotificationRead(thread.ID) } break @@ -444,7 +447,7 @@ func processPullNotification(h *common.RequestHandler, thread *models.Notificati func pollWorkNotifications() { h := common.CreateRequestHandler(GitAuthor, BotName) - data, err := h.GetNotifications(nil) + data, err := h.GetPullNotifications(nil) if err != nil { h.LogPlainError(err) @@ -453,7 +456,6 @@ func pollWorkNotifications() { if data != nil { for _, notification := range data { - switch notification.Subject.Type { case "Pull": processPullNotification(h, notification)