appview/pulls: fix stacked resubmits using the wrong source-sha #664

merged
opened by oppi.li targeting master from push-yzlvxoyxmuyp

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 me@oppi.li

Changed files
+23 -28
appview
db
models
pulls
+2 -3
appview/db/pulls.go
··· 590 return err 591 } 592 593 - func ResubmitPull(e Execer, pull *models.Pull, newPatch, sourceRev string) error { 594 - newRoundNumber := len(pull.Submissions) 595 _, err := e.Exec(` 596 insert into pull_submissions (pull_at, round_number, patch, source_rev) 597 values (?, ?, ?, ?) 598 - `, pull.PullAt(), newRoundNumber, newPatch, sourceRev) 599 600 return err 601 }
··· 590 return err 591 } 592 593 + func ResubmitPull(e Execer, pullAt syntax.ATURI, newRoundNumber int, newPatch string, newSourceRev string) error { 594 _, err := e.Exec(` 595 insert into pull_submissions (pull_at, round_number, patch, source_rev) 596 values (?, ?, ?, ?) 597 + `, pullAt, newRoundNumber, newPatch, newSourceRev) 598 599 return err 600 }
+6 -15
appview/models/pull.go
··· 84 func (p Pull) AsRecord() tangled.RepoPull { 85 var source *tangled.RepoPull_Source 86 if p.PullSource != nil { 87 - s := p.PullSource.AsRecord() 88 - source = &s 89 source.Sha = p.LatestSha() 90 } 91 92 record := tangled.RepoPull{ ··· 111 Repo *Repo 112 } 113 114 - func (p PullSource) AsRecord() tangled.RepoPull_Source { 115 - var repoAt *string 116 - if p.RepoAt != nil { 117 - s := p.RepoAt.String() 118 - repoAt = &s 119 - } 120 - record := tangled.RepoPull_Source{ 121 - Branch: p.Branch, 122 - Repo: repoAt, 123 - } 124 - return record 125 - } 126 - 127 type PullSubmission struct { 128 // ids 129 ID int
··· 84 func (p Pull) AsRecord() tangled.RepoPull { 85 var source *tangled.RepoPull_Source 86 if p.PullSource != nil { 87 + source = &tangled.RepoPull_Source{} 88 + source.Branch = p.PullSource.Branch 89 source.Sha = p.LatestSha() 90 + if p.PullSource.RepoAt != nil { 91 + s := p.PullSource.Repo.RepoAt().String() 92 + source.Repo = &s 93 + } 94 } 95 96 record := tangled.RepoPull{ ··· 115 Repo *Repo 116 } 117 118 type PullSubmission struct { 119 // ids 120 ID int
+15 -10
appview/pulls/pulls.go
··· 415 416 targetBranch := branchResp 417 418 - latestSourceRev := pull.Submissions[pull.LastRoundNumber()].SourceRev 419 420 if pull.IsStacked() && stack != nil { 421 top := stack[0] 422 - latestSourceRev = top.Submissions[top.LastRoundNumber()].SourceRev 423 } 424 425 if latestSourceRev != targetBranch.Hash { ··· 1811 1812 // validate sourceRev if branch/fork based 1813 if pull.IsBranchBased() || pull.IsForkBased() { 1814 - if sourceRev == pull.Submissions[pull.LastRoundNumber()].SourceRev { 1815 s.pages.Notice(w, "resubmit-error", "This branch has not changed since the last submission.") 1816 return 1817 } ··· 1825 } 1826 defer tx.Rollback() 1827 1828 - err = db.ResubmitPull(tx, pull, patch, sourceRev) 1829 if err != nil { 1830 log.Println("failed to create pull request", err) 1831 s.pages.Notice(w, "resubmit-error", "Failed to create pull request. Try again later.") ··· 2016 continue 2017 } 2018 2019 - submission := np.Submissions[np.LastRoundNumber()] 2020 - 2021 - // resubmit the old pull 2022 - err := db.ResubmitPull(tx, op, submission.Patch, submission.SourceRev) 2023 2024 if err != nil { 2025 log.Println("failed to update pull", err, op.PullId) ··· 2027 return 2028 } 2029 2030 - record := op.AsRecord() 2031 - record.Patch = submission.Patch 2032 2033 writes = append(writes, &comatproto.RepoApplyWrites_Input_Writes_Elem{ 2034 RepoApplyWrites_Update: &comatproto.RepoApplyWrites_Update{
··· 415 416 targetBranch := branchResp 417 418 + latestSourceRev := pull.LatestSha() 419 420 if pull.IsStacked() && stack != nil { 421 top := stack[0] 422 + latestSourceRev = top.LatestSha() 423 } 424 425 if latestSourceRev != targetBranch.Hash { ··· 1811 1812 // validate sourceRev if branch/fork based 1813 if pull.IsBranchBased() || pull.IsForkBased() { 1814 + if sourceRev == pull.LatestSha() { 1815 s.pages.Notice(w, "resubmit-error", "This branch has not changed since the last submission.") 1816 return 1817 } ··· 1825 } 1826 defer tx.Rollback() 1827 1828 + pullAt := pull.PullAt() 1829 + newRoundNumber := len(pull.Submissions) 1830 + newPatch := patch 1831 + newSourceRev := sourceRev 1832 + err = db.ResubmitPull(tx, pullAt, newRoundNumber, newPatch, newSourceRev) 1833 if err != nil { 1834 log.Println("failed to create pull request", err) 1835 s.pages.Notice(w, "resubmit-error", "Failed to create pull request. Try again later.") ··· 2020 continue 2021 } 2022 2023 + // resubmit the new pull 2024 + pullAt := op.PullAt() 2025 + newRoundNumber := len(op.Submissions) 2026 + newPatch := np.LatestPatch() 2027 + newSourceRev := np.LatestSha() 2028 + err := db.ResubmitPull(tx, pullAt, newRoundNumber, newPatch, newSourceRev) 2029 2030 if err != nil { 2031 log.Println("failed to update pull", err, op.PullId) ··· 2033 return 2034 } 2035 2036 + record := np.AsRecord() 2037 2038 writes = append(writes, &comatproto.RepoApplyWrites_Input_Writes_Elem{ 2039 RepoApplyWrites_Update: &comatproto.RepoApplyWrites_Update{