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

Environment custom branch policies support type ('branch', 'tag') #910

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

goruha
Copy link

@goruha goruha commented Apr 4, 2024

What

  • Added type support for environment deployment_branch_policy custom branches.

Why

  • Environment deployment_branch_policy supports custom branches type - branch or tag. The type is an option parameter that sets branch by default. These changes allow us to specify deployment_branch_policy for tag

Config example

environments:
  - name: development
    deployment_branch_policy:
      custom_branches:
        - dev/*
        - name: release/*
          type: branch
        - name: v*
          type: tag

You can specify custom_branches list item as string for back-compatibility or as object

name: `string`
type: `branch | tag`

Releated links

Copy link

vercel bot commented Apr 4, 2024

@goruha is attempting to deploy a commit to the Repository Settings Team on Vercel.

A member of the Team first needs to authorize it.

@goruha
Copy link
Author

goruha commented Apr 4, 2024

@julekirk @mayliang021 @travi
may I have a review pls?

@travi
Copy link
Member

travi commented Apr 4, 2024

supporting tag targets feels separate from what makes sense under "custom_branches". would a separate section for tags be a better fit?

@goruha
Copy link
Author

goruha commented Apr 8, 2024

@travi

supporting tag targets feels separate from what makes sense under "custom_branches". would a separate section for tags be a better fit?

Yeah, the separate settings for tags look better.
However, GitHub API does not have this separation, and we should follow the GitHub API structure.
Mapping the GitHub API contract to settings.yml solves the lack of documentation - you can always reference GitHub API to see what fields are available.
So I advocate to go with solution provided in the PR

https://docs.github.com/en/rest/deployments/branch-policies?apiVersion=2022-11-28#create-a-deployment-branch-policy

@goruha
Copy link
Author

goruha commented May 13, 2024

@travi can we have this PR merged?

@travi
Copy link
Member

travi commented May 17, 2024

Yeah, the separate settings for tags look better.
However, GitHub API does not have this separation, and we should follow the GitHub API structure.
Mapping the GitHub API contract to settings.yml solves the lack of documentation - you can always reference GitHub API to see what fields are available.

in general, i agree. however, as mentioned in the docs for the environments plugin, we already deviate a bit, so that is the reason that gave me pause here. since even the github api still uses the branches terminology for this, i think i'm ok with proceeding with the proposed approach

this.customBranches = any.listOf(() => ({
name: any.word(),
id: any.integer(),
type: any.fromList(['branch', 'tag'])
Copy link
Member

Choose a reason for hiding this comment

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

i appreciate that you tracked down how to accomplish this and i think this is totally valid for the scenario that defines type, but i think this change now results in not having a scenario tested for the option to not include type, doesnt it. it seems like we probably should define an additional scenario for including type in https://github.com/repository-settings/app/blob/master/test/integration/features/environments.feature

i also wonder if the inclusion of a type that doesnt match the default requires any additional care to avoid unnecessary update requests when the intended value matches what is in the api. could you verify that comparing an existing rule in the api avoids extra calls when the type is and is not present in the settings.yml? if that requires additional logic to avoid extra calls, we may need test scenarios for those cases as well

Copy link
Author

Choose a reason for hiding this comment

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

Actually, we always specify type for API calls.
https://github.com/repository-settings/app/pull/910/files#diff-d3173e671826d864f026b433955eeef4008090a5fc6c3111f8ec2e3977e2bc4dR156

So, the test is correct and does not dismiss the case without type.

Comment on lines +155 to +156
name: rule.name || rule,
type: rule.type || 'branch'
Copy link
Member

Choose a reason for hiding this comment

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

because of the default values, i think we also need to handle similar in

function deploymentBranchPolicyHasChanged (existing, attrs) {
return (
deploymentBranchPolicyToString(existing.deployment_branch_policy) !==
deploymentBranchPolicyToString(attrs.deployment_branch_policy)
)
}
to avoid repetitively updating rules that are already in an ok state.

Copy link
Author

Choose a reason for hiding this comment

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

@travi, thanks for the nice catch.
I'll address this comment this week.

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.

None yet

2 participants