Skip to main content

rules

Creates, updates, deletes, gets or lists a rules resource.

Overview

Namerules
TypeResource
Idgithub.repos.rules

Fields

The following fields are returned by SELECT queries:

Response

NameDatatypeDescription
ruleset_idintegerThe ID of the ruleset that includes this rule.
parametersobject
ruleset_sourcestringThe name of the source of the ruleset that includes this rule.
ruleset_source_typestringThe type of source for the ruleset that includes this rule. (Repository, Organization)
typestring (creation)

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
get_branch_rulesselectowner, repo, branchper_page, pageReturns all active rules that apply to the specified branch. The branch does not need to exist; rules that would apply
to a branch with that name will be returned. All active rules that apply will be returned, regardless of the level
at which they are configured (e.g. repository or organization). Rules in rulesets with "evaluate" or "disabled"
enforcement statuses are not returned.
get_repo_rulesetselectowner, repo, ruleset_idincludes_parentsGet a ruleset for a repository.

Note: To prevent leaking sensitive information, the bypass_actors property is only returned if the user
making the API request has write access to the ruleset.
get_org_rulesetselectorg, ruleset_idGet a repository ruleset for an organization.

Note: To prevent leaking sensitive information, the bypass_actors property is only returned if the user
making the API request has write access to the ruleset.
get_repo_rulesetsselectowner, repoper_page, page, includes_parents, targetsGet all the rulesets for a repository.
get_org_rulesetsselectorgper_page, page, targetsGet all the repository rulesets for an organization.
create_repo_rulesetinsertowner, repo, name, enforcementCreate a ruleset for a repository.
create_org_rulesetinsertorg, name, enforcementCreate a repository ruleset for an organization.
update_repo_rulesetreplaceowner, repo, ruleset_idUpdate a ruleset for a repository.
update_org_rulesetreplaceorg, ruleset_idUpdate a ruleset for an organization.
delete_repo_rulesetdeleteowner, repo, ruleset_idDelete a ruleset for a repository.
delete_org_rulesetdeleteorg, ruleset_idDelete a ruleset for an organization.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
branchstringThe name of the branch. Cannot contain wildcard characters. To use wildcard characters in branch names, use the GraphQL API.
orgstringThe organization name. The name is not case sensitive.
ownerstringThe account owner of the repository. The name is not case sensitive.
repostringThe name of the repository without the .git extension. The name is not case sensitive.
ruleset_idintegerThe ID of the ruleset.
includes_parentsbooleanInclude rulesets configured at higher levels that apply to this repository
pageintegerThe page number of the results to fetch. For more information, see "Using pagination in the REST API."
per_pageintegerThe number of results per page (max 100). For more information, see "Using pagination in the REST API."
targetsstringA comma-separated list of rule targets to filter by. If provided, only rulesets that apply to the specified targets will be returned. For example, branch,tag,push.

SELECT examples

Returns all active rules that apply to the specified branch. The branch does not need to exist; rules that would apply
to a branch with that name will be returned. All active rules that apply will be returned, regardless of the level
at which they are configured (e.g. repository or organization). Rules in rulesets with "evaluate" or "disabled"
enforcement statuses are not returned.

SELECT
ruleset_id,
parameters,
ruleset_source,
ruleset_source_type,
type
FROM github.repos.rules
WHERE owner = '{{ owner }}' -- required
AND repo = '{{ repo }}' -- required
AND branch = '{{ branch }}' -- required
AND per_page = '{{ per_page }}'
AND page = '{{ page }}'
;

INSERT examples

Create a ruleset for a repository.

INSERT INTO github.repos.rules (
name,
target,
enforcement,
bypass_actors,
conditions,
rules,
owner,
repo
)
SELECT
'{{ name }}' /* required */,
'{{ target }}',
'{{ enforcement }}' /* required */,
'{{ bypass_actors }}',
'{{ conditions }}',
'{{ rules }}',
'{{ owner }}',
'{{ repo }}'
RETURNING
id,
name,
node_id,
_links,
bypass_actors,
conditions,
created_at,
current_user_can_bypass,
enforcement,
rules,
source,
source_type,
target,
updated_at
;

REPLACE examples

Update a ruleset for a repository.

REPLACE github.repos.rules
SET
name = '{{ name }}',
target = '{{ target }}',
enforcement = '{{ enforcement }}',
bypass_actors = '{{ bypass_actors }}',
conditions = '{{ conditions }}',
rules = '{{ rules }}'
WHERE
owner = '{{ owner }}' --required
AND repo = '{{ repo }}' --required
AND ruleset_id = '{{ ruleset_id }}' --required
RETURNING
id,
name,
node_id,
_links,
bypass_actors,
conditions,
created_at,
current_user_can_bypass,
enforcement,
rules,
source,
source_type,
target,
updated_at;

DELETE examples

Delete a ruleset for a repository.

DELETE FROM github.repos.rules
WHERE owner = '{{ owner }}' --required
AND repo = '{{ repo }}' --required
AND ruleset_id = '{{ ruleset_id }}' --required
;