From 0268a93640709b4299be85eed2684e574e630371 Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Mon, 13 Oct 2025 15:36:40 +0100 Subject: [PATCH] appview/pulls: fix stacked resubmits using the wrong source-sha Change-Id: yzlvxoyxmuypulqwrmxrkrwsxnszvmzo the SHA stored on the sh.tangled.repo.pull record was incorrect, causing spindles to report the wrong SHA in pipeline statuses. Signed-off-by: oppiliappan --- appview/db/pulls.go | 5 ++--- appview/models/pull.go | 21 ++++++--------------- appview/pulls/pulls.go | 25 +++++++++++++++---------- 3 files changed, 23 insertions(+), 28 deletions(-) diff --git a/appview/db/pulls.go b/appview/db/pulls.go index cacb6c42..8ea2db64 100644 --- a/appview/db/pulls.go +++ b/appview/db/pulls.go @@ -590,12 +590,11 @@ func DeletePull(e Execer, repoAt syntax.ATURI, pullId int) error { return err } -func ResubmitPull(e Execer, pull *models.Pull, newPatch, sourceRev string) error { - newRoundNumber := len(pull.Submissions) +func ResubmitPull(e Execer, pullAt syntax.ATURI, newRoundNumber int, newPatch string, newSourceRev string) error { _, err := e.Exec(` insert into pull_submissions (pull_at, round_number, patch, source_rev) values (?, ?, ?, ?) - `, pull.PullAt(), newRoundNumber, newPatch, sourceRev) + `, pullAt, newRoundNumber, newPatch, newSourceRev) return err } diff --git a/appview/models/pull.go b/appview/models/pull.go index 3902e100..7ae16bcd 100644 --- a/appview/models/pull.go +++ b/appview/models/pull.go @@ -84,9 +84,13 @@ type Pull struct { func (p Pull) AsRecord() tangled.RepoPull { var source *tangled.RepoPull_Source if p.PullSource != nil { - s := p.PullSource.AsRecord() - source = &s + source = &tangled.RepoPull_Source{} + source.Branch = p.PullSource.Branch source.Sha = p.LatestSha() + if p.PullSource.RepoAt != nil { + s := p.PullSource.Repo.RepoAt().String() + source.Repo = &s + } } record := tangled.RepoPull{ @@ -111,19 +115,6 @@ type PullSource struct { Repo *Repo } -func (p PullSource) AsRecord() tangled.RepoPull_Source { - var repoAt *string - if p.RepoAt != nil { - s := p.RepoAt.String() - repoAt = &s - } - record := tangled.RepoPull_Source{ - Branch: p.Branch, - Repo: repoAt, - } - return record -} - type PullSubmission struct { // ids ID int diff --git a/appview/pulls/pulls.go b/appview/pulls/pulls.go index 02a0d4ed..568ba305 100644 --- a/appview/pulls/pulls.go +++ b/appview/pulls/pulls.go @@ -415,11 +415,11 @@ func (s *Pulls) resubmitCheck(r *http.Request, f *reporesolver.ResolvedRepo, pul targetBranch := branchResp - latestSourceRev := pull.Submissions[pull.LastRoundNumber()].SourceRev + latestSourceRev := pull.LatestSha() if pull.IsStacked() && stack != nil { top := stack[0] - latestSourceRev = top.Submissions[top.LastRoundNumber()].SourceRev + latestSourceRev = top.LatestSha() } if latestSourceRev != targetBranch.Hash { @@ -1811,7 +1811,7 @@ func (s *Pulls) resubmitPullHelper( // validate sourceRev if branch/fork based if pull.IsBranchBased() || pull.IsForkBased() { - if sourceRev == pull.Submissions[pull.LastRoundNumber()].SourceRev { + if sourceRev == pull.LatestSha() { s.pages.Notice(w, "resubmit-error", "This branch has not changed since the last submission.") return } @@ -1825,7 +1825,11 @@ func (s *Pulls) resubmitPullHelper( } defer tx.Rollback() - err = db.ResubmitPull(tx, pull, patch, sourceRev) + pullAt := pull.PullAt() + newRoundNumber := len(pull.Submissions) + newPatch := patch + newSourceRev := sourceRev + err = db.ResubmitPull(tx, pullAt, newRoundNumber, newPatch, newSourceRev) if err != nil { log.Println("failed to create pull request", err) s.pages.Notice(w, "resubmit-error", "Failed to create pull request. Try again later.") @@ -2016,10 +2020,12 @@ func (s *Pulls) resubmitStackedPullHelper( continue } - submission := np.Submissions[np.LastRoundNumber()] - - // resubmit the old pull - err := db.ResubmitPull(tx, op, submission.Patch, submission.SourceRev) + // resubmit the new pull + pullAt := op.PullAt() + newRoundNumber := len(op.Submissions) + newPatch := np.LatestPatch() + newSourceRev := np.LatestSha() + err := db.ResubmitPull(tx, pullAt, newRoundNumber, newPatch, newSourceRev) if err != nil { log.Println("failed to update pull", err, op.PullId) @@ -2027,8 +2033,7 @@ func (s *Pulls) resubmitStackedPullHelper( return } - record := op.AsRecord() - record.Patch = submission.Patch + record := np.AsRecord() writes = append(writes, &comatproto.RepoApplyWrites_Input_Writes_Elem{ RepoApplyWrites_Update: &comatproto.RepoApplyWrites_Update{ -- 2.43.0