@@ -139,6 +139,11 @@ func dataSourceGithubOrganization() *schema.Resource {
139
139
Type : schema .TypeBool ,
140
140
Computed : true ,
141
141
},
142
+ "summary_only" : {
143
+ Type : schema .TypeBool ,
144
+ Optional : true ,
145
+ Default : false ,
146
+ },
142
147
},
143
148
}
144
149
}
@@ -165,75 +170,100 @@ func dataSourceGithubOrganizationRead(d *schema.ResourceData, meta interface{})
165
170
ListOptions : github.ListOptions {PerPage : 100 , Page : 1 },
166
171
}
167
172
168
- var repoList []string
169
- var allRepos []* github.Repository
173
+ summaryOnly := d .Get ("summary_only" ).(bool )
174
+ if ! summaryOnly {
175
+ var repoList []string
176
+ var allRepos []* github.Repository
170
177
171
- for {
172
- repos , resp , err := client3 .Repositories .ListByOrg (ctx , name , opts )
173
- if err != nil {
174
- return err
175
- }
176
- allRepos = append (allRepos , repos ... )
178
+ for {
179
+ repos , resp , err := client3 .Repositories .ListByOrg (ctx , name , opts )
180
+ if err != nil {
181
+ return err
182
+ }
183
+ allRepos = append (allRepos , repos ... )
177
184
178
- opts .Page = resp .NextPage
185
+ opts .Page = resp .NextPage
179
186
180
- if resp .NextPage == 0 {
181
- break
187
+ if resp .NextPage == 0 {
188
+ break
189
+ }
182
190
}
183
- }
184
191
185
- ignoreArchiveRepos := d .Get ("ignore_archived_repos" ).(bool )
186
- for index := range allRepos {
187
- repo := allRepos [index ]
188
- if ignoreArchiveRepos && repo .GetArchived () {
189
- continue
190
- }
192
+ ignoreArchiveRepos := d .Get ("ignore_archived_repos" ).(bool )
193
+ for index := range allRepos {
194
+ repo := allRepos [index ]
195
+ if ignoreArchiveRepos && repo .GetArchived () {
196
+ continue
197
+ }
191
198
192
- repoList = append (repoList , repo .GetFullName ())
193
- }
199
+ repoList = append (repoList , repo .GetFullName ())
200
+ }
194
201
195
- var query struct {
196
- Organization struct {
197
- MembersWithRole struct {
198
- Edges []struct {
199
- Role githubv4.String
200
- Node struct {
201
- Id githubv4.String
202
- Login githubv4.String
203
- Email githubv4.String
202
+ var query struct {
203
+ Organization struct {
204
+ MembersWithRole struct {
205
+ Edges []struct {
206
+ Role githubv4.String
207
+ Node struct {
208
+ Id githubv4.String
209
+ Login githubv4.String
210
+ Email githubv4.String
211
+ }
204
212
}
205
- }
206
- PageInfo struct {
207
- EndCursor githubv4.String
208
- HasNextPage bool
209
- }
210
- } `graphql:"membersWithRole(first: 100, after: $after)"`
211
- } `graphql:"organization(login: $login)"`
212
- }
213
- variables := map [string ]interface {}{
214
- "login" : githubv4 .String (name ),
215
- "after" : (* githubv4 .String )(nil ),
216
- }
217
- var members []string
218
- var users []map [string ]string
219
- for {
220
- err := client4 .Query (ctx , & query , variables )
221
- if err != nil {
222
- return err
213
+ PageInfo struct {
214
+ EndCursor githubv4.String
215
+ HasNextPage bool
216
+ }
217
+ } `graphql:"membersWithRole(first: 100, after: $after)"`
218
+ } `graphql:"organization(login: $login)"`
223
219
}
224
- for _ , edge := range query .Organization .MembersWithRole .Edges {
225
- members = append (members , string (edge .Node .Login ))
226
- users = append (users , map [string ]string {
227
- "id" : string (edge .Node .Id ),
228
- "login" : string (edge .Node .Login ),
229
- "email" : string (edge .Node .Email ),
230
- "role" : string (edge .Role ),
231
- })
220
+ variables := map [string ]interface {}{
221
+ "login" : githubv4 .String (name ),
222
+ "after" : (* githubv4 .String )(nil ),
232
223
}
233
- if ! query .Organization .MembersWithRole .PageInfo .HasNextPage {
234
- break
224
+ var members []string
225
+ var users []map [string ]string
226
+ for {
227
+ err := client4 .Query (ctx , & query , variables )
228
+ if err != nil {
229
+ return err
230
+ }
231
+ for _ , edge := range query .Organization .MembersWithRole .Edges {
232
+ members = append (members , string (edge .Node .Login ))
233
+ users = append (users , map [string ]string {
234
+ "id" : string (edge .Node .Id ),
235
+ "login" : string (edge .Node .Login ),
236
+ "email" : string (edge .Node .Email ),
237
+ "role" : string (edge .Role ),
238
+ })
239
+ }
240
+ if ! query .Organization .MembersWithRole .PageInfo .HasNextPage {
241
+ break
242
+ }
243
+ variables ["after" ] = githubv4 .NewString (query .Organization .MembersWithRole .PageInfo .EndCursor )
235
244
}
236
- variables ["after" ] = githubv4 .NewString (query .Organization .MembersWithRole .PageInfo .EndCursor )
245
+
246
+ d .Set ("repositories" , repoList )
247
+ d .Set ("members" , members )
248
+ d .Set ("users" , users )
249
+ d .Set ("two_factor_requirement_enabled" , organization .GetTwoFactorRequirementEnabled ())
250
+ d .Set ("default_repository_permission" , organization .GetDefaultRepoPermission ())
251
+ d .Set ("members_can_create_repositories" , organization .GetMembersCanCreateRepos ())
252
+ d .Set ("members_allowed_repository_creation_type" , organization .GetMembersAllowedRepositoryCreationType ())
253
+ d .Set ("members_can_create_public_repositories" , organization .GetMembersCanCreatePublicRepos ())
254
+ d .Set ("members_can_create_private_repositories" , organization .GetMembersCanCreatePrivateRepos ())
255
+ d .Set ("members_can_create_internal_repositories" , organization .GetMembersCanCreateInternalRepos ())
256
+ d .Set ("members_can_fork_private_repositories" , organization .GetMembersCanCreatePrivateRepos ())
257
+ d .Set ("web_commit_signoff_required" , organization .GetWebCommitSignoffRequired ())
258
+ d .Set ("members_can_create_pages" , organization .GetMembersCanCreatePages ())
259
+ d .Set ("members_can_create_public_pages" , organization .GetMembersCanCreatePublicPages ())
260
+ d .Set ("members_can_create_private_pages" , organization .GetMembersCanCreatePrivatePages ())
261
+ d .Set ("advanced_security_enabled_for_new_repositories" , organization .GetAdvancedSecurityEnabledForNewRepos ())
262
+ d .Set ("dependabot_alerts_enabled_for_new_repositories" , organization .GetDependabotAlertsEnabledForNewRepos ())
263
+ d .Set ("dependabot_security_updates_enabled_for_new_repositories" , organization .GetDependabotSecurityUpdatesEnabledForNewRepos ())
264
+ d .Set ("dependency_graph_enabled_for_new_repositories" , organization .GetDependencyGraphEnabledForNewRepos ())
265
+ d .Set ("secret_scanning_enabled_for_new_repositories" , organization .GetSecretScanningEnabledForNewRepos ())
266
+ d .Set ("secret_scanning_push_protection_enabled_for_new_repositories" , organization .GetSecretScanningPushProtectionEnabledForNewRepos ())
237
267
}
238
268
239
269
d .SetId (strconv .FormatInt (organization .GetID (), 10 ))
@@ -243,27 +273,6 @@ func dataSourceGithubOrganizationRead(d *schema.ResourceData, meta interface{})
243
273
d .Set ("node_id" , organization .GetNodeID ())
244
274
d .Set ("description" , organization .GetDescription ())
245
275
d .Set ("plan" , planName )
246
- d .Set ("repositories" , repoList )
247
- d .Set ("members" , members )
248
- d .Set ("users" , users )
249
- d .Set ("two_factor_requirement_enabled" , organization .GetTwoFactorRequirementEnabled ())
250
- d .Set ("default_repository_permission" , organization .GetDefaultRepoPermission ())
251
- d .Set ("members_can_create_repositories" , organization .GetMembersCanCreateRepos ())
252
- d .Set ("members_allowed_repository_creation_type" , organization .GetMembersAllowedRepositoryCreationType ())
253
- d .Set ("members_can_create_public_repositories" , organization .GetMembersCanCreatePublicRepos ())
254
- d .Set ("members_can_create_private_repositories" , organization .GetMembersCanCreatePrivateRepos ())
255
- d .Set ("members_can_create_internal_repositories" , organization .GetMembersCanCreateInternalRepos ())
256
- d .Set ("members_can_fork_private_repositories" , organization .GetMembersCanCreatePrivateRepos ())
257
- d .Set ("web_commit_signoff_required" , organization .GetWebCommitSignoffRequired ())
258
- d .Set ("members_can_create_pages" , organization .GetMembersCanCreatePages ())
259
- d .Set ("members_can_create_public_pages" , organization .GetMembersCanCreatePublicPages ())
260
- d .Set ("members_can_create_private_pages" , organization .GetMembersCanCreatePrivatePages ())
261
- d .Set ("advanced_security_enabled_for_new_repositories" , organization .GetAdvancedSecurityEnabledForNewRepos ())
262
- d .Set ("dependabot_alerts_enabled_for_new_repositories" , organization .GetDependabotAlertsEnabledForNewRepos ())
263
- d .Set ("dependabot_security_updates_enabled_for_new_repositories" , organization .GetDependabotSecurityUpdatesEnabledForNewRepos ())
264
- d .Set ("dependency_graph_enabled_for_new_repositories" , organization .GetDependencyGraphEnabledForNewRepos ())
265
- d .Set ("secret_scanning_enabled_for_new_repositories" , organization .GetSecretScanningEnabledForNewRepos ())
266
- d .Set ("secret_scanning_push_protection_enabled_for_new_repositories" , organization .GetSecretScanningPushProtectionEnabledForNewRepos ())
267
276
268
277
return nil
269
278
}
0 commit comments