Timeline events will contain Reviews and ReviewRequests and ReviewDismissed events. We need to handle this at event parsing time and not to punt this to the query functions later on. If the last event is an actual review, we use this. If no review, check if last event associated with the reviewer is Dismissed or Requested Review but not if a dismissed Review preceeds it.
65 lines
2.0 KiB
Go
65 lines
2.0 KiB
Go
package common
|
|
|
|
import (
|
|
"encoding/json"
|
|
"slices"
|
|
|
|
"src.opensuse.org/autogits/common/gitea-generated/models"
|
|
)
|
|
|
|
const (
|
|
TimelineCommentType_ReviewDismissed = "dismiss_review"
|
|
TimelineCommentType_ReviewRequested = "review_request"
|
|
TimelineCommentType_Review = "review"
|
|
TimelineCommentType_PushPull = "pull_push"
|
|
TimelineCommentType_PullRequestRef = "pull_ref"
|
|
TimelineCommentType_DismissReview = "dismiss_review"
|
|
TimelineCommentType_Comment = "comment"
|
|
)
|
|
|
|
func FetchTimelineSinceLastPush(gitea GiteaTimelineFetcher, headSha, org, repo string, id int64) ([]*models.TimelineComment, error) {
|
|
timeline, err := gitea.GetTimeline(org, repo, id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
//{"is_force_push":true,"commit_ids":["36e43509be1b13a1a8fc63a4361405de04cc621ab16935f88968c46193221bb6","732246a48fbc6bac9df16c0b0ca23ce0f6fbabd9990795863b6d1f0ef3f242c8"]}
|
|
type PullPushData struct {
|
|
IsForcePush bool `json:"is_force_push"`
|
|
CommitIds []string `json:"commit_ids"`
|
|
}
|
|
|
|
// trim timeline to last push update or last time review request was requested
|
|
for i, e := range timeline {
|
|
if e.Type == TimelineCommentType_PushPull {
|
|
var push PullPushData
|
|
if err := json.Unmarshal([]byte(e.Body), &push); err != nil {
|
|
LogError(err)
|
|
}
|
|
|
|
if slices.Contains(push.CommitIds, headSha) {
|
|
return timeline[0:i], nil
|
|
}
|
|
}
|
|
}
|
|
|
|
return timeline, nil
|
|
}
|
|
|
|
func FetchTimelineSinceReviewRequestOrPush(gitea GiteaTimelineFetcher, groupName, headSha, org, repo string, id int64) ([]*models.TimelineComment, error) {
|
|
timeline, err := FetchTimelineSinceLastPush(gitea, headSha, org, repo, id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// trim timeline to last push update or last time review request was requested
|
|
for i, e := range timeline {
|
|
if e.Type == TimelineCommentType_ReviewRequested && e.Assignee != nil && e.Assignee.UserName == groupName {
|
|
// review request is cut-off for reviews too
|
|
return timeline[0:i], nil
|
|
}
|
|
}
|
|
|
|
return timeline, nil
|
|
}
|