POST/repos/{owner}/{repo}/rulesets

Create a repository ruleset

Creates a ruleset for a repository to apply rules when its specified conditions are met. Supply a name and enforcement level, and use target, conditions, and rules to configure where the ruleset applies and which rules it enforces. You can also configure actors that can bypass the ruleset with bypass_actors.

  • IdempotentThe SDK sends Idempotency-Key, so a retried request is only applied once.

2 parameters · 6 body fields
ownerstringrequired
The account owner of the repository; the name is not case sensitive.
repostringrequired
The repository name without the `.git` extension; the name is not case sensitive.

Repository ruleset configuration, including its target, enforcement level, bypass actors, conditions, and rules.

namestringrequired
The name of the ruleset.
targetstringoptional
The target of the ruleset
Allowed:branchtagpushDefault:branch
enforcementstringrequired
The enforcement level of the ruleset. `evaluate` allows admins to test rules before enforcing them. Admins can view insights on the Rule Insights page (`evaluate` is only available with GitHub Enterprise).
Allowed:disabledactiveevaluate
bypass_actorsarray<RepositoryRulesetBypassActor>optional
The actors that can bypass the rules in this ruleset
conditionsobjectoptional
Parameters for a repository ruleset ref name condition
rulesarray<RepositoryRule>optional
An array of rules within the ruleset.

4 status codes
201Returns the created repository ruleset object, including its identifier, name, target, enforcement level, source, conditions, rules, and timestamps.
idintegerrequired
The ID of the ruleset
namestringrequired
The name of the ruleset
targetstringoptional
The target of the ruleset
Allowed:branchtagpushrepository
source_typestringoptional
The type of the source of the ruleset
Allowed:RepositoryOrganizationEnterprise
sourcestringrequired
The name of the source
enforcementstringrequired
The enforcement level of the ruleset. `evaluate` allows admins to test rules before enforcing them. Admins can view insights on the Rule Insights page (`evaluate` is only available with GitHub Enterprise).
Allowed:disabledactiveevaluate
bypass_actorsarray<RepositoryRulesetBypassActor>optional
The actors that can bypass the rules in this ruleset
current_user_can_bypassstringoptional
The bypass type of the user making the API request for this ruleset. This field is only returned when querying the repository-level endpoint.
Allowed:alwayspull_requests_onlyneverexempt
node_idstringoptional
_linksobjectoptional
conditionsobjectoptional
Parameters for a repository ruleset ref name condition
rulesarray<RepositoryRule>optional
created_atstringoptional
updated_atstringoptional
404Returned when the repository resource is not found.
messagestringoptional
documentation_urlstringoptional
urlstringoptional
statusstringoptional
422Returned when validation fails or the endpoint has been spammed.
messagestringrequired
documentation_urlstringrequired
errorsarray<object>optional
500Returned when an internal error occurs.
messagestringoptional
documentation_urlstringoptional
urlstringoptional
statusstringoptional

Error handling

A 404 is returned when the repository resource is not found; a 422 is returned when validation fails or the endpoint has been spammed; a 500 is returned when an internal error occurs. name and enforcement are required, and enforcement must be disabled, active, or evaluate; target must be branch, tag, or push when provided. Each bypass_actors item must use an accepted actor_type and bypass_mode, and the owner and repo path parameters must identify the repository.