Enable protection rules
note
Currently, branch rules are in pre-beta. These features might not function as expected while they are in development.
In Harness Code, you can create branch rules for a single branch or multiple branches in a repository. Branch rules establish criteria for approving and merging PRs, define who can create and delete branches, and more.
Add branch rules
- Go to the repository where you want to enable branch rules, and select Settings.
- Select the Rules tab.
- Select New Branch Rule.
- Enter the rule Name and optional Description.
- In Target Patterns, specify branches covered by this rule according to branch name globstar patterns, such as
string
,feature-*
, orreleases/**
. You can also select whether the rule should apply to the default branch (such asmain
). Patterns can be inclusive or exclusive. - In Bypass List, you can specify users who can bypass this rule.
- For each of the Rules, select the rule you want to enable and provide additional specifications, if necessary. For example, if you select Require a minimum number of reviewers, you must specify the minimum number of reviewers.
- Select Create Rule.
Available rules
The following rules are available when adding branch rules. Some rules require additional configuration.
Rule | Additional configuration |
---|---|
Block branch creation | This rule doesn't block users in the Bypass List. |
Block branch deletion | This rule doesn't block users in the Bypass List. |
Require pull request | This rule doesn't block users in the Bypass List. |
Require a minimum number of reviewers | You must specify the minimum number of reviewers. |
Require review from code owners | This rule requires a CODEOWNERS file in your branches. If there is no CODEOWNERS file, Harness can't enforce the rule. |
Require approval of new changes | This rule requires that you also enable Require a minimum number of reviewers or Require review from code owners (or both). Without at least one of those additional rules, this rule has no effect. |
Require comment resolution | None. |
Require status checks to pass | You must specify the checks that must pass. |
Limit merge strategies | You must select the allowed merge strategies. |
Auto delete branch on merge | None. |
Toggle rules
You can toggle branch rules on and off.
- Go to your repository and select Settings.
- Select the Rules tab.
- Use the switch next to each rule to enable or disable rules.
Edit or delete rules
- Go to your repository and select Settings.
- Select the Rules tab.
- Locate the rule you want to edit or delete, select More options (⋮), and then select Edit Rule or Delete Rule.