Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: add GitHub repository collaborators when repository name contains the org name #2013

Conversation

ppatel1604
Copy link
Contributor

Resolves #1658

Before the change?

Adding a github_repository_collaborator like below:

terraform {
  required_providers {
    github = {
      source  = "integrations/github"
      version = "~> 5.0"
    }
  }

  required_version = ">= 1.2.0"
}

provider "github" {}

resource "github_repository_collaborator" "main" {
  repository = "my-org/my-repo"
  username   = "kdean-hdai"
  permission = "push"
}

Terraform apply for it returns an error with a status code 404 because the repository attribute is used as it is. During the API call the repo looks something like https://api.github.com/repos/my-org/my-org/my-repo/collaborators/USERNAME instead of https://api.github.com/repos/my-org/my-repo/collaborators/USERNAME

In the request, the org name is used twice which is the cause of the 404 error.


After the change?

With the change, all the requests made to Github API contains only repository name.

Note
The repository supplied through the TF file is kept as it to avoid any state diff issue. The repository name is only pruned during the Github API Calls.


Pull request checklist

  • 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

Copy link
Member

@kfcampbell kfcampbell left a comment

Choose a reason for hiding this comment

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

Thank you for contributing!

@kfcampbell kfcampbell merged commit 2a9dcc6 into integrations:main Nov 21, 2023
3 checks passed
avidspartan1 pushed a commit to avidspartan1/terraform-provider-github that referenced this pull request Feb 5, 2024
…s the org name (integrations#2013)

* Fix: add collaborator when repo name contains the org name

* Tests for the fix

* Update documentation

* Removed username from test

* Update website/docs/r/repository_collaborator.html.markdown

Co-authored-by: Keegan Campbell <me@kfcampbell.com>

---------

Co-authored-by: Keegan Campbell <me@kfcampbell.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Unable to add github_repository_collaborators.
2 participants