Skip to content

[Feature Request] Add checks field to RequiredStatusChecks #2274

Closed

Description

@k24dizzle

According to the Github API, there is a new checks field that is supposed to replace the contexts field when setting required status checks.
Screen Shot 2022-01-27 at 12 16 01 PM

Note: if contexts is required, not sure how that will interact with the checks field.

Add this field here.
Screen Shot 2022-01-27 at 12 14 26 PM

Activity

  1. gmlewis commented on Jan 27, 2022

    @gmlewis
    Collaborator

    Thank you, @k24dizzle ! Would you like to make a PR, or shall I open this up to other contributors to this repo?

  2. k24dizzle commented on Jan 27, 2022

    @k24dizzle
    ContributorAuthor

    Hi @gmlewis, new to contributing to this repo but I can give it a shot

  3. gmlewis commented on Jan 27, 2022

    @gmlewis
    Collaborator

    Excellent, @k24dizzle !
    Please make sure to check out our CONTRIBUTING.md file for how to get started.

  4. k24dizzle commented on Jan 27, 2022

    @k24dizzle
    ContributorAuthor

    I did some more research, with some CURLs and realized that in required_status_checks you must supply either contexts or checks, but you cannot supply both at the same time:

    curl   -X PUT   -H "Accept: application/vnd.github.v3+json" \
      -H "Authorization: token REDACTED" \
        https://api.github.com/repos/ORG/REPO_NAME/branches/BRANCH_NAME/protection  \
      -d '{"enforce_admins": null, "required_pull_request_reviews": null,
         "required_status_checks":{"strict":true,"contexts":["contexts"],"checks":[{"context":"contexts"}]}, 
         "restrictions": null}'
    {
      "message": "Invalid request.\n\nNo subschema in \"anyOf\" matched.\nMore than one subschema in \"oneOf\" matched.\nNot all subschemas of \"allOf\" matched.\nFor 'anyOf/1', {\"strict\"=>true, \"contexts\"=>[\"contexts\"], \"checks\"=>[{\"context\"=>\"contexts\"}]} is not a null.",
      "documentation_url": "https://docs.github.com/rest/reference/repos#update-branch-protection"
    }
    

    So the documentation given by github is a little misleading:

    Screen Shot 2022-01-27 at 3 34 29 PM

    You could just provide checks (without contexts) for example and this should work:

    curl   -X PUT   -H "Accept: application/vnd.github.v3+json" \
      -H "Authorization: token REDACTED" \
        https://api.github.com/repos/ORG/REPO_NAME/branches/BRANCH_NAME/protection  \
      -d '{"enforce_admins": null, "required_pull_request_reviews": null,
         "required_status_checks":{"strict":true,"checks":[{"context":"contexts"}]}, 
         "restrictions": null}'
    

    Right now, I'm kind of stuck on figuring out how to enforce this logic/rule in go-github to help prevent these invalid request errors. Is there an example of how to specify a required one or the other field logic?

  5. gmlewis commented on Jan 27, 2022

    @gmlewis
    Collaborator

    If both fields are slices with omitempty, then you could set one or the other to nil and they should not be passed to the endpoint (which you can confirm with a unit test).

  6. added a commit that references this issue on May 9, 2024
    e1c28bc
  7. added a commit that references this issue on Jun 28, 2026
    06b0505
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions