@@ -7,13 +7,22 @@ import (
7
7
"golang.org/x/oauth2"
8
8
"log"
9
9
"net/url"
10
+ "strings"
10
11
)
11
12
13
+ func boolPointer (b bool ) * bool {
14
+ return & b
15
+ }
16
+
12
17
type GithubConfig struct {
13
- JobName string `yaml:"job_name"`
14
- AccessToken string `yaml:"access_token"`
15
- URL string `yaml:"url,omitempty"`
16
- client * github.Client
18
+ JobName string `yaml:"job_name"`
19
+ AccessToken string `yaml:"access_token"`
20
+ URL string `yaml:"url,omitempty"`
21
+ Starred * bool `yaml:"starred,omitempty"`
22
+ OrgMember * bool `yaml:"org_member,omitempty"`
23
+ Collaborator * bool `yaml:"collaborator,omitempty"`
24
+ Owned * bool `yaml:"owned,omitempty"`
25
+ client * github.Client
17
26
}
18
27
19
28
func (c * GithubConfig ) Test () error {
@@ -53,6 +62,18 @@ func (c *GithubConfig) setDefaults() {
53
62
if c .JobName == "" {
54
63
c .JobName = "GitHub"
55
64
}
65
+ if c .Collaborator == nil {
66
+ c .Collaborator = boolPointer (true )
67
+ }
68
+ if c .OrgMember == nil {
69
+ c .OrgMember = boolPointer (true )
70
+ }
71
+ if c .Owned == nil {
72
+ c .Owned = boolPointer (true )
73
+ }
74
+ if c .Starred == nil {
75
+ c .Starred = boolPointer (true )
76
+ }
56
77
httpClient := oauth2 .NewClient (context .Background (), oauth2 .StaticTokenSource (& oauth2.Token {AccessToken : c .AccessToken }))
57
78
if c .URL == "" {
58
79
c .client = github .NewClient (httpClient )
@@ -106,11 +127,28 @@ func (c *GithubConfig) getAllRepos() ([]*github.Repository, error) {
106
127
}
107
128
108
129
func (c * GithubConfig ) getRepos (page int ) ([]* github.Repository , * github.Response , error ) {
130
+ affiliations := make ([]string , 0 )
131
+
132
+ if * c .Owned {
133
+ affiliations = append (affiliations , "owner" )
134
+ }
135
+ if * c .Collaborator {
136
+ affiliations = append (affiliations , "collaborator" )
137
+ }
138
+ if * c .OrgMember {
139
+ affiliations = append (affiliations , "organization_member" )
140
+ }
141
+
142
+ if len (affiliations ) == 0 {
143
+ return make ([]* github.Repository , 0 ), & github.Response {}, nil
144
+ }
145
+
109
146
return c .client .Repositories .List (context .Background (), "" , & github.RepositoryListOptions {
110
147
ListOptions : github.ListOptions {
111
148
Page : page ,
112
149
PerPage : 100 ,
113
150
},
151
+ Affiliation : strings .Join (affiliations , "," ),
114
152
})
115
153
}
116
154
@@ -125,8 +163,8 @@ func (c *GithubConfig) getStarredRepos(page int) ([]*github.Repository, *github.
125
163
return nil , response , err
126
164
}
127
165
repos := make ([]* github.Repository , len (starred ))
128
- for i , _ := range repos {
166
+ for i := range repos {
129
167
repos [i ] = starred [i ].Repository
130
168
}
131
169
return repos , response , err
132
- }
170
+ }
0 commit comments