Skip to content

[Schema Inaccuracy] Updating branch protection rules - restrictions schema requires subschemas of apps and teams. GitHub accounts without organizations cannot have users and teams restrictions. #1319

Closed
@simonmcho

Description

@simonmcho

Schema Inaccuracy

As title states, organization-less GitHub Accounts cannot have users and teams restrictions for branch protection rules. However, the schema for restrictions require the subschema key of teams. Passing in an empty array results in a schema error.

Expected

Schema validation to accept empty array or undefined teams subschema in restrictions.

Reproduction Steps

Scenario 1
Note the empty array for restrictions.teams:

curl \
  -X PUT \
  -H "Accept: application/vnd.github+json" \ 
  -H "Authorization: token <TOKEN>" \
  https://api.github.com/repos/OWNER/REPO/branches/BRANCH/protection \
  -d '{"required_status_checks":{"strict":true,"contexts":["continuous-integration/travis-ci"]},"enforce_admins":true,"required_pull_request_reviews":{"dismissal_restrictions":{"users":["octocat"],"teams":[]},"dismiss_stale_reviews":true,"require_code_owner_reviews":true,"required_approving_review_count":2,"bypass_pull_request_allowances":{"users":["octocat"],"teams":["justice-league"]}},"restrictions":{"users":["octocat"],"teams":[],},"required_linear_history":true,"allow_force_pushes":true,"allow_deletions":true,"block_creations":true,"required_conversation_resolution":true}'

Response:

{
    "message": "Validation Failed",
    "errors": [
        "Only organization repositories can have users and team restrictions"
    ],
    "documentation_url": "https://docs.github.com/rest/reference/repos#update-branch-protection"
}

Scenario 2

Note the missing subschema for teams in restrictions:

curl \
  -X PUT \
  -H "Accept: application/vnd.github+json" \ 
  -H "Authorization: token <TOKEN>" \
  https://api.github.com/repos/OWNER/REPO/branches/BRANCH/protection \
  -d '{"required_status_checks":{"strict":true,"contexts":["continuous-integration/travis-ci"]},"enforce_admins":true,"required_pull_request_reviews":{"dismissal_restrictions":{"users":["octocat"],"teams":[]},"dismiss_stale_reviews":true,"require_code_owner_reviews":true,"required_approving_review_count":2,"bypass_pull_request_allowances":{"users":["octocat"],"teams":["justice-league"]}},"restrictions":{"users":["octocat"],"teams":[],},"required_linear_history":true,"allow_force_pushes":true,"allow_deletions":true,"block_creations":true,"required_conversation_resolution":true}'

Response:

{
    "message": "Invalid request.\n\nNo subschema in \"anyOf\" matched.\nFor 'properties/users', nil is not an array.\nFor 'properties/teams', nil is not an array.\nNot all subschemas of \"allOf\" matched.\nFor 'anyOf/1', {\"users\"=>nil, \"apps\"=>[], \"teams\"=>nil} is not a null.",
    "documentation_url": "https://docs.github.com/rest/reference/repos#update-branch-protection"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions