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-adopt-now-takes-over-any-author.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- An operator's Adopt now takes over any PR, a hive owner's or maintainer's included: the stage engine honours the forced adoption instead of refusing it as person-authored on every sweep, which left the row at "adopting… (queued)" forever. The hive still never adopts a person's own PR on its own initiative; the audit names the author taken over from.
5 changes: 4 additions & 1 deletion src/pkg/dashboard/api_repo_item_decision_reroute.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ func (s *Server) handleRepoItemAdoptNow(ctx context.Context, w http.ResponseWrit
jsonError(w, "queuing forced adoption: "+err.Error(), http.StatusBadGateway)
return
}
s.audit.LogRecord(user, auditRepoItemDecisionAdoptNow, auditDetail("repo", repoFull, "number", strconv.Itoa(number), "type", "pr", "action", repoItemDecisionAdoptNowAction, "label", delegatedecision.LabelAdoptSupersede), "", repoFull, number)
// The audit names whose PR was taken over: an operator may force the
// adoption of anyone's PR, a hive owner's included, and that choice
// stays attributable.
s.audit.LogRecord(user, auditRepoItemDecisionAdoptNow, auditDetail("repo", repoFull, "number", strconv.Itoa(number), "type", "pr", "action", repoItemDecisionAdoptNowAction, "label", delegatedecision.LabelAdoptSupersede, "author", facts.Author, "author_owner", strconv.FormatBool(s.isAuthorizedUserLogin(facts.Author))), "", repoFull, number)
superseding := s.nudgeSweepAndAwaitAdoption(ctx, store, key, repoFull, number)
jsonResponse(w, repoItemAdoptNowResponse(repoFull, number, superseding))
}
Expand Down
27 changes: 27 additions & 0 deletions src/pkg/dashboard/api_repo_item_takeover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,33 @@ func TestRepoItemAdoptNowGuards(t *testing.T) {
}
}

// An operator may take over anyone's PR, a hive owner's included: Adopt now
// on an owner-authored PR records the forced mark and the audit names the
// author as an owner.
func TestRepoItemAdoptNowOnOwnerAuthoredPR(t *testing.T) {
srv, store := takeoverServer(t, &repoItemDecisionMock{prForeign: true})
srv.deps.Config.Dashboard.AuthorizedUsers = []string{"someone:owner"}
w := postRepoItemDecision(t, srv, 8, "writer", `{"decision":"adopt","force":true,"type":"pr"}`)
if w.Code != http.StatusOK {
t.Fatalf("owner-authored: code=%d body=%s", w.Code, w.Body.String())
}
if rec, _ := store.Get(stagelabels.Key("testorg/testrepo", 8)); !recForced(rec) {
t.Fatalf("forced mark not recorded for an owner's PR: %+v", rec)
}
found := false
for _, e := range srv.GetAudit().Recent(20) {
if e.Action == auditRepoItemDecisionAdoptNow {
found = true
if !strings.Contains(e.Detail, "author=someone") || !strings.Contains(e.Detail, "author_owner=true") {
t.Fatalf("audit detail %q lacks the owner attribution", e.Detail)
}
}
}
if !found {
t.Fatalf("audit = %v", decisionAuditActions(srv))
}
}

func TestRepoItemRerouteNoneOnlineIsConflict(t *testing.T) {
srv, _ := takeoverServer(t, &repoItemDecisionMock{prForeign: true})
w := postRepoItemDecision(t, srv, 8, "writer", `{"decision":"reroute","to":"any","type":"pr"}`)
Expand Down
46 changes: 46 additions & 0 deletions src/pkg/github/automerge/automerge_adopt_now_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,49 @@ func TestAdoptNowOfflineWordingAndHoldStops(t *testing.T) {
t.Fatalf("offline wording: %s", comments[0])
}
}

// An operator may take over anyone's PR, a hive owner's included: the
// person-authored rule (hivecommons/hive#15202) holds for the hive's own
// initiative and for an adoption/supersede request, but an explicit Adopt
// now adopts, consumes the forced mark and leaves no "queued" behind.
func TestAdoptNowTakesOverOwnerAuthoredPR(t *testing.T) {
policy := adoptPolicy()
policy.OwnerAuthor = func(login string) bool { return login == "mallory" }
h, done := newAdoptHarness(t, ContributorNudgeOutcome{Mode: "comment"}, policy)
defer done()
h.sink.presence = &ContributorPresence{Registered: true, Online: false}
h.observe(adoptPR(7, "aaa"), "check-failing:unit")
key := stageKey("acme", "widget", 7)
store := h.e.stageStoreOrShared()
labels := []string{"stage/072-returned-to-contributor", "role/contributor", "author/clanker"}

// Control: the request label alone is refused for an owner's PR.
h.api.reset()
h.clock.advance(time.Minute)
h.observe(adoptPR(7, "aaa", append(labels, "adoption/supersede")...), "check-failing:unit")
if len(h.adopt.pulls) != 0 {
t.Fatalf("request adopted an owner's PR: pulls=%v", h.adopt.pulls)
}
if rec, _ := store.Get(key); rec.AdoptionBlocked("aaa") != "author-is-person" {
t.Fatalf("refusal not recorded: %+v", rec)
}

store.NoteAdoptionForced(key, "clubanderson", h.clock.now())
h.api.reset()
h.clock.advance(time.Minute)
h.observe(adoptPR(7, "aaa", append(labels, "adoption/supersede")...), "check-failing:unit")
if len(h.adopt.pulls) != 1 {
t.Fatalf("Adopt now did not supersede an owner's PR: pulls=%v added=%v", h.adopt.pulls, h.api.added)
}
comments := adoptionComments(h.api)
if len(comments) != 1 || !strings.Contains(comments[0], "by=@clubanderson reason=operator-forced") {
t.Fatalf("adoption comments = %v", h.api.comments)
}
rec, _ := store.Get(key)
if rec.AdoptedHead != "aaa" || rec.AdoptedBy != 90 || rec.AdoptReason != AdoptReasonOperatorForced {
t.Fatalf("record after Adopt now: %+v", rec)
}
if _, forced := rec.AdoptionForced(); forced || rec.AdoptionBlocked("aaa") != "" {
t.Fatalf("forced mark or person block survived the adoption: %+v", rec)
}
}
19 changes: 14 additions & 5 deletions src/pkg/github/automerge/automerge_contributor_adopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,16 +644,23 @@ func (c *Engine) adoptContributorPR(ctx context.Context, store *stagelabels.Stor
c.info("stage labels: adoption due but blocked by label", "repo", obs.Display, "pr", obs.Number, "label", l)
return 0, nil
}
if personAuthored(obs, policy) {
person := personAuthored(obs, policy)
if person && !forced {
// A person's own PR (hivecommons/hive#15202): no contributor hive
// can be offline for it, and neither an operator request nor a
// forced adoption changes who should fix it. Recorded so the
// tracker row says why.
// can be offline for it, and an operator's adoption request does
// not change who should fix it. Recorded so the tracker row says
// why. Only an explicit Adopt now (forced) takes it over.
store.NoteAdoptionBlocked(key, obs.HeadSHA, stagelabels.AdoptBlockedAuthorPerson, now)
c.info("stage labels: adoption refused, a person pushed this PR themselves; asking the author instead", "repo", obs.Display, "pr", obs.Number, "author", obs.Author, "head", obs.HeadSHA, "author_kind", obs.AuthorKind.String(), "reason", reason, "requested", requested, "forced", forced)
return 0, nil
}
if forced {
if person {
// An operator may take over anyone's PR, owners and
// maintainers included: the click is the decision, logged
// with the actor so the takeover stays attributable.
c.info("stage labels: operator-forced adoption over a person-authored PR", "repo", obs.Display, "pr", obs.Number, "author", obs.Author, "author_kind", obs.AuthorKind.String(), "head", obs.HeadSHA, "by", forcedBy)
}
c.info("stage labels: operator forced adoption; maintainer policy, admission and presence bypassed", "repo", obs.Display, "pr", obs.Number, "author", obs.Author, "by", forcedBy, "online", presence.Online, "policy", policy.maintainerPolicy())
} else if c.adoptionRefusedByAdmission(ctx, store, key, obs, requested, now) {
return 0, nil
Expand Down Expand Up @@ -1559,7 +1566,9 @@ func (c *Engine) authorMaintainsRepo(ctx context.Context, obs stageObservation,

// personAuthored: the PR was pushed by a person — author/human, or one of
// this hive's owners — rather than by a clanker or a registered contributor
// relay. Such a PR is never adopted (hivecommons/hive#15202).
// relay. Such a PR is never adopted on the hive's own initiative
// (hivecommons/hive#15202); only an operator's explicit Adopt now takes it
// over.
func personAuthored(obs stageObservation, policy StageLabelPolicy) bool {
if obs.AuthorKind == authorkind.Human {
return true
Expand Down
Loading