@@ -18,9 +18,10 @@ import (
18
18
var PVERSION = "dev"
19
19
20
20
type GitHubRepository struct {
21
- owner string
22
- repo string
23
- client * github.Client
21
+ owner string
22
+ repo string
23
+ client * github.Client
24
+ compareCommits bool
24
25
}
25
26
26
27
func (repo * GitHubRepository ) Init (config map [string ]string ) error {
@@ -42,12 +43,14 @@ func (repo *GitHubRepository) Init(config map[string]string) error {
42
43
if token == "" {
43
44
return errors .New ("github token missing" )
44
45
}
46
+
45
47
if ! strings .Contains (slug , "/" ) {
46
48
return errors .New ("invalid slug" )
47
49
}
48
50
split := strings .Split (slug , "/" )
49
51
repo .owner = split [0 ]
50
52
repo .repo = split [1 ]
53
+
51
54
oauthClient := oauth2 .NewClient (context .Background (), oauth2 .StaticTokenSource (& oauth2.Token {AccessToken : token }))
52
55
if gheHost != "" {
53
56
gheUrl := fmt .Sprintf ("https://%s/api/v3/" , gheHost )
@@ -59,6 +62,11 @@ func (repo *GitHubRepository) Init(config map[string]string) error {
59
62
} else {
60
63
repo .client = github .NewClient (oauthClient )
61
64
}
65
+
66
+ if config ["github_use_compare_commits" ] == "true" {
67
+ repo .compareCommits = true
68
+ }
69
+
62
70
return nil
63
71
}
64
72
@@ -75,15 +83,26 @@ func (repo *GitHubRepository) GetInfo() (*provider.RepositoryInfo, error) {
75
83
}, nil
76
84
}
77
85
86
+ func (repo * GitHubRepository ) getCommitsFromGithub (fromSha , toSha string , opts * github.ListOptions ) ([]* github.RepositoryCommit , * github.Response , error ) {
87
+ if ! repo .compareCommits {
88
+ return repo .client .Repositories .ListCommits (context .Background (), repo .owner , repo .repo , & github.CommitsListOptions {
89
+ SHA : toSha ,
90
+ ListOptions : * opts ,
91
+ })
92
+ }
93
+ compCommits , resp , err := repo .client .Repositories .CompareCommits (context .Background (), repo .owner , repo .repo , fromSha , toSha , opts )
94
+ if err != nil {
95
+ return nil , nil , err
96
+ }
97
+ return compCommits .Commits , resp , nil
98
+ }
99
+
78
100
func (repo * GitHubRepository ) GetCommits (fromSha , toSha string ) ([]* semrel.RawCommit , error ) {
79
101
allCommits := make ([]* semrel.RawCommit , 0 )
80
- opts := & github.CommitsListOptions {
81
- SHA : toSha ,
82
- ListOptions : github.ListOptions {PerPage : 100 },
83
- }
102
+ opts := & github.ListOptions {PerPage : 100 }
84
103
done := false
85
104
for {
86
- commits , resp , err := repo .client . Repositories . ListCommits ( context . Background (), repo . owner , repo . repo , opts )
105
+ commits , resp , err := repo .getCommitsFromGithub ( fromSha , toSha , opts )
87
106
if err != nil {
88
107
return nil , err
89
108
}
0 commit comments