Skip to content

Commit 1dbf8a4

Browse files
committed
Improve DEBUG logging of repo collaborators
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
1 parent a42b848 commit 1dbf8a4

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

github/resource_github_repository_collaborators.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ func resourceGithubRepositoryCollaborators() *schema.Resource {
117117
}
118118

119119
func resourceGithubRepositoryCollaboratorsDiff(ctx context.Context, d *schema.ResourceDiff, m any) error {
120+
tflog.Debug(ctx, "Diffing user collaborators")
120121
if d.HasChange("user") {
121122
users := d.Get("user").(*schema.Set).List()
122123
seen := make(map[string]any)
@@ -181,6 +182,11 @@ func resourceGithubRepositoryCollaboratorsCreate(ctx context.Context, d *schema.
181182
teams := d.Get("team").(*schema.Set).List()
182183
ignoreTeams := d.Get("ignore_team").(*schema.Set).List()
183184

185+
tflog.Debug(ctx, "Creating repository collaborators", map[string]any{
186+
"users": users,
187+
"teams": teams,
188+
"ignoreTeams": ignoreTeams,
189+
})
184190
inUsers, err := getUserCollaborators(users)
185191
if err != nil {
186192
return diag.FromErr(err)
@@ -226,6 +232,7 @@ func resourceGithubRepositoryCollaboratorsCreate(ctx context.Context, d *schema.
226232
}
227233

228234
func resourceGithubRepositoryCollaboratorsRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics {
235+
tflog.Debug(ctx, "Reading repository collaborators")
229236
meta, _ := m.(*Owner)
230237
client := meta.v3client
231238
owner := meta.name
@@ -289,6 +296,7 @@ func resourceGithubRepositoryCollaboratorsRead(ctx context.Context, d *schema.Re
289296
}
290297

291298
func resourceGithubRepositoryCollaboratorsUpdate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics {
299+
tflog.Debug(ctx, "Updating repository collaborators")
292300
meta, _ := m.(*Owner)
293301
client := meta.v3client
294302
owner := meta.name
@@ -334,6 +342,7 @@ func resourceGithubRepositoryCollaboratorsUpdate(ctx context.Context, d *schema.
334342
}
335343

336344
func resourceGithubRepositoryCollaboratorsDelete(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics {
345+
tflog.Debug(ctx, "Deleting repository collaborators")
337346
meta, _ := m.(*Owner)
338347
client := meta.v3client
339348
owner := meta.name
@@ -365,6 +374,7 @@ func resourceGithubRepositoryCollaboratorsDelete(ctx context.Context, d *schema.
365374
}
366375

367376
func resourceGithubRepositoryCollaboratorsImport(ctx context.Context, d *schema.ResourceData, m any) ([]*schema.ResourceData, error) {
377+
tflog.Debug(ctx, "Importing repository collaborators")
368378
meta := m.(*Owner)
369379
client := meta.v3client
370380
owner := meta.name
@@ -497,7 +507,10 @@ func getTeamIdentity(d any) (teamIdentity, error) {
497507

498508
func listUserCollaborators(ctx context.Context, client *github.Client, owner, repoName string) (userCollaborators, error) {
499509
col := make([]userCollaborator, 0)
500-
510+
tflog.Debug(ctx, "Listing user collaborators", map[string]any{
511+
"owner": owner,
512+
"repoName": repoName,
513+
})
501514
affiliations := []string{"direct", "outside"}
502515
for _, affiliation := range affiliations {
503516
opt := &github.ListCollaboratorsOptions{
@@ -634,6 +647,14 @@ func updateUserCollaboratorsAndInvites(ctx context.Context, client *github.Clien
634647
lookup[inUser.login] = inUser
635648
}
636649

650+
tflog.Debug(ctx, "Updating user collaborators and invitations", map[string]any{
651+
"repoName": repoName,
652+
"inUsers": inUsers,
653+
"lookup": lookup,
654+
"seen": seen,
655+
"remove": remove,
656+
})
657+
637658
ghUsers, err := listUserCollaborators(ctx, client, owner, repoName)
638659
if err != nil {
639660
return nil, err

0 commit comments

Comments
 (0)