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

Repository environment creation fails on private Teams repos #2602

Closed
AnitaErnszt opened this issue Dec 20, 2022 · 6 comments
Closed

Repository environment creation fails on private Teams repos #2602

AnitaErnszt opened this issue Dec 20, 2022 · 6 comments

Comments

@AnitaErnszt
Copy link
Contributor

This is related to the discussion on the integrations/terraform-provider-github#1262

In June GitHub made the environments and environment protection rules generally available, however, the wait_timer and reviewers remains limited to enterprise.

Many developers would like to make use of this great new feature, but the bug in the Terraform provider currently proves to be a blocker.
The provider uses the go-github Go library under the hood and makes the following call:

_, _, err := client.Repositories.CreateUpdateEnvironment(ctx, owner, repoName, escapedEnvName, &updateData)

where the &updateData is a github.CreateUpdateEnvironment struct.

Looking at the code it seems that instead of sending nil value for wait_timer it defaults to 0.

// CreateUpdateEnvironment represents the fields required for the create/update operation
// following the Create/Update release example.
// See https://github.com/google/go-github/issues/992 for more information.
// Removed omitempty here as the API expects null values for reviewers and deployment_branch_policy to clear them.
type CreateUpdateEnvironment struct {
	WaitTimer              *int            `json:"wait_timer"`
	Reviewers              []*EnvReviewers `json:"reviewers"`
	DeploymentBranchPolicy *BranchPolicy   `json:"deployment_branch_policy"`
}

This is causing the issue for us, as the API doesn't expect this parameter and returns 422.

I understand why the omitempty was removed, so I'm looking at what alternative solutions are possible to ensure environments fully work regardless of the payment plan.

@gmlewis
Copy link
Collaborator

gmlewis commented Dec 20, 2022

Please read #2467 and see if that answers your questions.

@AnitaErnszt
Copy link
Contributor Author

@gmlewis It seems unrelated to me.

I'm very new to go-github and go in general, so I could be wrong.

My core issue is that the API is expecting different objects from Enterprise and Teams customers.
Above code is correct for Enterprise. Adding omitempty would make it work for Teams, but would introduce bug for enterprise customers.

@gmlewis
Copy link
Collaborator

gmlewis commented Dec 20, 2022

OK, thanks, @AnitaErnszt - so would it help to split it into two separate endpoints?

@gmlewis
Copy link
Collaborator

gmlewis commented Dec 20, 2022

I suppose another option might be to add a flag that alters its behavior.

Thoughts?

@AnitaErnszt
Copy link
Contributor Author

@gmlewis do you mean creating separate endpoints based on pricing plan (one for teams/pro where wait_timer is not sent, and one for enterprise where wait_timer defaults to 0 if not set)?

I'm still checking in the TF provider if it's possible to access the pricing plan to decide which endpoint to call.

If not, we might have to call the enterprise endpoint first, and if it returns 422 make an attempt to call the teams endpoint. However, in this case, would it not be better to make a retry attempt here, rather than downstream?

@gmlewis
Copy link
Collaborator

gmlewis commented Dec 20, 2022

Hi @AnitaErnszt - honestly, I don't know what the best answer is. I also no longer have access to GitHub Enterprise, so it makes it very challenging to experiment and further investigate.

Maybe others who also use GitHub Enterprise might be able to comment?

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

No branches or pull requests

2 participants