reviews: use timeline and ignore reviews prior to last push
This commit is contained in:
@@ -67,6 +67,10 @@ const (
|
||||
ReviewStateUnknown models.ReviewStateType = ""
|
||||
)
|
||||
|
||||
type GiteaTimelineFetcher interface {
|
||||
GetTimeline(org, repo string, idx int64) ([]*models.TimelineComment, error)
|
||||
}
|
||||
|
||||
type GiteaComment interface {
|
||||
AddComment(pr *models.PullRequest, comment string) error
|
||||
}
|
||||
@@ -81,6 +85,10 @@ type GiteaPRFetcher interface {
|
||||
GetAssociatedPrjGitPR(prjGitOrg, prjGitRepo, refOrg, refRepo string, Index int64) (*models.PullRequest, error)
|
||||
}
|
||||
|
||||
type GiteaCommitFetcher interface {
|
||||
GetCommit(org, repo, sha string) (*models.Commit, error)
|
||||
}
|
||||
|
||||
type GiteaReviewFetcher interface {
|
||||
GetPullRequestReviews(org, project string, PRnum int64) ([]*models.PullReview, error)
|
||||
}
|
||||
@@ -138,8 +146,10 @@ type Gitea interface {
|
||||
GiteaReviewRequester
|
||||
GiteaReviewer
|
||||
GiteaPRFetcher
|
||||
GiteaCommitFetcher
|
||||
GiteaReviewFetcher
|
||||
GiteaCommentFetcher
|
||||
GiteaTimelineFetcher
|
||||
GiteaMaintainershipReader
|
||||
GiteaFileContentReader
|
||||
GiteaCommitStatusGetter
|
||||
@@ -290,6 +300,25 @@ func (gitea *GiteaTransport) GetPullRequestReviews(org, project string, PRnum in
|
||||
return allReviews, nil
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) GetCommit(org, repo, sha string) (*models.Commit, error) {
|
||||
f := false
|
||||
|
||||
r, err := gitea.client.Repository.RepoGetSingleCommit(
|
||||
repository.NewRepoGetSingleCommitParams().
|
||||
WithOwner(org).
|
||||
WithRepo(repo).
|
||||
WithSha(sha).
|
||||
WithStat(&f).
|
||||
WithFiles(&f).
|
||||
WithVerification(&f),
|
||||
gitea.transport.DefaultAuthentication)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return r.Payload, nil
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) GetIssueComments(org, project string, issueNo int64) ([]*models.Comment, error) {
|
||||
// limit := int64(20)
|
||||
// var page int64
|
||||
@@ -625,6 +654,41 @@ func (gitea *GiteaTransport) AddComment(pr *models.PullRequest, comment string)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) GetTimeline(org, repo string, idx int64) ([]*models.TimelineComment, error) {
|
||||
limit := int64(20)
|
||||
page := int64(1)
|
||||
resCount := limit
|
||||
|
||||
retData := []*models.TimelineComment{}
|
||||
|
||||
for resCount == limit {
|
||||
res, err := gitea.client.Issue.IssueGetCommentsAndTimeline(
|
||||
issue.NewIssueGetCommentsAndTimelineParams().
|
||||
WithOwner(org).
|
||||
WithRepo(repo).
|
||||
WithIndex(idx).
|
||||
WithPage(&page).
|
||||
WithLimit(&limit),
|
||||
gitea.transport.DefaultAuthentication,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resCount = int64(len(res.Payload))
|
||||
page++
|
||||
|
||||
retData = append(retData, res.Payload...)
|
||||
}
|
||||
|
||||
slices.SortFunc(retData, func(a, b *models.TimelineComment) int {
|
||||
return time.Time(a.Created).Compare(time.Time(b.Created))
|
||||
})
|
||||
|
||||
return retData, nil
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) GetRepositoryFileContent(org, repo, hash, path string) ([]byte, string, error) {
|
||||
params := repository.NewRepoGetContentsParams().WithOwner(org).WithRepo(repo).WithFilepath(path)
|
||||
if len(hash) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user