Repository Ruleset
Definition of a Repository Ruleset, the following properties are supported:
| Key | Value | Description | Notes |
|---|---|---|---|
| name | string | The name of this repository ruleset | |
| target | string | The target of this ruleset | Possible values are branch, tag or push |
| enforcement | string | The enforcement status of this ruleset | Possible values are active, disabled or evaluate (evaluate only available when enterprise billing is enabled) |
| bypass_actors | list[BypassActor] | List of actors able to bypass this ruleset | |
| include_refs | list[RefMatcher] | List of refs or patterns to include matching branches | |
| exclude_refs | list[RefMatcher] | List of refs or patterns to exclude matching branches | |
| allows_creations | boolean | If disabled, only allows users with bypass permission to create matching refs | |
| allows_deletions | boolean | If disabled, only allows users with bypass permission to delete matching refs | |
| allows_updates | boolean | If disabled, only allows users with bypass permission to push matching refs | |
| allows_force_pushes | boolean | If disabled, only allows users with bypass permission to force push matching refs | |
| required_status_checks | StatusCheckSettings or null | If specified, status checks must pass before branches can be merged into a matching branch | |
| requires_commit_signatures | boolean | If enabled, commits pushed to matching branches must have verified signatures | |
| requires_linear_history | boolean | If enabled, prevent merge commits from being pushed to matching branches | |
| requires_deployments | boolean | If enabled, environments must be successfully deployed to before branches can be merged into a matching branch | |
| required_deployment_environments | list[string] | List of environments that must be successfully deployed to before branches can be merged | Only taken into account when requires_deployments is enabled |
| required_pull_request | PullRequestSettings or null | If specified, requires a pull request before merging. All commits must be made to a non-protected branch and submitted via a pull request before they can be merged into matching branches | |
| required_merge_queue | MergeQueueSettings or null | If specified, merges must be performed via a merge queue | |
| copilot_code_review | CopilotCodeReviewSettings or null | If specified, request a review from Copilot automatically for new pull requests, if their author has access to Copilot code review | Only supported by rulesets with target branch |
| commit_message_pattern | PatternSettings or null | If specified, the message of the commits pushed to matching refs must match a pattern | Not supported by rulesets with target push |
| commit_author_email_pattern | PatternSettings or null | If specified, the email of the author of the commits pushed to matching refs must match a pattern | Not supported by rulesets with target push |
| committer_email_pattern | PatternSettings or null | If specified, the email of the committer of the commits pushed to matching refs must match a pattern | Not supported by rulesets with target push |
| branch_name_pattern | PatternSettings or null | If specified, the names of matching branches must match a pattern | Only supported by rulesets with target branch |
| tag_name_pattern | PatternSettings or null | If specified, the names of matching tags must match a pattern | Only supported by rulesets with target tag |
| restricted_file_paths | list[string] | List of file paths that can not be pushed, using fnmatch syntax, e.g. secrets/** |
Only supported by rulesets with target push, at most 200 entries of up to 200 characters |
| restricted_file_paths_exceptions | list[string] | List of file paths that can be pushed even if they match restricted_file_paths |
Only taken into account when restricted_file_paths is not empty |
| max_file_path_length | integer | The maximum number of characters of the paths of the files that can be pushed | Only supported by rulesets with target push, allowed values in the range [0, 32767], 0 disables the rule |
| restricted_file_extensions | list[string] | List of file extensions that can not be pushed, e.g. *.exe |
Only supported by rulesets with target push, at most 200 entries of up to 200 characters |
| max_file_size | integer | The maximum size in megabytes of the files that can be pushed, files stored with Git LFS are not limited | Only supported by rulesets with target push, allowed values in the range [0, 100], 0 disables the rule |
| max_file_size_exceptions | list[string] | List of file paths that can exceed max_file_size |
Only taken into account when max_file_size is not 0 |
| required_code_scanning | CodeScanningSettings or null | If specified, code scanning tools must provide results before branches can be merged into a matching branch | Only supported by rulesets with target branch |
| required_code_quality | CodeQualitySettings or null | If specified, the code quality results of a pull request must be resolved before it can be merged into a matching branch | Only supported by rulesets with target branch |
| required_code_coverage | CodeCoverageSettings or null | If specified, the line coverage of a pull request must meet thresholds before it can be merged into a matching branch | Only supported by rulesets with target branch, in public preview on GitHub |
| requires_license_compliance_scanning | boolean | If enabled, the dependencies added or changed by a pull request must comply with the license policy of the organization before it can be merged into a matching branch | Only supported by rulesets with target branch |
Rulesets support use-cases that can not be modelled with Branch Protection Rules, e.g. bypass actors that are
exempted from all rules of a ruleset, while the bypass allowances of a Branch Protection Rule only lift the pull
request requirement and required status checks still apply. See
Rulesets or branch protection rules for a comparison and the
features of rulesets that are not supported, and Protecting branches for
examples, e.g. restricting the files that can be pushed
with a ruleset with target push.
A ruleset with target push checks the content of every push, to any ref of the repository: GitHub only supports
the push rules in it, restricted_file_paths, max_file_path_length, restricted_file_extensions and
max_file_size. The rules protecting branches or blocking the merge of pull requests, e.g. requires_linear_history
or required_code_scanning, have to be defined in a separate ruleset with target branch.
A rule missing from a ruleset, e.g. because the default template predates it, is not managed: plan reports no
difference for it and apply keeps its current setting on GitHub, including its exceptions, e.g.
restricted_file_paths_exceptions, while a rule set to its disabled value, e.g. null, is removed.
Jsonnet Function¶
Embedded Models¶
Status Check Settings¶
| Key | Value | Description | Notes |
|---|---|---|---|
| do_not_enforce_on_create | boolean | If enabled, allow repositories and branches to be created if a check would otherwise prohibit it | |
| strict | boolean | If enabled, pull requests targeting a matching branch must have been tested with the latest code | This setting will not take effect unless at least one status check is enabled |
| status_checks | list[StatusCheck] | List of status checks that must succeed before branches can be merged |
Jsonnet Function¶
Pull Request Settings¶
| Key | Value | Description | Notes |
|---|---|---|---|
| required_approving_review_count | integer | The number or approvals required before a pull request can be merged | Allowed values in the range [0, 10] |
| dismisses_stale_reviews | boolean | If enabled, dismiss approved reviews automatically when a new commit is pushed | |
| requires_code_owner_review | boolean | If enabled, require an approved review in pull requests including files with a designated code owner | |
| requires_last_push_approval | boolean | Whether the most recent push must be approved by someone other than the person who pushed it | |
| requires_review_thread_resolution | boolean | If enabled, all conversations on code must be resolved before a pull request can be merged into a matching branch | |
| allowed_merge_methods | list[string] | The merge methods that are allowed when merging a pull request into a matching branch | Allowed values: merge, squash, rebase; defaults to all three, matching GitHub's behavior when the parameter is omitted |
Jsonnet Function¶
Merge Queue Settings¶
| Key | Value | Description | Notes |
|---|---|---|---|
| merge_method | string | Method to use when merging changes from queued pull requests | Possible values are MERGE, SQUASH or REBASE |
| build_concurrency | integer | Limit the number of queued pull requests requesting checks and workflow runs at the same time | Must be in non-negative number |
| min_group_size | integer | The minimum number of PRs that will be merged together in a group | Must be in non-negative number |
| max_group_size | integer | The maximum number of PRs that will be merged together in a group | Must be in non-negative number |
| wait_time_for_minimum_group_size | integer | The time in minutes the merge queue should wait after the first PR is added to the queue for the minimum group size to be met. After this time has elapsed, the minimum group size will be ignored and a smaller group will be merged |
Must be in non-negative number |
| status_check_timeout | integer | Maximum time in minutes for a required status check to report a conclusion. After this much time has elapsed, checks that have not reported a conclusion will be assumed to have failed |
Must be in non-negative number |
| requires_all_group_entries_to_pass_required_checks | boolean | When this setting is disabled, only the commit at the head of the merge group, i.e. the commit containing changes from all of the PRs in the group, must pass its required checks to merge |
Jsonnet Function¶
Copilot Code Review Settings¶
| Key | Value | Description | Notes |
|---|---|---|---|
| review_on_push | boolean | If enabled, Copilot reviews each new push to the pull request | |
| review_draft_pull_requests | boolean | If enabled, Copilot reviews draft pull requests before they are marked as ready for review |
Jsonnet Function¶
Pattern Settings¶
| Key | Value | Description | Notes |
|---|---|---|---|
| operator | string | The operator used to match the pattern | Possible values are starts_with, ends_with, contains or regex |
| pattern | string | The pattern to match | Must not be empty |
| name | string | The name of the rule shown on GitHub | Not sent to GitHub if empty |
| negate | boolean | If enabled, the rule fails if the pattern matches |
Jsonnet Function¶
Code Scanning Settings¶
| Key | Value | Description | Notes |
|---|---|---|---|
| code_scanning_tools | list[string] | List of code scanning tools that must provide results, as <tool>:<security_alerts_threshold>:<alerts_threshold>, e.g. CodeQL:high_or_higher:errors |
At least one tool must be listed. Possible security alerts thresholds are none, critical, high_or_higher, medium_or_higher or all, possible alerts thresholds are none, errors, errors_and_warnings or all |
Jsonnet Function¶
Code Quality Settings¶
| Key | Value | Description | Notes |
|---|---|---|---|
| severity | string | The lowest severity of the code quality results that must be resolved before a pull request can be merged | Possible values are errors, warnings, notes or all |
Jsonnet Function¶
Code Coverage Settings¶
| Key | Value | Description | Notes |
|---|---|---|---|
| minimum_coverage | number or null | The minimum line coverage of a pull request, in percent | Allowed values in the range [0, 100], not enforced if null |
| max_coverage_drop | number or null | The maximum drop of the line coverage of a pull request compared to the default branch, in percentage points | Allowed values in the range [0, 100], not enforced if null |
Jsonnet Function¶
Validation rules¶
- setting
enforcementtoevaluatefor an organization on a nonenterpriseplan triggers an error - setting
targetmust be one ofbranch,tagorpush, any other value triggers an error - setting
restricted_file_paths,max_file_path_length,restricted_file_extensionsormax_file_sizefor a ruleset whosetargetis notpushtriggers an error - setting a rule that rulesets with target
pushdo not support, e.g.copilot_code_revieworcommit_message_pattern, for a ruleset with targetpushtriggers an error, a warning for the rulesallows_*,requires_*,required_pull_request,required_status_checksandrequired_merge_queue - setting a rule required before merging a pull request, e.g.
copilot_code_revieworrequired_code_scanning, for a ruleset with targettagtriggers an error - setting
branch_name_patternfor a ruleset whosetargetis notbranch, ortag_name_patternfor a ruleset whosetargetis nottagtriggers an error - setting
include_refsorexclude_refsfor a ruleset with targetpushtriggers a warning, as push rulesets apply to all refs of a repository - setting
restricted_file_paths,max_file_path_length,restricted_file_extensionsormax_file_sizefor a ruleset of a public repository triggers an error, as GitHub only supports push rules for private and internal repositories - setting
max_file_path_lengthoutside the range [0, 32767],max_file_sizeoutside the range [0, 100], or more than 200 entries or an entry longer than 200 characters in the lists of the push rules triggers an error - setting
restricted_file_paths_exceptionswhilerestricted_file_pathsis empty, ormax_file_size_exceptionswhilemax_file_sizeis0triggers a warning - setting an invalid
operator, an emptypattern, an invalid code scanning tool or threshold, an invalid code quality severity or a code coverage threshold outside the range [0, 100] triggers an error - setting a push rule,
required_code_qualityorrequired_code_coveragefor an organization on afreeplan triggers a warning, as they require at least GitHub Team - setting a pattern, e.g.
commit_message_pattern, orrequires_license_compliance_scanningfor an organization on a nonenterpriseplan triggers a warning, as they require GitHub Enterprise - setting
required_workflowstriggers an error, as it is only supported by organization rulesets, see Organization Ruleset
Example usage¶
orgs.newOrg('adoptium') {
...
_repositories+:: [
...
orgs.newRepo('adoptium.net') {
description: "Adoptium Website",
homepage: "https://adoptium.net",
...
rulesets: [
orgs.newRepoRuleset('main') {
bypass_actors+: [
"@adoptium/project-leads",
],
include_refs+: [
"~DEFAULT_BRANCH"
],
required_pull_request+: {
required_approving_review_count: 0,
},
required_status_checks+: {
strict: true,
status_checks+: [
"build"
],
},
required_merge_queue: orgs.newMergeQueue() {
merge_method: "REBASE"
}
},
],
},
],
}