diff --git a/appview/db/pulls.go b/appview/db/pulls.go index 85ec13c9..9948b3af 100644 --- a/appview/db/pulls.go +++ b/appview/db/pulls.go @@ -947,6 +947,31 @@ func SetPullParentChangeId(e Execer, parentChangeId string, filters ...filter) e return err } +// Only used when stacking to update contents in the event of a rebase (the interdiff should be empty). +// otherwise submissions are immutable +func UpdatePull(e Execer, newPatch, sourceRev string, filters ...filter) error { + var conditions []string + var args []any + + args = append(args, sourceRev) + args = append(args, newPatch) + + for _, filter := range filters { + conditions = append(conditions, filter.Condition()) + args = append(args, filter.arg) + } + + whereClause := "" + if conditions != nil { + whereClause = " where " + strings.Join(conditions, " and ") + } + + query := fmt.Sprintf("update pull_submissions set source_rev = ?, patch = ? %s", whereClause) + _, err := e.Exec(query, args...) + + return err +} + type PullCount struct { Open int Merged int diff --git a/appview/state/pull.go b/appview/state/pull.go index 6e485aea..4c6ee51a 100644 --- a/appview/state/pull.go +++ b/appview/state/pull.go @@ -260,8 +260,9 @@ func (s *State) resubmitCheck(f *FullyResolvedRepo, pull *db.Pull, stack db.Stac latestSourceRev = top.Submissions[top.LastRoundNumber()].SourceRev } + log.Println(latestSourceRev, result.Branch.Hash) + if latestSourceRev != result.Branch.Hash { - log.Println(latestSourceRev, result.Branch.Hash) return pages.ShouldResubmit } @@ -1609,7 +1610,11 @@ func (s *State) resubmitStackedPullHelper( patchutil.SortPatch(origFiles) // text content of patch may be identical, but a jj rebase might have forwarded it - if patchutil.Equal(newFiles, origFiles) && origHeader.SHA == newHeader.SHA { + // + // we still need to update the hash in submission.Patch and submission.SourceRev + if patchutil.Equal(newFiles, origFiles) && + origHeader.Title == newHeader.Title && + origHeader.Body == newHeader.Body { unchanged[op.ChangeId] = struct{}{} } else { updated[op.ChangeId] = struct{}{} @@ -1695,6 +1700,45 @@ func (s *State) resubmitStackedPullHelper( }) } + // unchanged pulls are edited without starting a new round + // + // update source-revs & patches without advancing rounds + for changeId := range unchanged { + op, _ := origById[changeId] + np, _ := newById[changeId] + + origSubmission := op.Submissions[op.LastRoundNumber()] + newSubmission := np.Submissions[np.LastRoundNumber()] + + log.Println("moving unchanged change id : ", changeId) + + err := db.UpdatePull( + tx, + newSubmission.Patch, + newSubmission.SourceRev, + db.FilterEq("id", origSubmission.ID), + ) + + if err != nil { + log.Println("failed to update pull", err, op.PullId) + s.pages.Notice(w, "pull-resubmit-error", "Failed to resubmit pull request. Try again later.") + return + } + + record := op.AsRecord() + record.Patch = newSubmission.Patch + + writes = append(writes, &comatproto.RepoApplyWrites_Input_Writes_Elem{ + RepoApplyWrites_Update: &comatproto.RepoApplyWrites_Update{ + Collection: tangled.RepoPullNSID, + Rkey: op.Rkey, + Value: &lexutil.LexiconTypeDecoder{ + Val: &record, + }, + }, + }) + } + // update parent-change-id relations for the entire stack for _, p := range newStack { err := db.SetPullParentChangeId(