Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/incidents/mx_gate_keeps_the_branch_current.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# mx. `mx_gate_keeps_the_branch_current`

**What happened:** A person approved someone's pull request and the auto-merge gate armed. Three seconds later the gate found the pull request conflicting with its base and stopped: on a person's pull request it never brought the base in (`updating:false`), it only told a person to resolve it. Twelve minutes later a person pushed the conflict resolution. CoderHelm reviewed only the pull request's own change since its approval and approved again, and the gate armed and stopped at once with "waiting on approvals". The person's approval was of the earlier commit, and the gate counted only approvals of the head, though GitHub itself still counted it. The gate waited on a review event that never came, said nothing more on the pull request or in the team's channel, and the person had to dismiss their approval and approve again for it to move.

**The guarantee:** A pull request behind or conflicting with its base is CoderHelm's maintenance, on anyone's pull request: as soon as the gate is armed (before a person's approval lands where the rules dismiss approvals on push) it merges the base in through the same conflict resolution runs use, once per head, compares the pull request's own change before and after with the reviewer's comparison (`review_scope::same_own_change`), queues CoderHelm's review of the new head itself, labelled pull request or not (a push's review, so the earlier approval is carried with the review it rests on when the pull request's own change is the one approved), and arms itself on the new head, where the review, CI and the keys are read again. The gate never waits on a review it caused. Only a conflict it can't resolve, or a fork it can't push to, is reported, once, with the files. The person key follows GitHub's own required-review rule (`reviewDecision`): an approval GitHub keeps counts, and with no rule an approval of an earlier commit counts when every commit since only brought the base in. When the gate waits on a person it names exactly what is missing (a dismissed approval and the commit that dismissed it, the branch's required count, who was asked) on the run page, in the pull request's one status comment and once in the team's channel, and it reads the pull request again every 15 minutes for a day, so a missed webhook can't strand it.
35 changes: 35 additions & 0 deletions services/worker/src/clients/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5841,6 +5841,41 @@ impl GitHubClient {
.await
}

/// Classic branch protection of a branch (needs read access to
/// administration; callers treat an error as not known).
pub async fn branch_protection(
&self,
owner: &str,
repo: &str,
branch: &str,
) -> Result<serde_json::Value, Box<dyn std::error::Error + Send + Sync>> {
self.get(&format!(
"{API_BASE}/repos/{owner}/{repo}/branches/{}/protection",
urlencoding::encode(branch)
))
.await
}

/// GitHub's own reading of a pull request's required reviews: its
/// `reviewDecision` (`APPROVED`, `REVIEW_REQUIRED`, `CHANGES_REQUESTED`),
/// `None` when the branch requires no reviews.
pub async fn pr_review_decision(
&self,
owner: &str,
repo: &str,
pr_number: u64,
) -> Result<Option<String>, Box<dyn std::error::Error + Send + Sync>> {
let data = self
.graphql_read(
"query($owner:String!,$name:String!,$pr:Int!){ repository(owner:$owner,name:$name){ pullRequest(number:$pr){ reviewDecision } } }",
serde_json::json!({ "owner": owner, "name": repo, "pr": pr_number }),
)
.await?;
Ok(data["repository"]["pullRequest"]["reviewDecision"]
.as_str()
.map(str::to_string))
}

/// Classic branch protection's required status checks (needs read
/// access to administration; callers treat an error as none).
pub async fn required_status_checks(
Expand Down
Loading
Loading