Manage git Branches With gitStream
Use gitStream to enforce branch naming conventions, review assignment, and other branch managment workflows.
Enforce Branch Naming Conventions - Automatically enforce prefixes or keywords in PR branch names.
Branch-Based Review Policies - Automatically assign PR reviewers for target branches that include a specified keyword.
Enforce Branch Naming Conventions
Automatically enforce prefixes or keywords in PR branch names.
Configuration Description
Conditions (all must be true):
- The incoming branch name is missing a required prefix
feature
fix
orstable
- The invoming branch name fails to match a specified regex pattern. In this case
abc-
followed by a number. - The incoming branch name is not listed in an
ignoreList
custom expression.
Automation Actions:
- Post a comment explaining the branch name requirements.
- Apply a red label:
❗ Incorrect Branch Name
- Close the PR.
Enforce Branch Naming Conventions
# -*- mode: yaml -*-
manifest:
version: 1.0
automations:
enforce_branch_name:
if:
- {{ not has.requiredBranchPrefix }}
- {{ not has.requiredBranchKeyword }}
- {{ not ignoreList }}
run:
- action: add-label@v1
args:
label: "❗ Incorrect Branch Name"
color: {{ colors.red }}
- action: add-comment@v1
args:
comment: |
All PR branch names must be prefixed by feature, stable, or fix, and must contain a reference to a Jira ticket. E.g. 'feature-abc-1234'
Please move your changes to a new branch that meets these requirements and open a new PR.
- action: close@v1
has:
requiredBranchPrefix: {{ branch.name | includes(regex=r/^(feature|stable|fix)/) }}
requiredBranchKeyword: {{ branch.name | includes(regex=r/abc+-\d+/) }}
ignoreList: {{ branch.name | match(regex=r/^(development|staging)/) }}
Branch-Based Review Policies
Automatically route and manage PRs based on the target or destination branch.
Configuration Description
Conditions (all must be true):
- The target or source branch name contains a specified prefix.
Automation Actions:
- Implement custom review policies for the branch.
Review Target Branch
# -*- mode: yaml -*-
manifest:
version: 1.0
automations:
{% for item in branches %}
review_target_branch_{{ item.name }}:
if:
- {{ pr.target| match(regex=item.prefix) }}
run:
- action: set-required-approvals@v1
args:
approvals: {{ item.reviews }}
- action: add-comment@v1
args:
comment: |
PRs to the {{ item.name }} branch require {{ item.reviews }} review(s).
- action: add-reviewers@v1
args:
reviewers: [{{ item.reviewers }}]
{% endfor %}
branches:
- name: Release
prefix: r/^release/
reviewers: org/release-team
reviews: 4
- name: Experimental
prefix: r/^experimental-/
reviewers: org/experiment-team
reviews: 1
Review Source Branch
# -*- mode: yaml -*-
manifest:
version: 1.0
automations:
{% for item in branches %}
review_source_branch{{ item.name }}:
if:
- {{ branch.name | match(regex=item.prefix) }}
run:
- action: set-required-approvals@v1
args:
approvals: {{ item.reviews }}
- action: add-comment@v1
args:
comment: |
Reviewers from the {{ item.name }} team have automatically been assigned to this PR.
- action: add-reviewers@v1
args:
reviewers: [{{ item.reviewers }}]
{% endfor %}
branches:
- name: ABC
prefix: r/^ABC/
reviewers: org/a-team
- name: XYZ
prefix: r/^XYZ-/
reviewers: org/x-team
Additional Resources
gitStream is a workflow automation tool that enables you to use YAML configuration files to optimize your code review process. Add context to PRs, find code experts for reviews, and automate the merge process to maximize developer productivity.
Learn More about how gitStream Works.
Related Automations:
- Assign additional reviewers for large PRs
- Assign or suggest reviewers based on level of code expertise for the code changed in a PR.
- Assign reviewers based on modified directories and files
- Assign reviewers to share knowledge based on pre-determined criteria
More Automations can be found on the Automation Library and Integrations pages.