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
+20 -26
appview
db
models
pulls
+4 -2
appview/db/pulls.go
···
return err
}
-
func ResubmitPull(e Execer, pull *models.Pull, newPatch, sourceRev string) error {
+
func ResubmitPull(e Execer, pull *models.Pull) error {
+
newPatch := pull.LatestPatch()
+
newSourceRev := pull.LatestSha()
newRoundNumber := len(pull.Submissions)
_, err := e.Exec(`
insert into pull_submissions (pull_at, round_number, patch, source_rev)
values (?, ?, ?, ?)
-
`, pull.PullAt(), newRoundNumber, newPatch, sourceRev)
+
`, pull.PullAt(), newRoundNumber, newPatch, newSourceRev)
return err
}
+6 -15
appview/models/pull.go
···
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{
···
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
+10 -9
appview/pulls/pulls.go
···
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 {
···
// 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
···
defer tx.Rollback()
-
err = db.ResubmitPull(tx, pull, patch, sourceRev)
+
pull.Submissions = append(pull.Submissions, &models.PullSubmission{
+
Patch: patch,
+
SourceRev: sourceRev,
+
})
+
err = db.ResubmitPull(tx, pull)
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.")
···
continue
-
submission := np.Submissions[np.LastRoundNumber()]
-
// resubmit the old pull
-
err := db.ResubmitPull(tx, op, submission.Patch, submission.SourceRev)
+
err := db.ResubmitPull(tx, np)
if err != nil {
log.Println("failed to update pull", err, op.PullId)
···
return
-
record := op.AsRecord()
-
record.Patch = submission.Patch
+
record := np.AsRecord()
writes = append(writes, &comatproto.RepoApplyWrites_Input_Writes_Elem{
RepoApplyWrites_Update: &comatproto.RepoApplyWrites_Update{