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 problem with pr #303, adding "maintain" and "triage" for repo collaborators #421

Closed
wants to merge 2 commits into from

Conversation

romaninsh
Copy link
Contributor

@romaninsh romaninsh commented Apr 7, 2020

Due to type validation in previous PR #303 did not enable new roles for collaborators (only for teams) as per https://developer.github.com/v3/repos/collaborators/#add-user-as-a-collaborator collaborators can also be "maintain" and "triage":

Error: unexpected permission value: maintain
Error: unexpected permission value: maintain

This PR updates role validation and also updates documentation for repository_collaborator.

More info: https://github.com/terraform-providers/terraform-provider-github/pull/303#issuecomment-610409485

(my first contribution!)

@ghost ghost added size/XS Type: Documentation Improvements or additions to documentation labels Apr 7, 2020
@romaninsh
Copy link
Contributor Author

@paultyng @liamg - my first PR here on some work you did previously. I hope it's OK!

@anGie44 anGie44 requested a review from jcudit April 7, 2020 18:01
@anGie44
Copy link
Contributor

anGie44 commented Apr 7, 2020

@romaninsh @jcudit updating the respository_collaborator_test with a test case that checks for these new permission types (maintain and/or triage) could be helpful as well :) looks like it's hardcoded to only check the admin permission

@romaninsh
Copy link
Contributor Author

@anGie44 - I tried to find a way to update the test, but couldn't figure it out. Could you give some example how to do it?

@anGie44
Copy link
Contributor

anGie44 commented Apr 9, 2020

hi @romaninsh, sure thing! (@jcudit can you weigh in here as well for best practice when updating test cases?) so in resource_github_repository_collaborator_test.go, the basic test for example, refers to the expectedPermission const defined on line 17. i'm thinking one way to test for the different permissions could be to instead add steps like below and define permissions within the method like:

adminPermission := "admin"
maintainPermission := "maintain"
resource.ParallelTest(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t) },
		Providers:    testAccProviders,
		CheckDestroy: testAccCheckGithubRepositoryCollaboratorDestroy,
		Steps: []resource.TestStep{
			{
				Config: testAccGithubRepositoryCollaboratorConfig(repoName, testCollaborator, adminPermission),
			},
			{
				ResourceName:      rn,
				ImportState:       true,
				ImportStateVerify: true,
			},
			{
				Config: testAccGithubRepositoryCollaboratorConfig(repoName, testCollaborator, maintainPermission),
			},
			{
				ResourceName:      rn,
				ImportState:       true,
				ImportStateVerify: true,
			},
		},
	})

*This of course has the side-effect that the method testAccGithubRepositoryCollaboratorConfig needs to handle an additional string parameter for each permission type you pass in.
Hope this helps :) Let me know if you have any follow-up questions!

@jcudit
Copy link
Contributor

jcudit commented Apr 14, 2020

The boilerplate referenced above is a good starting point. For more context, the function changing, getRepoPermission, is used by two resources and one data source. Only one use case currently has tests.

Take a look at this similar test logic to get an idea of how this was approached previously.

@anGie44
Copy link
Contributor

anGie44 commented May 13, 2020

hi @romaninsh, thanks again for this contribution and bug fix! closing this PR as the continuation of the implementation now lives in #457. please reach out with any questions or concerns if they arise :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/XS Type: Documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants