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-15225.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Re-adopting a pull request after the hive closed its earlier copy now merges the base branch into the new copy again, so the fresh copy no longer opens with the conflict the first adoption had resolved ([#15225](https://github.com/hivecommons/hive/issues/15225)).
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,27 @@ func TestAdoptionReadoptAfterClosedCopyIsNotJournalReplayed(t *testing.T) {
// The journal replays the PR-create claim and hands back a copy that is
// closed: the adoption claims a fresh copy rather than reading the replay
// as a failure and clearing the adoption.
func TestAdoptionReadoptReplaysBaseMergeKeyedByPriorCopy(t *testing.T) {
h, jb, done, adopted := adoptAt074Journaled(t)
defer done()
h.adopt.setSuperseder(90, "closed", false)
h.api.reset()
h.clock.advance(adoptCheckInterval)
h.observe(adoptPR(7, "aaa", append(adopted, "needs-rebase")...), "check-failing:unit")
var replay effects.Claim
for _, c := range jb.claims {
if c.Kind == effects.KindBranchPush && c.Inputs["reason"] == "supersede-replay" {
replay = c
}
}
if got := replay.Inputs["prior_copy"]; got != "90" {
t.Fatalf("supersede-replay claim prior_copy = %q, want 90 (claims %v)", got, jb.claims)
}
if len(h.adopt.merges) != 1 || h.adopt.merges[0] != "hive/adopt-7<-v5" {
t.Fatalf("base not merged on re-adoption: %v", h.adopt.merges)
}
}

func TestAdoptionJournalReplayOfClosedCopyOpensFreshCopy(t *testing.T) {
h, jb, done, adopted := adoptAt074Journaled(t)
defer done()
Expand Down
22 changes: 13 additions & 9 deletions src/pkg/github/automerge/automerge_contributor_adopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -807,12 +807,7 @@ func (c *Engine) supersedeAdoptedPR(ctx context.Context, store *stagelabels.Stor
if stored, ok := store.Get(key); ok && stored.AdoptedBy > 0 && stored.AdoptOrphanedBy == stored.AdoptedBy {
priorCopy = stored.AdoptedBy
}
claimInputs := func(prior int, inputs map[string]string) map[string]string {
if prior > 0 {
inputs["prior_copy"] = strconv.Itoa(prior)
}
return inputs
}
claimInputs := priorCopyInputs
// resignedTip stays "" when the branch falls back to the unsigned
// contributor head; the body then keeps the manual DCO repair steps.
var resignedTip string
Expand Down Expand Up @@ -860,7 +855,7 @@ func (c *Engine) supersedeAdoptedPR(ctx context.Context, store *stagelabels.Stor
// The head is red on a conflict: opening the copy as-is would just
// move the conflict. Replay the base onto the hive branch first; a
// git conflict is terminal for this head (one note, 07x reason).
conflicted, n, err := c.replaySupersedeOntoBase(ctx, store, key, obs, branch, now)
conflicted, n, err := c.replaySupersedeOntoBase(ctx, store, key, obs, branch, priorCopy, now)
if err != nil || conflicted {
return n, err
}
Expand Down Expand Up @@ -976,12 +971,12 @@ func AdoptionSupersedeConflictComment(obs stageObservation, branch string, files
// recorded as supersede-conflict so the request is consumed and the 07x
// reason names it, and one note is posted. Other API failures return the
// error with the attempt already recorded by the caller.
func (c *Engine) replaySupersedeOntoBase(ctx context.Context, store *stagelabels.Store, key string, obs stageObservation, branch string, now time.Time) (conflicted bool, comments int, err error) {
func (c *Engine) replaySupersedeOntoBase(ctx context.Context, store *stagelabels.Store, key string, obs stageObservation, branch string, priorCopy int, now time.Time) (conflicted bool, comments int, err error) {
owner, repo, number := obs.Owner, obs.Repo, obs.Number
var status int
_, err = effects.Execute(ctx, c.mutation, effects.Claim{
Repo: owner + "/" + repo, Kind: effects.KindBranchPush, Target: branch, Actor: "stage_labels",
Inputs: map[string]string{"pr": strconv.Itoa(number), "head_sha": obs.HeadSHA, "base": obs.BaseRef, "reason": "supersede-replay"},
Inputs: priorCopyInputs(priorCopy, map[string]string{"pr": strconv.Itoa(number), "head_sha": obs.HeadSHA, "base": obs.BaseRef, "reason": "supersede-replay"}),
}, func(ctx context.Context) (effects.Result, error) {
commit, resp, apiErr := c.gh.Repositories.Merge(ctx, owner, repo, &gh.RepositoryMergeRequest{
Base: gh.Ptr(branch),
Expand Down Expand Up @@ -1018,6 +1013,15 @@ func (c *Engine) replaySupersedeOntoBase(ctx context.Context, store *stagelabels
return true, 1, nil
}

// priorCopyInputs keys a claim by the closed copy it follows, so a
// re-adoption is not answered by the first adoption's journal entry.
func priorCopyInputs(prior int, inputs map[string]string) map[string]string {
if prior > 0 {
inputs["prior_copy"] = strconv.Itoa(prior)
}
return inputs
}

// adoptionReplayedPRNumber reads the PR number from a pull_request_create
// provenance URL (…/pull/N); 0 when there is none.
func adoptionReplayedPRNumber(provenance string) int {
Expand Down
Loading