forked from zengchen1024/robot-gitee-review-trigger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
64 lines (52 loc) · 1.23 KB
/
client.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
package main
import (
"strings"
"time"
sdk "github.com/opensourceways/go-gitee/gitee"
)
type ghclient struct {
iClient
}
func (c ghclient) getPRCodeUpdateTime(org, repo, headSHA string) (time.Time, error) {
v, err := c.GetPRCommit(org, repo, headSHA)
if err != nil {
return time.Time{}, err
}
return v.Commit.Committer.Date, nil
}
func (c ghclient) getPullRequestChanges(org, repo string, number int32) ([]string, error) {
filenames, err := c.GetPullRequestChanges(org, repo, number)
if err != nil {
return nil, err
}
r := make([]string, 0, len(filenames))
for i := range filenames {
r = append(r, filenames[i].Filename)
}
return r, nil
}
func (c ghclient) listCollaborators(org, repo string) ([]string, error) {
cs, err := c.ListCollaborators(org, repo)
if err != nil {
return nil, err
}
r := make([]string, 0, len(cs))
for i := range cs {
r = append(r, normalizeLogin(cs[i].Login))
}
return r, nil
}
func getAssignees(pr *sdk.PullRequestHook) []string {
if pr == nil {
return nil
}
v := pr.Assignees
as := make([]string, 0, len(v))
for i := range v {
as = append(as, normalizeLogin(v[i].Login))
}
return as
}
func normalizeLogin(s string) string {
return strings.TrimPrefix(strings.ToLower(s), "@")
}