forked from zengchen1024/robot-gitee-review-trigger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
review.go
65 lines (53 loc) · 1.71 KB
/
review.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"time"
"github.com/opensourceways/community-robot-lib/giteeclient"
sdk "github.com/opensourceways/go-gitee/gitee"
"github.com/opensourceways/repo-owners-cache/repoowners"
"github.com/sirupsen/logrus"
)
func (bot *robot) genRepoOwner(org, repo, branch string, cfg ownerConfig, log *logrus.Entry) (repoowners.RepoOwner, error) {
if cfg.IsBranchWithoutOwners(branch) {
cs, err := bot.client.listCollaborators(org, repo)
if err != nil {
return nil, err
}
return repoowners.RepoMemberAsOwners(cs), nil
}
return repoowners.NewRepoOwners(
repoowners.RepoBranch{
Platform: "gitee",
Org: org,
Repo: repo,
Branch: branch,
},
bot.cacheCli,
)
}
func (bot *robot) genPullRequest(prInfo iPRInfo, assignees []string, owner repoowners.RepoOwner) (pullRequest, error) {
org, repo := prInfo.getOrgAndRepo()
filenames, err := bot.client.getPullRequestChanges(org, repo, prInfo.getNumber())
if err != nil {
return pullRequest{}, err
}
return newPullRequest(prInfo, filenames, assignees, owner), nil
}
func (bot *robot) getReviewInfo(info iPRInfo) (ri reviewInfo, err error) {
org, repo := info.getOrgAndRepo()
ri.comments, err = bot.client.ListPRComments(org, repo, info.getNumber())
if err != nil {
return
}
ri.t, err = bot.client.getPRCodeUpdateTime(org, repo, info.getHeadSHA())
return
}
type reviewInfo struct {
comments []sdk.PullRequestComments
t time.Time
}
func (r reviewInfo) reviewGuides(botName string) []giteeclient.BotComment {
return giteeclient.FindBotComment(r.comments, botName, isNotificationComment)
}
func (r reviewInfo) doStats(s *reviewStats, botName string) (reviewSummary, reviewResult) {
return s.StatReview(r.comments, r.t, botName)
}