.
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
|
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() {
|
if h.HasError() {
|
||||||
return nil, h.Error
|
return nil, h.Error
|
||||||
}
|
}
|
||||||
@ -95,6 +95,8 @@ func (h *RequestHandler) GetNotifications(since *time.Time) ([]*models.Notificat
|
|||||||
|
|
||||||
params := notification.NewNotifyGetListParams().
|
params := notification.NewNotifyGetListParams().
|
||||||
WithDefaults().
|
WithDefaults().
|
||||||
|
WithSubjectType([]string{"Pull"}).
|
||||||
|
WithStatusTypes([]string{"unread"}).
|
||||||
WithLimit(&bigLimit)
|
WithLimit(&bigLimit)
|
||||||
|
|
||||||
if since != nil {
|
if since != nil {
|
||||||
@ -125,11 +127,12 @@ func (h *RequestHandler) SetNotificationRead(notificationId int64) error {
|
|||||||
list, err := client.Notification.NotifyReadThread(
|
list, err := client.Notification.NotifyReadThread(
|
||||||
notification.NewNotifyReadThreadParams().
|
notification.NewNotifyReadThreadParams().
|
||||||
WithDefaults().
|
WithDefaults().
|
||||||
WithID(fmt.Sprint(id)),
|
WithID(fmt.Sprint(notificationId)),
|
||||||
transport.DefaultAuthentication,
|
transport.DefaultAuthentication,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
h.LogError("Error setting notification: %d: %v", notificationId, err)
|
||||||
h.Error = err
|
h.Error = err
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -303,6 +303,7 @@ func processPullNotification(h *common.RequestHandler, thread *models.Notificati
|
|||||||
|
|
||||||
pr, reviews, err := h.GetPullRequestAndReviews(org, repo, id)
|
pr, reviews, err := h.GetPullRequestAndReviews(org, repo, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
h.LogError("No PR associated with review: %s. Error: %v", notification.URL, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,6 +322,8 @@ func processPullNotification(h *common.RequestHandler, thread *models.Notificati
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !reviewRequested {
|
if !reviewRequested {
|
||||||
|
h.Log("Review not requested in notification. Setting to status 'read'")
|
||||||
|
h.SetNotificationRead(thread.ID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,12 +433,12 @@ func processPullNotification(h *common.RequestHandler, thread *models.Notificati
|
|||||||
case common.ReviewStateApproved:
|
case common.ReviewStateApproved:
|
||||||
// done, mark notification as read
|
// done, mark notification as read
|
||||||
h.Log("processing request for success build ...")
|
h.Log("processing request for success build ...")
|
||||||
// h.SetNotificationRead(thread.ID)
|
h.SetNotificationRead(thread.ID)
|
||||||
|
|
||||||
case common.ReviewStateRequestChanges:
|
case common.ReviewStateRequestChanges:
|
||||||
// build failures, nothing to do here, mark notification as read
|
// build failures, nothing to do here, mark notification as read
|
||||||
h.Log("processing request for failed request changes...")
|
h.Log("processing request for failed request changes...")
|
||||||
// h.SetNotificationRead(thread.ID)
|
h.SetNotificationRead(thread.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
break
|
break
|
||||||
@ -444,7 +447,7 @@ func processPullNotification(h *common.RequestHandler, thread *models.Notificati
|
|||||||
|
|
||||||
func pollWorkNotifications() {
|
func pollWorkNotifications() {
|
||||||
h := common.CreateRequestHandler(GitAuthor, BotName)
|
h := common.CreateRequestHandler(GitAuthor, BotName)
|
||||||
data, err := h.GetNotifications(nil)
|
data, err := h.GetPullNotifications(nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.LogPlainError(err)
|
h.LogPlainError(err)
|
||||||
@ -453,7 +456,6 @@ func pollWorkNotifications() {
|
|||||||
|
|
||||||
if data != nil {
|
if data != nil {
|
||||||
for _, notification := range data {
|
for _, notification := range data {
|
||||||
|
|
||||||
switch notification.Subject.Type {
|
switch notification.Subject.Type {
|
||||||
case "Pull":
|
case "Pull":
|
||||||
processPullNotification(h, notification)
|
processPullNotification(h, notification)
|
||||||
|
Loading…
Reference in New Issue
Block a user