Skip to content

Add checks field to RequiredStatusChecks - #2276

Merged
gmlewis merged 3 commits into
google:masterfrom
k24dizzle:checks
Jan 31, 2022
Merged

gmlewis merged 3 commits into
google:masterfrom
k24dizzle:checks

Conversation

@k24dizzle

@k24dizzle k24dizzle commented Jan 28, 2022 •

Copy link
Copy Markdown
Contributor

Attempt to solve #2274.

From my own experimentation, I discovered that there's two ways that this Checks field can be used to update the required status checks for a protected branch:

  • update branch protection -> via the ProtectionRequest -> RequiredStatusChecks -> RequiredStatusCheck struct, in this API call we must provide either one of Checks or Contexts (the other must be nil) in RequiredStatusChecks to successfully update a branch protection. If you provide both or neither, you will get an Invalid Request error.
  • update status check protection -> via the RequiredStatusChecksRequest -> RequiredStatusCheck struct, in this API call Checks and Contexts are both optional fields, if you provide both of them only Checks will be used to update the status checks.

@codecov

codecov Bot commented Jan 29, 2022 •

Copy link
Copy Markdown

Codecov Report

Merging #2276 (d801426) into master (51df45c) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2276   +/-   ##
=======================================
  Coverage   97.81%   97.81%           
=======================================
  Files         114      114           
  Lines       10266    10266           
=======================================
  Hits        10042    10042           
  Misses        156      156           
  Partials       68       68           
Impacted Files Coverage Δ
github/repos.go 98.70% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 51df45c...d801426. Read the comment docs.

@gmlewis gmlewis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @k24dizzle !
Just a couple tweaks, please.

Comment thread github/repos.go Resolved
Comment thread github/repos.go Resolved
@gmlewis

gmlewis commented Jan 29, 2022

Copy link
Copy Markdown
Collaborator

It looks like the linter has a couple issues as well.

@gmlewis gmlewis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @k24dizzle !
LGTM.
Merging.

@gmlewis
gmlewis merged commit e1c28bc into google:master Jan 31, 2022
jlaportebot added a commit to jlaportebot/go-github that referenced this pull request Jun 28, 2026
Equinxe added a commit to Equinxe/AI_Enginering that referenced this pull request Nov 4, 2026
…und 2 left untested

Review round 3 of PR #460 at 23e4dc0 (QA Engineer, Code Reviewer R2-C1,
R2-C2, R2-M1, R2-m1; Security Engineer's non-blocking points).

Every branch PUT sent required_status_checks with both contexts and checks.
GitHub refuses that body: google/go-github#2276 ("If you provide both or
neither, you will get an Invalid Request error") and #2976 (a raw PUT
refused with both, accepted with checks alone), and
sigmavirus24/github3.py#1112 (422, more than one subschema in oneOf
matched). On a real repository the script would have protected nothing.
The body now sends checks alone. The REST docs give contexts a "Closing
down notice" and say to use checks instead (Update branch protection,
required_status_checks). A check with no app_id gets the app GitHub
selects, as contexts would. Both fake gh now refuse a branch protection PUT
that holds both lists or neither, with a 422 as GitHub does, and the case
that pinned both lists now pins checks alone.

Guards no case could fail now have one (R2-M1): an answer jq cannot read,
for the repository, the GitHub Actions app, a protection, the ruleset list
(which would otherwise create a second ruleset after main and develop were
written), the read-back of the required checks and that of automatic
head-branch deletion; a failed read-back of automatic head-branch deletion;
an Actions app id that is not an integer; a check sent as any app (-1) that
comes back with no app, and one that comes back tied to an app.

The Requires line, README.md, Workflows/PROJECT_BOOTSTRAP.md Step 2 and the
missing-jq message name jq and say how to install it; Git for Windows does
not include it. When the read-back after a PUT stops the run, the message
says that branch's new protection is already written, and to check and
restore it in Settings > Branches.

Red: on 23e4dc0's script, 56 of the 130 checks of this file's first
round-3 version fail, every run stopping on the fake's 422 for both lists.
Mutant X01, which sends contexts beside checks again, fails 38 of 46 the
same way. Each guard R2-M1 lists, removed alone, is caught by its new case
(Y03, Y04, Y09, Y09b, Y25 to Y30), as are the jq and read-back message
mutants (X02, X03). Green: the full set no longer fits 600 s on this
machine, so it ran in two halves, 95 and 54 checks passed, and the
WU-IAENG-384 cases passed before the limit.

RISK: GitHub refuses the PUT body with checks alone, which no case can show without writing to a real repository | tier=Medium | mitigation=checks is the non-deprecated form in the REST docs, and the go-github #2976 reproduction shows it accepted; a refused write stops the run before any other write and names what was applied | decided_by=self

Work Unit: WU-IAENG-433

Employee: DevOps Engineer
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants