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
1 change: 1 addition & 0 deletions changelog.d/fixed-owner-approve-admits-untrusted-pr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Activity Monitor: an owner's Approve (either variant) on an untrusted-author PR is now a trust override for that head — the stage record carries `admitted_by: operator-approval:<login>`, the contributor lane merges the head as-is after checks and soak, and the adoption engine refuses to adopt or supersede it while the admission stands (before, the approval was reduced to a comment and the claim-tier rule adopt-superseded the PR). When the head cannot merge as-is (commits without a Signed-off-by) the popover and both Approve confirms say so before acting and offer "Re-author as hive PR" as a separate choice. Fixes #15136 (#15156).
2 changes: 1 addition & 1 deletion src/docs/dashboard-sections.md
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ The glyph is drawn for **every** row on the gate, so two rows in the same state

| State the pill shows | Lead actions in ⋯ and in the popover (consequence) |
|---|---|
| PR at 090 *Ready for human merge* (untrusted author, workflow files, manual-merge path, branch protection…) | **Approve & merge as maintainer** (merges #N into *base* now via hive's identity, attributed to you — a comment on the PR names you, the audit log records `repo_item_decision_merge`, `source: dashboard`) · **Approve — let hive merge** (records your approval as the owner decision — an APPROVE review and the automerge label; the hive's merge sweep merges it on its next pass once CI is green and the head has soaked) · Give direction (hive-authored PRs only) · Close as superseded · Close as won't fix · Hold. Both merge actions need the merger or owner role and confirm first (with *Don't ask again*); the toast reads *merged* / *queued for merge*; the badge records `merge-now` / `queue-merge`. **Let hive decide** is here too (third): on a 090 PR it never runs the policy — the hive answers at once through the no-effect toast, *I can't merge this: author @Karibhou is untrusted on hotshot — …*, with *Approve & merge as maintainer · Approve — let hive merge* as buttons and the 👥 Contributors fix in the next line. |
| PR at 090 *Ready for human merge* (untrusted author, workflow files, manual-merge path, branch protection…) | **Approve & merge as maintainer** (merges #N into *base* now via hive's identity, attributed to you — a comment on the PR names you, the audit log records `repo_item_decision_merge`, `source: dashboard`) · **Approve — let hive merge** (records your approval as the owner decision — an APPROVE review and the automerge label; the hive's merge sweep merges it on its next pass once CI is green and the head has soaked) · Give direction (hive-authored PRs only) · Close as superseded · Close as won't fix · Hold. Both merge actions need the merger or owner role and confirm first (with *Don't ask again*); the toast reads *merged* / *queued for merge*; the badge records `merge-now` / `queue-merge`. **Let hive decide** is here too (third): on a 090 PR it never runs the policy — the hive answers at once through the no-effect toast, *I can't merge this: author @Karibhou is untrusted on hotshot — …*, with *Approve & merge as maintainer · Approve — let hive merge* as buttons and the 👥 Contributors fix in the next line. **Either Approve is the trust override for that head** ([#15136](https://github.com/hivecommons/hive/issues/15136); owner, 2026-10-29: "I approved these and then they went to adopted…"): the stage record gets `admitted_by: operator-approval:<you>`, the contributor lane merges the head as-is after checks and soak, and the adoption engine refuses to adopt or supersede it while the admission stands (the row reads *not adopted: a maintainer approved this head; the hive merges it as-is*; the 090 tooltip and popover say *Approved by @you as the owner decision…* and the second Approve greys out). When the record's commit check found commits without a `Signed-off-by`, the popover's blocker line and both Approve confirms say so **before** acting (*2 of 3 commits have no Signed-off-by, so a required DCO check refuses the merge*) and a third lead action appears, **Re-author as hive PR** — the explicit, separate choice: the hive re-homes the commits on a signed-off hive branch and opens a superseding PR; nothing is merged as-is. It is greyed with the reason on a person's PR. Renderer test: `TestStageTrackerReauthorAndApprovalCaveats`. |
| PR at 085 *Needs human decision* | Let hive decide · Approve · Give direction · Close as superseded · Close as won't fix · Hold (unchanged). |
| Issue at 045 *Needs decision* (direction) | Let hive decide · Give direction · Approve direction · Send back to the hive · Hold (unchanged). |
| Human-authored PR at 071 *Needs author* / 072 *Returned to contributor* | Let hive decide · Close as superseded · Close as won't fix · Hold — the hive never rewrites a person's PR, so the choice is wait or close. (A hive-authored PR there carries *Adopt now* when adoption applies.) |
Expand Down
27 changes: 26 additions & 1 deletion src/docs/operator-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,32 @@ verified owner or an authorized user with the `merger` role:
| `merge-now` — *Approve & merge as maintainer* | Comments on the PR that @you merged it from the dashboard, then merges it at once through the hive's GitHub App (`MergePRVia`, audit path `dashboard`). Refused when the PR is merged or closed, or when you are its author. | `repo_item_decision_merge`; `last_operator_action.action: merge-now`; toast *merged*. |
| `queue-merge` — *Approve — let hive merge* | Leaves an `APPROVED` review in your name with a note, adds the automerge label, and leaves the merge to the App self-merge sweep, which merges on its next pass once CI is green and the head has soaked. Refused on your own PR. | `repo_item_decision_queue_merge`; `last_operator_action.action: queue-merge`; toast *queued for merge*. |

Neither widens who the lanes trust: to stop a contributor's PRs parking at 090
**Approve is the trust override for that head
([#15136](https://github.com/hivecommons/hive/issues/15136)).** Before, an
owner's Approve on an untrusted-author PR was reduced to the `/lgtm` +
`/approve` comments and the contributor lane's claim-tier rule then
adopt-superseded the PR the owner had just approved. Now every Approve
variant — `approve`, `queue-merge`, `merge-now` — writes
`admitted_by: operator-approval:<login>` (with `admitted_head`,
`admitted_at`) on the PR's stage record before touching GitHub, and the
response and audit detail carry `admitted_by`. While that admission stands
for the head: the contributor lane admits the author for that head
(`contributor-lane:operator-approval`; the merge comment names who
admitted it), **no adoption or supersede is permitted** — a due adoption
records `adopt_blocked_by: operator-admission` and the row reads *not
adopted: a maintainer approved this head; the hive merges it as-is* — and
the hive merges as-is after checks and soak (or at once for `merge-now`).
A new push drops the admission and the row asks again. A
`/hive decision approve` comment by a trusted merger is the same admission;
the engine derives it from the recorded approval and writes it back. An
explicit **Adopt** / **Re-author** from the dashboard is the person choosing
re-authoring and is not refused.

| Decision | What it does | Audit / ledger |
|---|---|---|
| `re-author` — *Re-author as hive PR* | Offered as its own lead action on a 090 PR whose head cannot merge as-is — the stage record's commit check counted commits without a `Signed-off-by` (`dco_unsigned` / `dco_total` on the row). The popover and both Approve confirms say so **before** acting (*2 of 3 commits have no Signed-off-by, so a required DCO check refuses the merge*); approving never re-authors by itself. Re-author posts its own note and the `adoption/supersede` request label; the hive re-homes the commits on a hive-owned, signed-off branch and opens a superseding PR. Disabled with the reason on a person's PR (the hive does not re-author a human's PR — ask them to `git commit -s --amend`). | `repo_item_decision_adopt` with `decision=re-author`; `last_operator_action.action: re-author`; toast *adopted*. |

Neither merge action widens who the lanes trust: to stop a contributor's PRs parking at 090
give them the `trusted` / `merger` tier under 👥 Contributors
(`auto_merge.contributor_lane.require_tiers`), add them as a repository
collaborator, or list them under `dashboard.authorized_users` with the
Expand Down
84 changes: 73 additions & 11 deletions src/pkg/dashboard/api_repo_item_decision.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package dashboard

import (
Expand All @@ -8,11 +8,13 @@
"net/http"
"strconv"
"strings"
"time"

"github.com/hivecommons/hive/pkg/config"
"github.com/hivecommons/hive/pkg/delegatedecision"
ghpkg "github.com/hivecommons/hive/pkg/github"
"github.com/hivecommons/hive/pkg/review"
"github.com/hivecommons/hive/pkg/stagelabels"
)

// Activity-monitor row decisions (hivecommons/hive#13479 follow-up). The
Expand Down Expand Up @@ -67,6 +69,12 @@
// tick once CI is green (soak and the self-merge ban still apply).
repoItemDecisionMergeNow = "merge-now"
repoItemDecisionQueueMerge = "queue-merge"
// re-author is the operator's explicit choice, offered on a 090 PR
// whose head cannot merge as-is (unsigned commits → DCO), to have the
// hive re-home the commits on a hive-owned branch and open a
// superseding PR (hivecommons/hive#15136). It queues the same adoption
// the Adopt decision does; it is never implied by an Approve.
repoItemDecisionReauthor = "re-author"

repoItemDecisionMaxBody = 16 << 10
repoItemDecisionMaxComment = 4000
Expand Down Expand Up @@ -156,6 +164,29 @@
Result *RowActionResult `json:"result,omitempty"`
// Head is the PR head an approve / direction was recorded against.
Head string `json:"head,omitempty"`
// AdmittedBy is the trust override an Approve (either variant) wrote
// on the stage record for Head — "operator-approval:<login>" — so the
// contributor lane merges the head as-is and the adoption engine
// leaves the PR alone (hivecommons/hive#15136).
AdmittedBy string `json:"admitted_by,omitempty"`
}

// admitPullRequestHead records user's Approve as the trust override for
// head on the stage record (hivecommons/hive#15136) and returns the
// admitted_by value written ("" when there is no record to write to —
// the lane then derives the same admission from the recorded approval).
func (s *Server) admitPullRequestHead(repoFull string, number int, head, user string) string {
by := stagelabels.OperatorApprovalAdmission(user)
if strings.TrimSpace(head) == "" || by == "" {
return ""
}
store := s.stageStoreOrShared()
key := stagelabels.Key(repoFull, number)
store.NoteAdmission(key, head, by, time.Now())
if rec, ok := store.Get(key); ok && rec.Admission(head) == by {
return by
}
return ""
}

// repoItemDecisionResult reads a recorded human decision into the shared
Expand Down Expand Up @@ -200,6 +231,10 @@
out.Action = rowActionAdopted
out.Outcome = "Adoption queued: `" + label + "` applied."
out.Next = "The hive opens its own PR carrying the author's commits and sign-off on its next cycle; the original is closed as superseded."
case repoItemDecisionReauthor:
out.Action = rowActionAdopted
out.Outcome = "Re-authoring queued: `" + label + "` applied."
out.Next = "The hive re-homes the commits on a hive-owned, signed-off branch and opens a superseding PR on its next cycle; this PR is closed when that one merges. Nothing is merged as-is."
case repoItemDecisionMergeNow:
out.Action = rowActionMerged
out.Outcome = "Merged into `" + label + "` now via hive's identity, attributed to you."
Expand Down Expand Up @@ -347,16 +382,20 @@
s.audit.LogRecord(user, auditRepoItemDecisionClose, auditDetail("repo", repoFull, "number", numStr, "type", itemType, "reason", verb, "superseded_by", supersededBy), "", repoFull, number)
jsonResponse(w, repoItemDecisionResponse{OK: true, Repo: repoFull, Number: number, Decision: decision, Status: "closed", Label: label,
Result: repoItemDecisionResult(repoFull, number, itemType, decision, comment, supersededBy, label, nil)})
case repoItemDecisionAdopt:
case repoItemDecisionAdopt, repoItemDecisionReauthor:
if itemType != "pr" {
jsonError(w, "adopt applies to pull requests", http.StatusBadRequest)
jsonError(w, decision+" applies to pull requests", http.StatusBadRequest)
return
}
if !s.stageAdoptionEnabled() {
jsonError(w, "adoption requires governor.labels.stage.adoption to be enabled on this hive", http.StatusConflict)
return
}
if err := gh.CreateIssueComment(ctx, repoFull, number, renderRepoItemDecisionAdoptComment(user, comment)); err != nil {
note := renderRepoItemDecisionAdoptComment(user, comment)
if decision == repoItemDecisionReauthor {
note = renderRepoItemDecisionReauthorComment(user, comment)
}
if err := gh.CreateIssueComment(ctx, repoFull, number, note); err != nil {
jsonError(w, "posting adoption note: "+err.Error(), http.StatusBadGateway)
return
}
Expand All @@ -368,7 +407,7 @@
jsonError(w, "queuing adoption: "+err.Error(), http.StatusBadGateway)
return
}
s.audit.LogRecord(user, auditRepoItemDecisionAdopt, auditDetail("repo", repoFull, "number", numStr, "type", itemType, "label", delegatedecision.LabelAdoptSupersede), "", repoFull, number)
s.audit.LogRecord(user, auditRepoItemDecisionAdopt, auditDetail("repo", repoFull, "number", numStr, "type", itemType, "label", delegatedecision.LabelAdoptSupersede, "decision", decision), "", repoFull, number)
jsonResponse(w, repoItemDecisionResponse{OK: true, Repo: repoFull, Number: number, Decision: decision, Status: "adoption-queued", Label: delegatedecision.LabelAdoptSupersede,
Result: repoItemDecisionResult(repoFull, number, itemType, decision, comment, "", delegatedecision.LabelAdoptSupersede, nil)})
case repoItemDecisionMergeNow, repoItemDecisionQueueMerge:
Expand All @@ -382,7 +421,7 @@
}
s.handlePullRequestMergeDecision(ctx, w, repoFull, number, user, decision, comment)
default:
jsonError(w, "unknown decision; want approve, direction, close-superseded, close-wontfix, adopt, merge-now or queue-merge", http.StatusBadRequest)
jsonError(w, "unknown decision; want approve, direction, close-superseded, close-wontfix, adopt, re-author, merge-now or queue-merge", http.StatusBadRequest)
}
}

Expand Down Expand Up @@ -428,15 +467,19 @@
if base == "" {
base = "the base branch"
}
// Either variant is the person's trust override for this head: written
// before the GitHub call so the adoption engine cannot take the PR over
// between the approval landing and the merge (hivecommons/hive#15136).
admitted := s.admitPullRequestHead(repoFull, number, state.HeadSHA, user)
if decision == repoItemDecisionQueueMerge {
if err := gh.QueuePRAutoMergeWithNote(ctx, repoFull, number, user, renderRepoItemDecisionQueueNote(user, comment)); err != nil {
jsonError(w, err.Error(), http.StatusBadGateway)
return
}
label := gh.AutoMergeLabel()
s.audit.LogRecord(user, auditRepoItemDecisionQueue, auditDetail("repo", repoFull, "number", numStr, "type", "pr", "head", state.HeadSHA, "author", author, "label", label), "", repoFull, number)
s.audit.LogRecord(user, auditRepoItemDecisionQueue, auditDetail("repo", repoFull, "number", numStr, "type", "pr", "head", state.HeadSHA, "author", author, "label", label, "admitted_by", admitted), "", repoFull, number)
s.invalidateStageTrackerForWebhook()
jsonResponse(w, repoItemDecisionResponse{OK: true, Repo: repoFull, Number: number, Decision: decision, Status: "queued-for-merge", Label: label, Head: state.HeadSHA,
jsonResponse(w, repoItemDecisionResponse{OK: true, Repo: repoFull, Number: number, Decision: decision, Status: "queued-for-merge", Label: label, Head: state.HeadSHA, AdmittedBy: admitted,
Result: repoItemDecisionResult(repoFull, number, "pr", decision, comment, "", label, nil)})
return
}
Expand All @@ -455,9 +498,9 @@
jsonError(w, "GitHub did not merge the pull request: "+strings.TrimSpace(res.Message), http.StatusConflict)
return
}
s.audit.LogRecord(user, auditRepoItemDecisionMerge, auditDetail("repo", repoFull, "number", numStr, "type", "pr", "head", state.HeadSHA, "author", author, "base", state.BaseRef, "sha", res.SHA), "", repoFull, number)
s.audit.LogRecord(user, auditRepoItemDecisionMerge, auditDetail("repo", repoFull, "number", numStr, "type", "pr", "head", state.HeadSHA, "author", author, "base", state.BaseRef, "sha", res.SHA, "admitted_by", admitted), "", repoFull, number)
s.invalidateStageTrackerForWebhook()
jsonResponse(w, repoItemDecisionResponse{OK: true, Repo: repoFull, Number: number, Decision: decision, Status: "merged", Head: state.HeadSHA,
jsonResponse(w, repoItemDecisionResponse{OK: true, Repo: repoFull, Number: number, Decision: decision, Status: "merged", Head: state.HeadSHA, AdmittedBy: admitted,
Result: repoItemDecisionResult(repoFull, number, "pr", decision, comment, "", base, nil)})
}

Expand Down Expand Up @@ -491,6 +534,17 @@
return body
}

// renderRepoItemDecisionReauthorComment is the attributed note a
// Re-author decision leaves on the PR before the adoption request label is
// applied (hivecommons/hive#15136).
func renderRepoItemDecisionReauthorComment(user, comment string) string {
body := fmt.Sprintf("%s by=%s -->\n@%s asked the hive to re-author this pull request as a hive PR: its head cannot merge as-is (commits without a Signed-off-by), so the hive re-homes the commits on a hive-owned, signed-off branch and opens a superseding PR; this one is closed when that merges. The author's commits are preserved and attributed.", repoItemDecisionAdoptMarker, user, user)
if c := strings.TrimSpace(comment); c != "" {
body += "\n\n> " + strings.ReplaceAll(c, "\n", "\n> ")
}
return body
}

// handlePullRequestDecision answers approve / direction on a pull request.
func (s *Server) handlePullRequestDecision(ctx context.Context, w http.ResponseWriter, repoFull string, number int, user, decision, comment string) {
gh := s.deps.GHClient
Expand Down Expand Up @@ -533,14 +587,22 @@
return
}
action, status := auditRepoItemDecisionApprove, "approval-commented"
admitted := ""
if decision == repoItemDecisionDirection {
action, status = auditRepoItemDecisionDirection, "direction-recorded"
} else {
// The person's Approve is the trust override for this head: the
// contributor lane merges it as-is and the adoption engine leaves
// it alone while the admission stands (hivecommons/hive#15136).
if admitted = s.admitPullRequestHead(repoFull, number, head, user); admitted != "" {
released = append(released, "admitted")
}
}
s.audit.LogRecord(user, action, auditDetail("repo", repoFull, "number", numStr, "type", "pr", "head", head, "decision", comment, "released", strings.Join(released, ","), "stage", stage), "", repoFull, number)
s.audit.LogRecord(user, action, auditDetail("repo", repoFull, "number", numStr, "type", "pr", "head", head, "decision", comment, "released", strings.Join(released, ","), "stage", stage, "admitted_by", admitted), "", repoFull, number)
// The row's park was just answered: serve the re-derived stage on the
// next tracker read instead of the cached 085.
s.invalidateStageTrackerForWebhook()
jsonResponse(w, repoItemDecisionResponse{OK: true, Repo: repoFull, Number: number, Decision: decision, Status: status, Released: released, Stage: stage, Head: head,
jsonResponse(w, repoItemDecisionResponse{OK: true, Repo: repoFull, Number: number, Decision: decision, Status: status, Released: released, Stage: stage, Head: head, AdmittedBy: admitted,
Result: repoItemDecisionResult(repoFull, number, "pr", decision, comment, "", "", released)})
}

Expand Down
Loading
Loading