Skip to content

feat: Refactor repository collaborators#3233

Open
stevehipwell wants to merge 1 commit intointegrations:mainfrom
stevehipwell:refactor-repo-collaborators
Open

feat: Refactor repository collaborators#3233
stevehipwell wants to merge 1 commit intointegrations:mainfrom
stevehipwell:refactor-repo-collaborators

Conversation

@stevehipwell
Copy link
Collaborator

Resolves #2874


Before the change?

  • github_repository_collaborators errored if the repo was renamed
  • github_repository_collaborators prefered team ID and made extra calls if slug was used
  • github_repository_collaborators used unnecessary API calls to re-read
  • Team logic was inconsistent
  • Team resources didn't use native context

After the change?

  • github_repository_collaborators supports the repository being renamed
  • github_repository_collaborators uses the minimum number of API calls
  • Team logic is consistent and context is being used in more places

Pull request checklist

  • Schema migrations have been created if needed (example)
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

Please see our docs on breaking changes to help!

  • Yes
  • No

@stevehipwell stevehipwell added this to the v6.12.0 Release milestone Feb 26, 2026
@stevehipwell stevehipwell self-assigned this Feb 26, 2026
@stevehipwell stevehipwell added Type: Bug Something isn't working as documented Type: Feature New feature or request labels Feb 26, 2026
@github-actions
Copy link

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@stevehipwell stevehipwell force-pushed the refactor-repo-collaborators branch 2 times, most recently from 55043eb to 4be7e25 Compare February 27, 2026 09:50
Copy link
Collaborator

@deiga deiga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial review. Loving the direction here!

Comment on lines +126 to +128
if _, ok := seen[username]; ok {
return fmt.Errorf("duplicate username %s found in user collaborators", username)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Since "user" is TypeSet is it even possible to add duplicates? Oh, only if their hashes match

We could use the Set schema field to use only the username to calculate the hash, then this check wouldn't be necessary.

NOTE: Though, it doesn't error or complain, it just silently adds the first(?) of the duplicates

Set: func(v interface{}) int {
    m := v.(map[string]interface{})
    return schema.HashString(m["username"].(string))
  },

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't use Set as it errors if the values aren't known at plan time. I did spend a bit of time testing this out and seeing if I could work around it, but this behaviour (and better validation) needs the framework.

Comment on lines +133 to +156
if d.HasChange("team") && d.NewValueKnown("team") {
v, diags := d.GetRawConfigAt(cty.GetAttrPath("team"))
if diags.HasError() {
return fmt.Errorf("error reading team config: %v", diags)
}

if !v.IsNull() && v.IsKnown() {
seen := make(map[string]any)
it := v.ElementIterator()
for it.Next() {
_, elem := it.Element()
val := elem.GetAttr("team_id")
if val.IsNull() || !val.IsKnown() {
continue
}

teamID := val.AsString()
if _, ok := seen[teamID]; ok {
return fmt.Errorf("duplicate team %s found in team collaborators", teamID)
}
seen[teamID] = nil
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: This seems way too complex for the benefit. Would it make sense to simplify by using the Set: field to change the Hash calculation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, this isn't possible with the plugin SDK.

Signed-off-by: Steve Hipwell <steve.hipwell@gmail.com>
@stevehipwell stevehipwell force-pushed the refactor-repo-collaborators branch from 4be7e25 to 42a9206 Compare February 27, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug Something isn't working as documented Type: Feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: github_repository_collaborators error on repository rename

2 participants