+25
appview/db/pulls.go
+25
appview/db/pulls.go
···
947
return err
948
}
949
950
+
// Only used when stacking to update contents in the event of a rebase (the interdiff should be empty).
951
+
// otherwise submissions are immutable
952
+
func UpdatePull(e Execer, newPatch, sourceRev string, filters ...filter) error {
953
+
var conditions []string
954
+
var args []any
955
+
956
+
args = append(args, sourceRev)
957
+
args = append(args, newPatch)
958
+
959
+
for _, filter := range filters {
960
+
conditions = append(conditions, filter.Condition())
961
+
args = append(args, filter.arg)
962
+
}
963
+
964
+
whereClause := ""
965
+
if conditions != nil {
966
+
whereClause = " where " + strings.Join(conditions, " and ")
967
+
}
968
+
969
+
query := fmt.Sprintf("update pull_submissions set source_rev = ?, patch = ? %s", whereClause)
970
+
_, err := e.Exec(query, args...)
971
+
972
+
return err
973
+
}
974
+
975
type PullCount struct {
976
Open int
977
Merged int
+46
-2
appview/state/pull.go
+46
-2
appview/state/pull.go
···
273
latestSourceRev = top.Submissions[top.LastRoundNumber()].SourceRev
274
}
275
276
if latestSourceRev != result.Branch.Hash {
277
-
log.Println(latestSourceRev, result.Branch.Hash)
278
return pages.ShouldResubmit
279
}
280
···
1676
patchutil.SortPatch(origFiles)
1677
1678
// text content of patch may be identical, but a jj rebase might have forwarded it
1679
-
if patchutil.Equal(newFiles, origFiles) && origHeader.SHA == newHeader.SHA {
1680
unchanged[op.ChangeId] = struct{}{}
1681
} else {
1682
updated[op.ChangeId] = struct{}{}
···
1750
1751
record := op.AsRecord()
1752
record.Patch = submission.Patch
1753
1754
writes = append(writes, &comatproto.RepoApplyWrites_Input_Writes_Elem{
1755
RepoApplyWrites_Update: &comatproto.RepoApplyWrites_Update{
···
273
latestSourceRev = top.Submissions[top.LastRoundNumber()].SourceRev
274
}
275
276
+
log.Println(latestSourceRev, result.Branch.Hash)
277
+
278
if latestSourceRev != result.Branch.Hash {
279
return pages.ShouldResubmit
280
}
281
···
1677
patchutil.SortPatch(origFiles)
1678
1679
// text content of patch may be identical, but a jj rebase might have forwarded it
1680
+
//
1681
+
// we still need to update the hash in submission.Patch and submission.SourceRev
1682
+
if patchutil.Equal(newFiles, origFiles) &&
1683
+
origHeader.Title == newHeader.Title &&
1684
+
origHeader.Body == newHeader.Body {
1685
unchanged[op.ChangeId] = struct{}{}
1686
} else {
1687
updated[op.ChangeId] = struct{}{}
···
1755
1756
record := op.AsRecord()
1757
record.Patch = submission.Patch
1758
+
1759
+
writes = append(writes, &comatproto.RepoApplyWrites_Input_Writes_Elem{
1760
+
RepoApplyWrites_Update: &comatproto.RepoApplyWrites_Update{
1761
+
Collection: tangled.RepoPullNSID,
1762
+
Rkey: op.Rkey,
1763
+
Value: &lexutil.LexiconTypeDecoder{
1764
+
Val: &record,
1765
+
},
1766
+
},
1767
+
})
1768
+
}
1769
+
1770
+
// unchanged pulls are edited without starting a new round
1771
+
//
1772
+
// update source-revs & patches without advancing rounds
1773
+
for changeId := range unchanged {
1774
+
op, _ := origById[changeId]
1775
+
np, _ := newById[changeId]
1776
+
1777
+
origSubmission := op.Submissions[op.LastRoundNumber()]
1778
+
newSubmission := np.Submissions[np.LastRoundNumber()]
1779
+
1780
+
log.Println("moving unchanged change id : ", changeId)
1781
+
1782
+
err := db.UpdatePull(
1783
+
tx,
1784
+
newSubmission.Patch,
1785
+
newSubmission.SourceRev,
1786
+
db.FilterEq("id", origSubmission.ID),
1787
+
)
1788
+
1789
+
if err != nil {
1790
+
log.Println("failed to update pull", err, op.PullId)
1791
+
s.pages.Notice(w, "pull-resubmit-error", "Failed to resubmit pull request. Try again later.")
1792
+
return
1793
+
}
1794
+
1795
+
record := op.AsRecord()
1796
+
record.Patch = newSubmission.Patch
1797
1798
writes = append(writes, &comatproto.RepoApplyWrites_Input_Writes_Elem{
1799
RepoApplyWrites_Update: &comatproto.RepoApplyWrites_Update{