.
This commit is contained in:
parent
f1fb36763e
commit
96c800db05
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user