Skip to content

Update an organization repository ruleset

PUT
/orgs/{org}/rulesets/{ruleset_id}

Update a ruleset for an organization.

API method documentation

org
required
string

The organization name. The name is not case sensitive.

ruleset_id
required
integer

The ID of the ruleset.

Request body

Media type application/json
object
name

The name of the ruleset.

string
target

The target of the ruleset

string
Allowed values: branch tag push repository
enforcement

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).

string
Allowed values: disabled active evaluate
bypass_actors

The actors that can bypass the rules in this ruleset

Array<object>
Repository Ruleset Bypass Actor

An actor that can bypass rules in a ruleset

object
actor_id

The ID of the actor that can bypass a ruleset. Required for Integration, RepositoryRole, Team, and User actor types. If actor_type is OrganizationAdmin, actor_id is ignored. If actor_type is DeployKey, this should be null. OrganizationAdmin is not applicable for personal repositories.

integer
nullable
actor_type
required

The type of actor that can bypass a ruleset.

string
Allowed values: Integration OrganizationAdmin RepositoryRole Team DeployKey User
bypass_mode

When the specified actor can bypass the ruleset. pull_request means that an actor can only bypass rules on pull requests. pull_request is not applicable for the DeployKey actor type. Also, pull_request is only applicable to branch rulesets. When bypass_mode is exempt, rules will not be run for that actor and a bypass audit entry will not be created.

string
default: always
Allowed values: always pull_request exempt
conditions
One of:
repository_name_and_ref_name

Conditions to target repositories by name and refs by name

object
ref_name
object
include

Array of ref names or patterns to include. One of these patterns must match for the condition to pass. Also accepts ~DEFAULT_BRANCH to include the default branch or ~ALL to include all branches.

Array<string>
exclude

Array of ref names or patterns to exclude. The condition will not pass if any of these patterns match.

Array<string>
repository_name
required
object
include

Array of repository names or patterns to include. One of these patterns must match for the condition to pass. Also accepts ~ALL to include all repositories.

Array<string>
exclude

Array of repository names or patterns to exclude. The condition will not pass if any of these patterns match.

Array<string>
protected

Whether renaming of target repositories is prevented.

boolean
rules

An array of rules within the ruleset.

Array<object>
One of:
creation

Only allow users with bypass permission to create matching refs.

object
type
required
string
Allowed values: creation
Examples
Example default
{
"name": "super cool ruleset",
"target": "branch",
"enforcement": "active",
"bypass_actors": [
{
"actor_id": 234,
"actor_type": "Team",
"bypass_mode": "always"
}
],
"conditions": {
"ref_name": {
"include": [
"refs/heads/main",
"refs/heads/master"
],
"exclude": [
"refs/heads/dev*"
]
},
"repository_name": {
"include": [
"important_repository",
"another_important_repository"
],
"exclude": [
"unimportant_repository"
],
"protected": true
}
},
"rules": [
{
"type": "commit_author_email_pattern",
"parameters": {
"operator": "contains",
"pattern": "github"
}
}
]
}

Response

Media type application/json
Repository ruleset

A set of rules to apply when specified conditions are met.

object
id
required

The ID of the ruleset

integer
name
required

The name of the ruleset

string
target

The target of the ruleset

string
Allowed values: branch tag push repository
source_type

The type of the source of the ruleset

string
Allowed values: Repository Organization Enterprise
source
required

The name of the source

string
enforcement
required

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).

string
Allowed values: disabled active evaluate
bypass_actors

The actors that can bypass the rules in this ruleset

Array<object>
Repository Ruleset Bypass Actor

An actor that can bypass rules in a ruleset

object
actor_id

The ID of the actor that can bypass a ruleset. Required for Integration, RepositoryRole, Team, and User actor types. If actor_type is OrganizationAdmin, actor_id is ignored. If actor_type is DeployKey, this should be null. OrganizationAdmin is not applicable for personal repositories.

integer
nullable
actor_type
required

The type of actor that can bypass a ruleset.

string
Allowed values: Integration OrganizationAdmin RepositoryRole Team DeployKey User
bypass_mode

When the specified actor can bypass the ruleset. pull_request means that an actor can only bypass rules on pull requests. pull_request is not applicable for the DeployKey actor type. Also, pull_request is only applicable to branch rulesets. When bypass_mode is exempt, rules will not be run for that actor and a bypass audit entry will not be created.

string
default: always
Allowed values: always pull_request exempt
current_user_can_bypass

The bypass type of the user making the API request for this ruleset. This field is only returned when querying the repository-level endpoint.

string
Allowed values: always pull_requests_only never exempt
node_id
string
_links
object
self
object
href

The URL of the ruleset

string
html
object
href

The html URL of the ruleset

string
conditions
Any of:
Repository ruleset conditions for ref names

Parameters for a repository ruleset ref name condition

object
ref_name
object
include

Array of ref names or patterns to include. One of these patterns must match for the condition to pass. Also accepts ~DEFAULT_BRANCH to include the default branch or ~ALL to include all branches.

Array<string>
exclude

Array of ref names or patterns to exclude. The condition will not pass if any of these patterns match.

Array<string>
rules
Array<object>
One of:
creation

Only allow users with bypass permission to create matching refs.

object
type
required
string
Allowed values: creation
created_at
string format: date-time
updated_at
string format: date-time
Examples
Example default
{
"id": 21,
"name": "super cool ruleset",
"target": "branch",
"source_type": "Organization",
"source": "my-org",
"enforcement": "active",
"bypass_actors": [
{
"actor_id": 234,
"actor_type": "Team",
"bypass_mode": "always"
}
],
"conditions": {
"ref_name": {
"include": [
"refs/heads/main",
"refs/heads/master"
],
"exclude": [
"refs/heads/dev*"
]
},
"repository_name": {
"include": [
"important_repository",
"another_important_repository"
],
"exclude": [
"unimportant_repository"
],
"protected": true
}
},
"rules": [
{
"type": "commit_author_email_pattern",
"parameters": {
"operator": "contains",
"pattern": "github"
}
}
],
"node_id": "RRS_lACkVXNlcgQB",
"_links": {
"self": {
"href": "https://api.github.com/orgs/my-org/rulesets/21"
},
"html": {
"href": "https://github.com/organizations/my-org/settings/rules/21"
}
},
"created_at": "2023-08-15T08:43:03Z",
"updated_at": "2023-09-23T16:29:47Z"
}

Resource not found

Media type application/json
Basic Error

Basic Error

object
message
string
documentation_url
string
url
string
status
string
Example generated
{
"message": "example",
"documentation_url": "example",
"url": "example",
"status": "example"
}

Validation failed, or the endpoint has been spammed.

Media type application/json
Validation Error

Validation Error

object
message
required
string
documentation_url
required
string
errors
Array<object>
object
resource
string
field
string
message
string
code
required
string
index
integer
value
One of:
string
nullable
Example generated
{
"message": "example",
"documentation_url": "example",
"errors": [
{
"resource": "example",
"field": "example",
"message": "example",
"code": "example",
"index": 1,
"value": [
"example"
]
}
]
}

Internal Error

Media type application/json
Basic Error

Basic Error

object
message
string
documentation_url
string
url
string
status
string
Example generated
{
"message": "example",
"documentation_url": "example",
"url": "example",
"status": "example"
}