Skip to content

GitHub: Get rules for a branch

GitHub repos.reposGetBranchRules: arguments, response, policy and SDK examples.

← Repos operations · Get started

Operation github.repos_get_branch_rules

Provider route: GET /repos/{owner}/{repo}/rules/branches/{branch}. Alter supplies the connection’s credentials and routing.

Install @alter-ai/sdk @alter-ai/github with npm, or alter-sdk-github with pip. Supply your connected customer’s grant ID and the arguments described below.

import { App } from "@alter-ai/sdk";
import { GitHubIntegration } from "@alter-ai/github";
async function execute(input: Parameters<GitHubIntegration["repos"]["reposGetBranchRules"]>[0]) {
const app = new App({ apiKey: process.env.ALTER_API_KEY! });
try {
const provider = new GitHubIntegration(app, { grantId: process.env.PROVIDER_GRANT_ID! });
const call = await provider.repos.reposGetBranchRules(input);
const result = await call.wait();
return result.bodyJson();
} finally {
await app.close();
}
}
import os
from alter_sdk import App
from alter_sdk_github import GitHubIntegration
async def execute(arguments):
async with App(api_key=os.environ["ALTER_API_KEY"]) as app:
provider = GitHubIntegration(app, {"grant_id": os.environ["PROVIDER_GRANT_ID"]})
call = await provider.repos.repos_get_branch_rules(arguments)
result = await call.wait()
return result.body_json()
FieldTypePresenceDescription and constraints
$objectRootAdditional keys: not allowed
pathobjectRequired within parentAdditional keys: not allowed
path.ownerstringRequired within parent
path.repostringRequired within parent
path.branchstringRequired within parent
queryobjectOptionalAdditional keys: not allowed
query.per_pageintegerOptionalDefault: 30
query.pageintegerOptionalDefault: 1

Response media type: application/json. The table describes the pinned successful response. Referenced models link to their complete fields.

FieldTypePresenceDescription and constraints
$arrayRoot
$[]ModelEach itemExpand Get rules for a branch — response body — item

Referenced models: Get rules for a branch — response body — item

20 more schemas are linked from the tables above, on the schema pages.

Get a repository ruleset — response body — rules item branch name pattern
FieldTypePresenceDescription and constraints
$objectRootParameters to be used for the branch_name_pattern rule
parametersobjectOptional
parameters.namestringOptionalHow this rule appears when configuring it.
parameters.negatebooleanOptionalIf true, the rule will fail if the pattern matches.
parameters.operatorstringRequired within parentThe operator to use for matching.
Known values: starts_with, ends_with, contains, regex
parameters.patternstringRequired within parentThe pattern to match with.
typestringRequired within parentKnown values: branch_name_pattern
Get a repository ruleset — response body — rules item code coverage
FieldTypePresenceDescription and constraints
$objectRootEnforce minimum line coverage thresholds on pull requests. This rule evaluates uploaded coverage data but does not wait for coverage uploads. To ensure coverage is evaluated before merging, make each status check associated with a coverage upload a required status check.
parametersobjectOptional
parameters.max_coverage_dropJSONOptional
parameters.max_coverage_drop (anyOf 1)numberAlternativeThe maximum percentage points that line coverage may drop relative to the default branch. Pull requests that reduce line coverage by more than this amount will be blocked.
Format: float
Maximum: 100.0
Minimum: 0.0
parameters.max_coverage_drop (anyOf 2)stringAlternativePattern: ^-?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$
parameters.minimum_coverageJSONOptional
parameters.minimum_coverage (anyOf 1)numberAlternativeThe absolute minimum line coverage percentage required. Pull requests with line coverage below this threshold will be blocked.
Format: float
Maximum: 100.0
Minimum: 0.0
parameters.minimum_coverage (anyOf 2)stringAlternativePattern: ^-?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$
typestringRequired within parentKnown values: code_coverage
Get a repository ruleset — response body — rules item code quality
FieldTypePresenceDescription and constraints
$objectRootChoose which severity levels of code quality results should block pull request merges. When configured, a code quality analysis must be done on the pull request before the changes can be merged.
parametersobjectOptional
parameters.severitystringRequired within parentThe lowest severity level at which code quality reviews need to be resolved before commits can be merged.
Known values: errors, warnings, notes, all
typestringRequired within parentKnown values: code_quality
Get a repository ruleset — response body — rules item code scanning
FieldTypePresenceDescription and constraints
$objectRootChoose which tools must provide code scanning results before the reference is updated. When configured, code scanning must be enabled and have results for both the commit and the reference being updated.
parametersobjectOptional
parameters.code_scanning_toolsarrayRequired within parentTools that must provide code scanning results for this rule to pass.
parameters.code_scanning_tools[]ModelEach itemExpand Get a repository ruleset — response body — rules item code scanning parameters code scanning tools item
typestringRequired within parentKnown values: code_scanning

Referenced models: Get a repository ruleset — response body — rules item code scanning parameters code scanning tools item

Get a repository ruleset — response body — rules item commit author email pattern
FieldTypePresenceDescription and constraints
$objectRootParameters to be used for the commit_author_email_pattern rule
parametersobjectOptional
parameters.namestringOptionalHow this rule appears when configuring it.
parameters.negatebooleanOptionalIf true, the rule will fail if the pattern matches.
parameters.operatorstringRequired within parentThe operator to use for matching.
Known values: starts_with, ends_with, contains, regex
parameters.patternstringRequired within parentThe pattern to match with.
typestringRequired within parentKnown values: commit_author_email_pattern
Get a repository ruleset — response body — rules item commit message pattern
FieldTypePresenceDescription and constraints
$objectRootParameters to be used for the commit_message_pattern rule
parametersobjectOptional
parameters.namestringOptionalHow this rule appears when configuring it.
parameters.negatebooleanOptionalIf true, the rule will fail if the pattern matches.
parameters.operatorstringRequired within parentThe operator to use for matching.
Known values: starts_with, ends_with, contains, regex
parameters.patternstringRequired within parentThe pattern to match with.
typestringRequired within parentKnown values: commit_message_pattern
Get a repository ruleset — response body — rules item committer email pattern
FieldTypePresenceDescription and constraints
$objectRootParameters to be used for the committer_email_pattern rule
parametersobjectOptional
parameters.namestringOptionalHow this rule appears when configuring it.
parameters.negatebooleanOptionalIf true, the rule will fail if the pattern matches.
parameters.operatorstringRequired within parentThe operator to use for matching.
Known values: starts_with, ends_with, contains, regex
parameters.patternstringRequired within parentThe pattern to match with.
typestringRequired within parentKnown values: committer_email_pattern
Get a repository ruleset — response body — rules item copilot code review
FieldTypePresenceDescription and constraints
$objectRootRequest Copilot code review for new pull requests automatically if the author has access to Copilot code review and AI credits.
parametersobjectOptional
parameters.review_draft_pull_requestsbooleanOptionalCopilot automatically reviews draft pull requests before they are marked as ready for review.
parameters.review_on_pushbooleanOptionalCopilot automatically reviews each new push to the pull request.
typestringRequired within parentKnown values: copilot_code_review
Get a repository ruleset — response body — rules item creation
FieldTypePresenceDescription and constraints
$objectRootOnly allow users with bypass permission to create matching refs.
typestringRequired within parentKnown values: creation
Get a repository ruleset — response body — rules item deletion
FieldTypePresenceDescription and constraints
$objectRootOnly allow users with bypass permissions to delete matching refs.
typestringRequired within parentKnown values: deletion
Get a repository ruleset — response body — rules item file extension restriction
FieldTypePresenceDescription and constraints
$objectRootPrevent commits that include files with specified file extensions from being pushed to the commit graph.
parametersobjectOptional
parameters.restricted_file_extensionsarrayRequired within parentThe file extensions that are restricted from being pushed to the commit graph.
parameters.restricted_file_extensions[]stringEach item
typestringRequired within parentKnown values: file_extension_restriction
Get a repository ruleset — response body — rules item file path restriction
FieldTypePresenceDescription and constraints
$objectRootPrevent commits that include changes in specified file and folder paths from being pushed to the commit graph. This includes absolute paths that contain file names.
parametersobjectOptional
parameters.ignored_file_pathsarrayOptionalFiles matching these patterns are allowed even when they also match a restricted path.
parameters.ignored_file_paths[]stringEach item
parameters.restricted_file_pathsarrayRequired within parentThe file paths that are restricted from being pushed to the commit graph.
parameters.restricted_file_paths[]stringEach item
typestringRequired within parentKnown values: file_path_restriction
Get a repository ruleset — response body — rules item license compliance scanning
FieldTypePresenceDescription and constraints
$objectRootEnforce any added or changed dependencies to comply with the organization's license policy.
typestringRequired within parentKnown values: license_compliance_scanning
Get a repository ruleset — response body — rules item max file path length
FieldTypePresenceDescription and constraints
$objectRootPrevent commits that include file paths that exceed the specified character limit from being pushed to the commit graph.
parametersobjectOptional
parameters.max_file_path_lengthJSONRequired within parent
parameters.max_file_path_length (anyOf 1)integerAlternativeThe maximum amount of characters allowed in file paths.
Maximum: 32767
Minimum: 1
parameters.max_file_path_length (anyOf 2)stringAlternativePattern: ^-?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$
typestringRequired within parentKnown values: max_file_path_length

SDK function policy ID: github.repos_get_branch_rules. Catalog operation: repos/get-branch-rules. Rules can name either ID; function rules distinguish managed calls and conservatively cover raw calls sharing the route. Existing grant permissions and policy rules apply. wait() returns an immediate result or waits for a required approval; it never approves the request itself. Persist the approval ID to resume after a restart.

Provider errors retain their response; JSON decoding raises ProviderAPIError for provider failures. ManagedOperationError identifies contract/input/retention errors. See error handling and provider-specific behavior. Sensitive input may be refused before approval storage. A decoding error never resubmits a write.

Pinned headers: {"X-GitHub-Api-Version": "2026-03-10", "User-Agent": "Alter", "Accept": "application/vnd.github+json"}

Official provider source

Report an issue with this page

Necessary

Required for sign-in, security, authorization, and remembering your choices.

Always active

Analytics

Helps us understand which product and documentation features are useful.

Performance diagnostics

Uses performance tracing and privacy-masked session replay to diagnose problems.

You can change these choices at any time from Cookie settings.