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

Add support for tag-based environment deployment branch policy #2050

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

mcevoypeter
Copy link

@mcevoypeter mcevoypeter commented Dec 6, 2023

Resolves #1974


Before the change?

  • The github_repository_environment_deployment_policy only supported branch-based policies even though the GitHub API has support for both branch-based and tag-based policies.

After the change?

  • A tag_pattern attribute has been added to the github_repository_environment_deployment_policy resource.

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

The Type field is only necessary when creating a deployment branch
policy. When updating a deployment branch policy, the Type field is not
needed and is therefore set to nil.

Resources:
- https://docs.github.com/en/rest/deployments/branch-policies?apiVersion=2022-11-28
mcevoypeter and others added 7 commits December 13, 2023 13:17
…repository_environment_deployment_policy resource"

This reverts commit 029960b.
All other files in the module use v55 instead of v52. Furthermore,
attempting to build (i.e. `make build`) with v52 results in the
following error:

```console
==> Checking that code complies with gofmt requirements...
go build ./...
github/resource_github_issue_labels.go:79:69: cannot use options (variable of type *"github.com/google/go-github/v52/github".ListOptions) as *"github.com/google/go-github/v55/github".ListOptions value in argument to client.Issues.ListLabels
github/resource_github_issue_labels.go:147:71: cannot use &github.Label{…} (value of type *"github.com/google/go-github/v52/github".Label) as *"github.com/google/go-github/v55/github".Label value in argument to client.Issues.CreateLabel
github/resource_github_issue_labels.go:183:76: cannot use &github.Label{…} (value of type *"github.com/google/go-github/v52/github".Label) as *"github.com/google/go-github/v55/github".Label value in argument to client.Issues.EditLabel
make: *** [GNUmakefile:13: build] Error 1
```
@mcevoypeter
Copy link
Author

I switched from a pattern + type approach to a branch_pattern + tag_pattern approach. The former was a breaking change, whereas the latter is not and is also simpler for users of the provider to use correctly.

@mcevoypeter
Copy link
Author

@kfcampbell, is there anything I can do to help move this along?

@brandocomando
Copy link

Does repository need to be updated as well? github_repository_environment
Currently it has
deployment_branch_policy with custom_branch_policies.

Does it also need custom_tag_policies boolean?

@mcevoypeter
Copy link
Author

Does it [the github_repository_environment resource ]also need custom_tag_policies boolean?

I don't think so. The GitHub docs only lists two fields within the deployment_branch_policy object: protected_branches and custom_branch_policies.

@kfcampbell
Copy link
Member

@mcevoypeter Sorry about the delay; it's been slow with holidays. Thank you for the contribution!

When running the newly-added tests, I get the following error that fails them:

    testing.go:705: Step 0 error: After applying this step, the plan was not empty:
        
        DIFF:
        
        UPDATE: github_repository_environment_deployment_policy.test
          branch_pattern: "v*" => ""
          environment:    "environment/test" => "environment/test"
          id:             "tf-acc-test-7vk43:environment%2Ftest:13663474" => "tf-acc-test-7vk43:environment%2Ftest:13663474"
          repository:     "tf-acc-test-7vk43" => "tf-acc-test-7vk43"
          tag_pattern:    "v*" => "v*"
        
        
        
        STATE:
        
        (left out for now)

Can you reproduce this? Do they succeed for you?

@boredland
Copy link

Hi there! We're currently a bit blocked by this missing. Anything we could help with moving this forward?

@kfcampbell
Copy link
Member

@boredland you're certainly welcome to take this code as it is, resolve the issues/conflicts, and submit as another PR! I'd be happy to review it should you decide to do so.

@mcevoypeter
Copy link
Author

@boredland, go for it. I've been swamped since the beginning of January and can't get to this for the forseeable future. Let me know if there's anything I can do to help with hand-off.

@boredland
Copy link

Didn't find any time yet :(

sumnerwarren pushed a commit to sumnerwarren/terraform-provider-github that referenced this pull request Feb 20, 2024
sumnerwarren pushed a commit to sumnerwarren/terraform-provider-github that referenced this pull request Feb 20, 2024
@sumnerwarren
Copy link

@kfcampbell I took a stab at reworking this in #2165.

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.

[FEAT]: Add support for tag pattern to github_repository_environment_deployment_policy resource
5 participants