frag-review/gitea_comments.go

60 lines
1.4 KiB
Go
Raw Normal View History

package main
import (
"sort"
"code.gitea.io/sdk/gitea"
)
func GetReviewsPerPR(client *gitea.Client, prID int64) []int64 {
reviews, _, err := client.ListPullReviews(
config.Gitea.Owner, config.Gitea.Repository, prID, gitea.ListPullReviewsOptions{},
)
ExitOnError(err)
result := make([]int64, 0)
for _, review := range reviews {
result = append(result, review.ID)
}
return result
}
func RetrieveComments(client *gitea.Client, prID, reviewID int64) []*gitea.PullReviewComment {
comments, _, err := client.ListPullReviewComments(
config.Gitea.Owner, config.Gitea.Repository, prID, reviewID,
)
ExitOnError(err)
return comments
}
func SplitByFile(
splitComments map[string]([]*gitea.PullReviewComment),
comments []*gitea.PullReviewComment,
) map[string]([]*gitea.PullReviewComment) {
for _, comment := range comments {
arr, found := splitComments[comment.Path]
if !found {
arr = make([]*gitea.PullReviewComment, 0)
}
splitComments[comment.Path] = append(arr, comment)
}
return splitComments
}
func GetComments(client *gitea.Client, prID int64) map[string]([]*gitea.PullReviewComment) {
reviews := GetReviewsPerPR(client, prID)
splitComments := make(map[string]([]*gitea.PullReviewComment))
for _, reviewID := range reviews {
comments := RetrieveComments(client, prID, reviewID)
sort.Sort(ByLineNum(comments))
splitComments = SplitByFile(splitComments, comments)
}
return splitComments
}