@@ -7,13 +7,22 @@ import (
77 "golang.org/x/oauth2"
88 "log"
99 "net/url"
10+ "strings"
1011)
1112
13+ func boolPointer (b bool ) * bool {
14+ return & b
15+ }
16+
1217type 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
1726}
1827
1928func (c * GithubConfig ) Test () error {
@@ -53,6 +62,18 @@ func (c *GithubConfig) setDefaults() {
5362 if c .JobName == "" {
5463 c .JobName = "GitHub"
5564 }
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+ }
5677 httpClient := oauth2 .NewClient (context .Background (), oauth2 .StaticTokenSource (& oauth2.Token {AccessToken : c .AccessToken }))
5778 if c .URL == "" {
5879 c .client = github .NewClient (httpClient )
@@ -106,11 +127,28 @@ func (c *GithubConfig) getAllRepos() ([]*github.Repository, error) {
106127}
107128
108129func (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+
109146 return c .client .Repositories .List (context .Background (), "" , & github.RepositoryListOptions {
110147 ListOptions : github.ListOptions {
111148 Page : page ,
112149 PerPage : 100 ,
113150 },
151+ Affiliation : strings .Join (affiliations , "," ),
114152 })
115153}
116154
@@ -125,8 +163,8 @@ func (c *GithubConfig) getStarredRepos(page int) ([]*github.Repository, *github.
125163 return nil , response , err
126164 }
127165 repos := make ([]* github.Repository , len (starred ))
128- for i , _ := range repos {
166+ for i := range repos {
129167 repos [i ] = starred [i ].Repository
130168 }
131169 return repos , response , err
132- }
170+ }
0 commit comments