Skip to content

Commit 85d74a9

Browse files
committed
Added warning feature
1 parent 0730d90 commit 85d74a9

File tree

4 files changed

+76
-8
lines changed

4 files changed

+76
-8
lines changed

template/collaborators.tpl

+4
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,9 @@ Last updated: {{ .Updated }}
77
{{ range $user := .Users }}{{ range $org := $user.Organizations }}{{ range $repo := $org.Repositories }}| {{ $user.Number }} | [{{ $user.Login }}](https://github.com/{{ $user.Login }}) | {{if $user.Contributions}}:green_square:{{else}}:red_square:{{end}} {{ $user.Contributions }} | [{{ $org.Name }}](https://github.com/{{ $org.Login }}) | [{{ $repo.Name }}](https://github.com/{{ $org.Login }}/{{ $repo.Name }}) |
88
{{ end }}{{ end }}{{ end }}
99

10+
{{ if .Warnings }}
11+
## Warnings
12+
{{ range .Warnings }}* {{ . }}
13+
{{ end }}{{ end }}
1014
---
1115
Generated with :heart: by [github-users](https://github.com/prodyna/github-users)

template/members.tpl

+4
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@ Last updated: {{ .Updated }}
99

1010
{{ if .Users }}_{{ len .Users }} users_{{ else }}No users found.{{ end }}
1111

12+
{{ if .Warnings }}
13+
## Warnings
14+
{{ range .Warnings }}* {{ . }}
15+
{{ end }}{{ end }}
1216
---
1317
Generated with :heart: by [github-users](https://github.com/prodyna/github-users)

userlist/collaborators.go

+24-8
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ func (c *UserListConfig) loadCollaborators() error {
4646
Login string
4747
Name string
4848
}
49+
PageInfo struct {
50+
HasNextPage bool
51+
EndCursor githubv4.String
52+
}
4953
} `graphql:"organizations(first:100)"`
5054
} `graphql:"enterprise(slug: $slug)"`
5155
}
@@ -62,6 +66,11 @@ func (c *UserListConfig) loadCollaborators() error {
6266
}
6367
slog.Info("Loaded organizations", "organization.count", len(organizations.Enterprise.Organizations.Nodes))
6468

69+
if organizations.Enterprise.Organizations.PageInfo.HasNextPage {
70+
slog.Warn("More organizations available - not yet implemented")
71+
c.userList.addWarning("More organizations available - not yet implemented")
72+
}
73+
6574
/*
6675
{
6776
organization(login:"prodyna") {
@@ -113,19 +122,26 @@ func (c *UserListConfig) loadCollaborators() error {
113122
}
114123
}
115124
}
125+
PageInfo struct {
126+
HasNextPage bool
127+
EndCursor githubv4.String
128+
}
116129
} `graphql:"collaborators(first:100,affiliation:OUTSIDE)"`
117130
}
118-
} `graphql:"repositories(first:100)"`
131+
} `graphql:"repositories(first:$first,after:$after)"`
119132
} `graphql:"organization(login: $organization)"`
120133
}
121134

122135
variables := map[string]interface{}{
123136
"organization": githubv4.String(org.Login),
137+
"first": githubv4.Int(100),
138+
"after": (*githubv4.String)(nil),
124139
}
125140

126141
err := client.Query(ctx, &query, variables)
127142
if err != nil {
128143
slog.WarnContext(ctx, "Unable to query - will skip this organization", "error", err, "organization", org.Login)
144+
c.userList.addWarning(fmt.Sprintf("Unable to query organization %s", org.Login))
129145
continue
130146
}
131147

@@ -172,16 +188,16 @@ func (c *UserListConfig) loadCollaborators() error {
172188
continue
173189
}
174190

175-
output, err := json.MarshalIndent(c.userList, "", " ")
176-
if err != nil {
177-
slog.ErrorContext(ctx, "Unable to marshal json", "error", err)
178-
return err
179-
}
180-
fmt.Printf("%s\n", output)
181-
182191
slog.InfoContext(ctx, "Adding collaborators", "organization", org.Login)
183192
}
184193

194+
output, err := json.MarshalIndent(c.userList, "", " ")
195+
if err != nil {
196+
slog.ErrorContext(ctx, "Unable to marshal json", "error", err)
197+
return err
198+
}
199+
fmt.Printf("%s\n", output)
200+
185201
c.loaded = true
186202
return nil
187203
}

userlist/userlist.go

+44
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type UserList struct {
3131
Updated string
3232
Enterprise Enterprise
3333
Users []*User
34+
Warnings []string
3435
}
3536

3637
type Enterprise struct {
@@ -208,3 +209,46 @@ func (o *Organization) upsertRepository(repo Repository) {
208209
slog.Debug("Upserting repository", "name", repo.Name, "organization", o.Name)
209210
*o.Repositories = append(*o.Repositories, repo)
210211
}
212+
213+
func (u *User) findOrganization(login string) *Organization {
214+
for _, o := range *u.Organizations {
215+
if o.Login == login {
216+
return &o
217+
}
218+
}
219+
return nil
220+
}
221+
222+
func (u *User) createOrganization(login string, name string) *Organization {
223+
org := &Organization{
224+
Login: login,
225+
Name: name,
226+
Repositories: new([]Repository),
227+
}
228+
u.upsertOrganization(*org)
229+
return org
230+
}
231+
232+
func (o *Organization) findRepository(name string) *Repository {
233+
for _, r := range *o.Repositories {
234+
if r.Name == name {
235+
return &r
236+
}
237+
}
238+
return nil
239+
}
240+
241+
func (o *Organization) createRepository(name string) *Repository {
242+
repo := &Repository{
243+
Name: name,
244+
}
245+
o.upsertRepository(*repo)
246+
return repo
247+
}
248+
249+
func (c *UserList) addWarning(warning string) {
250+
if c.Warnings == nil {
251+
c.Warnings = make([]string, 0)
252+
}
253+
c.Warnings = append(c.Warnings, warning)
254+
}

0 commit comments

Comments
 (0)