Skip to content

Organization Ruleset

Definition of an Organization Ruleset, the following properties are supported:

Key Value Description Notes
include_repo_names list[RepoNameMatcher] List of names or patterns to include matching repositories
exclude_repo_names list[RepoNameMatcher] List of names or patterns to exclude matching repositories
protect_repo_names boolean If enabled, target repositories can only be renamed by those with bypass permission
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_workflows WorkflowsSettings or null If specified, workflows must pass before branches 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 matching repositories: 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_workflows, 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

orgs.newOrgRuleset('<name>') {
  <key>: <value>
}

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

orgs.newStatusChecks() {
  <key>: <value>
}

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

orgs.newPullRequest() {
  <key>: <value>
}

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

orgs.newMergeQueue() {
  <key>: <value>
}

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

orgs.newCopilotCodeReview() {
  <key>: <value>
}

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

orgs.newPattern() {
  <key>: <value>
}

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

orgs.newCodeScanning() {
  <key>: <value>
}

Workflows Settings

Key Value Description Notes
do_not_enforce_on_create boolean If enabled, allow repositories and branches to be created if a workflow would otherwise prohibit it
workflows list[string] List of workflows that must pass, as <owner>/<repository>:<path>[@<ref>][#<sha>], e.g. my-org/.github:.github/workflows/build.yml@refs/heads/main At least one workflow must be listed. The ref is a branch or a tag, the sha a commit, the repository is case-insensitive. %, @ and # are written %25, %40 and %23 in a path or a ref

Jsonnet Function

orgs.newWorkflows() {
  <key>: <value>
}

Validation rules

  • setting enforcement to evaluate for an organization on a non enterprise plan triggers an error
  • setting target must be one of branch, tag or push, any other value triggers an error
  • setting restricted_file_paths, max_file_path_length, restricted_file_extensions or max_file_size for a ruleset whose target is not push triggers an error
  • setting a rule that rulesets with target push do not support, e.g. copilot_code_review or commit_message_pattern, for a ruleset with target push triggers an error, a warning for the rules allows_*, requires_*, required_pull_request, required_status_checks and required_merge_queue
  • setting a rule required before merging a pull request, e.g. copilot_code_review or required_workflows, for a ruleset with target tag triggers an error
  • setting branch_name_pattern for a ruleset whose target is not branch, or tag_name_pattern for a ruleset whose target is not tag triggers an error
  • setting include_refs or exclude_refs for a ruleset with target push triggers a warning, as push rulesets apply to all refs of a repository
  • setting max_file_path_length outside the range [0, 32767], max_file_size outside 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_exceptions while restricted_file_paths is empty, or max_file_size_exceptions while max_file_size is 0 triggers a warning
  • setting an invalid operator, an empty pattern, an invalid code scanning tool or threshold, an invalid code quality severity, a code coverage threshold outside the range [0, 100] or an invalid workflow triggers an error
  • setting a workflow whose path is not a .yml or .yaml file triggers a warning, e.g. because of an unescaped @ in the path
  • referencing the repository of a workflow by its id triggers an error, otterdog shows a repository by its id only if it can not resolve its name, e.g. if the repository was deleted
  • setting a push rule, required_code_quality or required_code_coverage for an organization on a free plan triggers a warning, as they require at least GitHub Team
  • setting a pattern, e.g. commit_message_pattern, or requires_license_compliance_scanning for an organization on a non enterprise plan triggers a warning, as they require GitHub Enterprise
  • setting required_code_quality, required_code_coverage or requires_license_compliance_scanning triggers an error, as they are only supported by repository rulesets
  • defining organization rulesets for an organization on a non enterprise plan triggers an error

Example usage

The following ruleset would basically prevent force-pushes for the default branch of all repositories of the eclipse-csi GitHub organization:

orgs.newOrg('eclipse-csi') {
  ...
  rulesets: [
    orgs.newOrgRuleset('main') {
      include_repo_names: [
        "~ALL"
      ],
      include_refs+: [
        "~DEFAULT_BRANCH"
      ],
      required_pull_request: null,
      required_status_checks: null,
    },
  ],
}