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.
Call through Alter
Section titled “Call through Alter”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 osfrom alter_sdk import Appfrom 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()| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Additional keys: not allowed |
path | object | Required within parent | Additional keys: not allowed |
path.owner | string | Required within parent | |
path.repo | string | Required within parent | |
path.branch | string | Required within parent | |
query | object | Optional | Additional keys: not allowed |
query.per_page | integer | Optional | Default: 30 |
query.page | integer | Optional | Default: 1 |
Response
Section titled “Response”Response media type: application/json. The table describes the pinned successful response. Referenced models link to their complete fields.
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | array | Root | |
$[] | Model | Each item | Expand Get rules for a branch — response body — item |
Referenced models: Get rules for a branch — response body — item
Schemas
Section titled “Schemas”20 more schemas are linked from the tables above, on the schema pages.
Get a repository ruleset — response body — rules item branch name pattern
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Parameters to be used for the branch_name_pattern rule |
parameters | object | Optional | |
parameters.name | string | Optional | How this rule appears when configuring it. |
parameters.negate | boolean | Optional | If true, the rule will fail if the pattern matches. |
parameters.operator | string | Required within parent | The operator to use for matching. Known values: starts_with, ends_with, contains, regex |
parameters.pattern | string | Required within parent | The pattern to match with. |
type | string | Required within parent | Known values: branch_name_pattern |
Get a repository ruleset — response body — rules item code coverage
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Enforce 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. |
parameters | object | Optional | |
parameters.max_coverage_drop | JSON | Optional | |
parameters.max_coverage_drop (anyOf 1) | number | Alternative | The 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) | string | Alternative | Pattern: ^-?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$ |
parameters.minimum_coverage | JSON | Optional | |
parameters.minimum_coverage (anyOf 1) | number | Alternative | The 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) | string | Alternative | Pattern: ^-?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$ |
type | string | Required within parent | Known values: code_coverage |
Get a repository ruleset — response body — rules item code quality
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Choose 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. |
parameters | object | Optional | |
parameters.severity | string | Required within parent | The lowest severity level at which code quality reviews need to be resolved before commits can be merged. Known values: errors, warnings, notes, all |
type | string | Required within parent | Known values: code_quality |
Get a repository ruleset — response body — rules item code scanning
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Choose 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. |
parameters | object | Optional | |
parameters.code_scanning_tools | array | Required within parent | Tools that must provide code scanning results for this rule to pass. |
parameters.code_scanning_tools[] | Model | Each item | Expand Get a repository ruleset — response body — rules item code scanning parameters code scanning tools item |
type | string | Required within parent | Known 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
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Parameters to be used for the commit_author_email_pattern rule |
parameters | object | Optional | |
parameters.name | string | Optional | How this rule appears when configuring it. |
parameters.negate | boolean | Optional | If true, the rule will fail if the pattern matches. |
parameters.operator | string | Required within parent | The operator to use for matching. Known values: starts_with, ends_with, contains, regex |
parameters.pattern | string | Required within parent | The pattern to match with. |
type | string | Required within parent | Known values: commit_author_email_pattern |
Get a repository ruleset — response body — rules item commit message pattern
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Parameters to be used for the commit_message_pattern rule |
parameters | object | Optional | |
parameters.name | string | Optional | How this rule appears when configuring it. |
parameters.negate | boolean | Optional | If true, the rule will fail if the pattern matches. |
parameters.operator | string | Required within parent | The operator to use for matching. Known values: starts_with, ends_with, contains, regex |
parameters.pattern | string | Required within parent | The pattern to match with. |
type | string | Required within parent | Known values: commit_message_pattern |
Get a repository ruleset — response body — rules item committer email pattern
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Parameters to be used for the committer_email_pattern rule |
parameters | object | Optional | |
parameters.name | string | Optional | How this rule appears when configuring it. |
parameters.negate | boolean | Optional | If true, the rule will fail if the pattern matches. |
parameters.operator | string | Required within parent | The operator to use for matching. Known values: starts_with, ends_with, contains, regex |
parameters.pattern | string | Required within parent | The pattern to match with. |
type | string | Required within parent | Known values: committer_email_pattern |
Get a repository ruleset — response body — rules item copilot code review
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Request Copilot code review for new pull requests automatically if the author has access to Copilot code review and AI credits. |
parameters | object | Optional | |
parameters.review_draft_pull_requests | boolean | Optional | Copilot automatically reviews draft pull requests before they are marked as ready for review. |
parameters.review_on_push | boolean | Optional | Copilot automatically reviews each new push to the pull request. |
type | string | Required within parent | Known values: copilot_code_review |
Get a repository ruleset — response body — rules item creation
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Only allow users with bypass permission to create matching refs. |
type | string | Required within parent | Known values: creation |
Get a repository ruleset — response body — rules item deletion
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Only allow users with bypass permissions to delete matching refs. |
type | string | Required within parent | Known values: deletion |
Get a repository ruleset — response body — rules item file extension restriction
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Prevent commits that include files with specified file extensions from being pushed to the commit graph. |
parameters | object | Optional | |
parameters.restricted_file_extensions | array | Required within parent | The file extensions that are restricted from being pushed to the commit graph. |
parameters.restricted_file_extensions[] | string | Each item | |
type | string | Required within parent | Known values: file_extension_restriction |
Get a repository ruleset — response body — rules item file path restriction
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Prevent 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. |
parameters | object | Optional | |
parameters.ignored_file_paths | array | Optional | Files matching these patterns are allowed even when they also match a restricted path. |
parameters.ignored_file_paths[] | string | Each item | |
parameters.restricted_file_paths | array | Required within parent | The file paths that are restricted from being pushed to the commit graph. |
parameters.restricted_file_paths[] | string | Each item | |
type | string | Required within parent | Known values: file_path_restriction |
Get a repository ruleset — response body — rules item license compliance scanning
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Enforce any added or changed dependencies to comply with the organization's license policy. |
type | string | Required within parent | Known values: license_compliance_scanning |
Get a repository ruleset — response body — rules item max file path length
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Prevent commits that include file paths that exceed the specified character limit from being pushed to the commit graph. |
parameters | object | Optional | |
parameters.max_file_path_length | JSON | Required within parent | |
parameters.max_file_path_length (anyOf 1) | integer | Alternative | The maximum amount of characters allowed in file paths. Maximum: 32767 Minimum: 1 |
parameters.max_file_path_length (anyOf 2) | string | Alternative | Pattern: ^-?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$ |
type | string | Required within parent | Known values: max_file_path_length |
Policy, approvals and errors
Section titled “Policy, approvals and errors”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"}