Protect a GitHub repository for agents
curl --request POST \ --url https://example.com/api/v1/github/repositories/example/agent-protection \ --header 'Authorization: Bearer <token>'Adds Chelsea’s own rule sets to the repository where it does not already hold agents back: a branch rule set when its branches do not and a tag rule set when its tags are open (contents: write can create tags and releases). Each restricts creations, updates and deletions, on every branch outside agent/ or on every tag. When one of Chelsea’s own rule sets already exists in an older shape (people with bypass mode always, or a pull request rule in place of Restrict updates), it is brought to this one in place with one write, keeping its branches, its bypass list and any rule the team added; one already in this shape is not written. Then runs the check linking a repository to a project runs, and answers whether the repository now holds agents back (isProtected) and what is missing when it does not (problem). No other rule set or branch protection is edited, deleted or bypassed. People with the Write, Maintain or Admin role in the repository are exempt from both rule sets, so they create branches, push and merge with no bypass box; the integrations the organization chose in Settings, Integrations, GitHub (Shopify by default) can bypass them, and the GitHub App never can, so agents stay on agent/ branches, never create or move tags and cannot merge a pull request outside agent/. When GitHub refuses an integration because it is not installed in the organization, the rule set is added without it and droppedBypass names it. Needs the App’s Administration write access (424 GITHUB_ACCESS_MISSING names the step). Requires github.view and github.manage.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”The repository’s name inside the organization
The repository’s name inside the organization
Responses
Section titled “Responses”What the repository holds back now.
object
object
The integrations the rule set was meant to let through (such as Shopify) that GitHub refused because they are not installed in the organization, so the rule set was added without them. Empty when none was dropped; absent on an older server.
Whether the repository now holds the App back the way a code agent’s token requires: the default branch blocks direct pushes, and every branch outside agent/ and every tag restricts creations, updates and deletions through rule sets the App cannot bypass, so no agent token can merge a pull request outside agent/.
Whether Chelsea added its branch or tag rule set now or brought one of them from an older shape to the current one, with people exempt. false when nothing was written.
What is still missing, in words, when isProtected is false; else null.
Example generated
{ "data": { "defaultBranch": "example", "droppedBypass": [ "example" ], "fullName": "example", "isProtected": true, "isRulesetAdded": true, "problem": "example" }}Validation error. Parse failures include field paths and expectations.
Validation error with safe field paths and expected values; submitted values are never returned.
object
object
Stable machine-readable error code.
object
Human-readable error message.
HTTP status code, mirrored in the body.
Example
{ "error": { "code": "UNAUTHORIZED" }}Unauthorized.
Standard error envelope.
object
object
Stable machine-readable error code.
Human-readable error message.
HTTP status code, mirrored in the body.
Example
{ "error": { "code": "UNAUTHORIZED" }}Forbidden.
Standard error envelope.
object
object
Stable machine-readable error code.
Human-readable error message.
HTTP status code, mirrored in the body.
Example
{ "error": { "code": "UNAUTHORIZED" }}Not found.
Standard error envelope.
object
object
Stable machine-readable error code.
Human-readable error message.
HTTP status code, mirrored in the body.
Example
{ "error": { "code": "UNAUTHORIZED" }}Conflict.
Standard error envelope.
object
object
Stable machine-readable error code.
Human-readable error message.
HTTP status code, mirrored in the body.
Example
{ "error": { "code": "UNAUTHORIZED" }}Invalid input.
Standard error envelope.
object
object
Stable machine-readable error code.
Human-readable error message.
HTTP status code, mirrored in the body.
Example
{ "error": { "code": "UNAUTHORIZED" }}GitHub failed (GITHUB_API_ERROR), or Chelsea’s GitHub App or the organization has not granted the access this needs (GITHUB_ACCESS_MISSING; the message names the step in Settings, Integrations, GitHub).
Standard error envelope.
object
object
Stable machine-readable error code.
Human-readable error message.
HTTP status code, mirrored in the body.
Example
{ "error": { "code": "UNAUTHORIZED" }}Rate limit exceeded. Wait for Retry-After before retrying.
Standard error envelope.
object
object
Stable machine-readable error code.
Human-readable error message.
HTTP status code, mirrored in the body.
Example
{ "error": { "code": "UNAUTHORIZED" }}Headers
Section titled “Headers”Maximum requests in the current quota window.
Quota policy in requests and window seconds, for example 60;w=60.
Requests left in this quota window (zero when blocked).
Seconds until the current quota window resets, when available from the rate-limit store.
Seconds until another request may be attempted.
Chelsea is operated by Arepa Labs LLC