+7
-7
appview/db/profile.go
+7
-7
appview/db/profile.go
···
75
75
}
76
76
77
77
type PullEvents struct {
78
-
Items []*Pull
78
+
Items []*models.Pull
79
79
}
80
80
81
81
func (p PullEvents) Stats() PullEventStats {
82
82
var open, merged, closed int
83
83
for _, pull := range p.Items {
84
84
switch pull.State {
85
-
case PullOpen:
85
+
case models.PullOpen:
86
86
open += 1
87
-
case PullMerged:
87
+
case models.PullMerged:
88
88
merged += 1
89
-
case PullClosed:
89
+
case models.PullClosed:
90
90
closed += 1
91
91
}
92
92
}
···
546
546
switch stat {
547
547
case VanityStatMergedPRCount:
548
548
query = `select count(id) from pulls where owner_did = ? and state = ?`
549
-
args = append(args, did, PullMerged)
549
+
args = append(args, did, models.PullMerged)
550
550
case VanityStatClosedPRCount:
551
551
query = `select count(id) from pulls where owner_did = ? and state = ?`
552
-
args = append(args, did, PullClosed)
552
+
args = append(args, did, models.PullClosed)
553
553
case VanityStatOpenPRCount:
554
554
query = `select count(id) from pulls where owner_did = ? and state = ?`
555
-
args = append(args, did, PullOpen)
555
+
args = append(args, did, models.PullOpen)
556
556
case VanityStatOpenIssueCount:
557
557
query = `select count(id) from issues where did = ? and open = 1`
558
558
args = append(args, did)
+42
-342
appview/db/pulls.go
+42
-342
appview/db/pulls.go
···
4
4
"database/sql"
5
5
"fmt"
6
6
"log"
7
-
"slices"
8
7
"sort"
9
8
"strings"
10
9
"time"
11
10
12
11
"github.com/bluesky-social/indigo/atproto/syntax"
13
-
"tangled.org/core/api/tangled"
14
12
"tangled.org/core/appview/models"
15
-
"tangled.org/core/patchutil"
16
-
"tangled.org/core/types"
17
13
)
18
14
19
-
type PullState int
20
-
21
-
const (
22
-
PullClosed PullState = iota
23
-
PullOpen
24
-
PullMerged
25
-
PullDeleted
26
-
)
27
-
28
-
func (p PullState) String() string {
29
-
switch p {
30
-
case PullOpen:
31
-
return "open"
32
-
case PullMerged:
33
-
return "merged"
34
-
case PullClosed:
35
-
return "closed"
36
-
case PullDeleted:
37
-
return "deleted"
38
-
default:
39
-
return "closed"
40
-
}
41
-
}
42
-
43
-
func (p PullState) IsOpen() bool {
44
-
return p == PullOpen
45
-
}
46
-
func (p PullState) IsMerged() bool {
47
-
return p == PullMerged
48
-
}
49
-
func (p PullState) IsClosed() bool {
50
-
return p == PullClosed
51
-
}
52
-
func (p PullState) IsDeleted() bool {
53
-
return p == PullDeleted
54
-
}
55
-
56
-
type Pull struct {
57
-
// ids
58
-
ID int
59
-
PullId int
60
-
61
-
// at ids
62
-
RepoAt syntax.ATURI
63
-
OwnerDid string
64
-
Rkey string
65
-
66
-
// content
67
-
Title string
68
-
Body string
69
-
TargetBranch string
70
-
State PullState
71
-
Submissions []*PullSubmission
72
-
73
-
// stacking
74
-
StackId string // nullable string
75
-
ChangeId string // nullable string
76
-
ParentChangeId string // nullable string
77
-
78
-
// meta
79
-
Created time.Time
80
-
PullSource *PullSource
81
-
82
-
// optionally, populate this when querying for reverse mappings
83
-
Repo *models.Repo
84
-
}
85
-
86
-
func (p Pull) AsRecord() tangled.RepoPull {
87
-
var source *tangled.RepoPull_Source
88
-
if p.PullSource != nil {
89
-
s := p.PullSource.AsRecord()
90
-
source = &s
91
-
source.Sha = p.LatestSha()
92
-
}
93
-
94
-
record := tangled.RepoPull{
95
-
Title: p.Title,
96
-
Body: &p.Body,
97
-
CreatedAt: p.Created.Format(time.RFC3339),
98
-
Target: &tangled.RepoPull_Target{
99
-
Repo: p.RepoAt.String(),
100
-
Branch: p.TargetBranch,
101
-
},
102
-
Patch: p.LatestPatch(),
103
-
Source: source,
104
-
}
105
-
return record
106
-
}
107
-
108
-
type PullSource struct {
109
-
Branch string
110
-
RepoAt *syntax.ATURI
111
-
112
-
// optionally populate this for reverse mappings
113
-
Repo *models.Repo
114
-
}
115
-
116
-
func (p PullSource) AsRecord() tangled.RepoPull_Source {
117
-
var repoAt *string
118
-
if p.RepoAt != nil {
119
-
s := p.RepoAt.String()
120
-
repoAt = &s
121
-
}
122
-
record := tangled.RepoPull_Source{
123
-
Branch: p.Branch,
124
-
Repo: repoAt,
125
-
}
126
-
return record
127
-
}
128
-
129
-
type PullSubmission struct {
130
-
// ids
131
-
ID int
132
-
PullId int
133
-
134
-
// at ids
135
-
RepoAt syntax.ATURI
136
-
137
-
// content
138
-
RoundNumber int
139
-
Patch string
140
-
Comments []PullComment
141
-
SourceRev string // include the rev that was used to create this submission: only for branch/fork PRs
142
-
143
-
// meta
144
-
Created time.Time
145
-
}
146
-
147
-
type PullComment struct {
148
-
// ids
149
-
ID int
150
-
PullId int
151
-
SubmissionId int
152
-
153
-
// at ids
154
-
RepoAt string
155
-
OwnerDid string
156
-
CommentAt string
157
-
158
-
// content
159
-
Body string
160
-
161
-
// meta
162
-
Created time.Time
163
-
}
164
-
165
-
func (p *Pull) LatestPatch() string {
166
-
latestSubmission := p.Submissions[p.LastRoundNumber()]
167
-
return latestSubmission.Patch
168
-
}
169
-
170
-
func (p *Pull) LatestSha() string {
171
-
latestSubmission := p.Submissions[p.LastRoundNumber()]
172
-
return latestSubmission.SourceRev
173
-
}
174
-
175
-
func (p *Pull) PullAt() syntax.ATURI {
176
-
return syntax.ATURI(fmt.Sprintf("at://%s/%s/%s", p.OwnerDid, tangled.RepoPullNSID, p.Rkey))
177
-
}
178
-
179
-
func (p *Pull) LastRoundNumber() int {
180
-
return len(p.Submissions) - 1
181
-
}
182
-
183
-
func (p *Pull) IsPatchBased() bool {
184
-
return p.PullSource == nil
185
-
}
186
-
187
-
func (p *Pull) IsBranchBased() bool {
188
-
if p.PullSource != nil {
189
-
if p.PullSource.RepoAt != nil {
190
-
return p.PullSource.RepoAt == &p.RepoAt
191
-
} else {
192
-
// no repo specified
193
-
return true
194
-
}
195
-
}
196
-
return false
197
-
}
198
-
199
-
func (p *Pull) IsForkBased() bool {
200
-
if p.PullSource != nil {
201
-
if p.PullSource.RepoAt != nil {
202
-
// make sure repos are different
203
-
return p.PullSource.RepoAt != &p.RepoAt
204
-
}
205
-
}
206
-
return false
207
-
}
208
-
209
-
func (p *Pull) IsStacked() bool {
210
-
return p.StackId != ""
211
-
}
212
-
213
-
func (s PullSubmission) IsFormatPatch() bool {
214
-
return patchutil.IsFormatPatch(s.Patch)
215
-
}
216
-
217
-
func (s PullSubmission) AsFormatPatch() []types.FormatPatch {
218
-
patches, err := patchutil.ExtractPatches(s.Patch)
219
-
if err != nil {
220
-
log.Println("error extracting patches from submission:", err)
221
-
return []types.FormatPatch{}
222
-
}
223
-
224
-
return patches
225
-
}
226
-
227
-
func NewPull(tx *sql.Tx, pull *Pull) error {
15
+
func NewPull(tx *sql.Tx, pull *models.Pull) error {
228
16
_, err := tx.Exec(`
229
17
insert or ignore into repo_pull_seqs (repo_at, next_pull_id)
230
18
values (?, 1)
···
245
33
}
246
34
247
35
pull.PullId = nextId
248
-
pull.State = PullOpen
36
+
pull.State = models.PullOpen
249
37
250
38
var sourceBranch, sourceRepoAt *string
251
39
if pull.PullSource != nil {
···
312
100
return pullId - 1, err
313
101
}
314
102
315
-
func GetPullsWithLimit(e Execer, limit int, filters ...filter) ([]*Pull, error) {
316
-
pulls := make(map[int]*Pull)
103
+
func GetPullsWithLimit(e Execer, limit int, filters ...filter) ([]*models.Pull, error) {
104
+
pulls := make(map[int]*models.Pull)
317
105
318
106
var conditions []string
319
107
var args []any
···
362
150
defer rows.Close()
363
151
364
152
for rows.Next() {
365
-
var pull Pull
153
+
var pull models.Pull
366
154
var createdAt string
367
155
var sourceBranch, sourceRepoAt, stackId, changeId, parentChangeId sql.NullString
368
156
err := rows.Scan(
···
392
180
pull.Created = createdTime
393
181
394
182
if sourceBranch.Valid {
395
-
pull.PullSource = &PullSource{
183
+
pull.PullSource = &models.PullSource{
396
184
Branch: sourceBranch.String,
397
185
}
398
186
if sourceRepoAt.Valid {
···
445
233
defer submissionsRows.Close()
446
234
447
235
for submissionsRows.Next() {
448
-
var s PullSubmission
236
+
var s models.PullSubmission
449
237
var sourceRev sql.NullString
450
238
var createdAt string
451
239
err := submissionsRows.Scan(
···
471
259
}
472
260
473
261
if p, ok := pulls[s.PullId]; ok {
474
-
p.Submissions = make([]*PullSubmission, s.RoundNumber+1)
262
+
p.Submissions = make([]*models.PullSubmission, s.RoundNumber+1)
475
263
p.Submissions[s.RoundNumber] = &s
476
264
}
477
265
}
···
512
300
return nil, err
513
301
}
514
302
if p, ok := pulls[pullId]; ok {
515
-
p.Submissions[p.LastRoundNumber()].Comments = make([]PullComment, commentCount)
303
+
p.Submissions[p.LastRoundNumber()].Comments = make([]models.PullComment, commentCount)
516
304
}
517
305
}
518
306
if err := rows.Err(); err != nil {
519
307
return nil, err
520
308
}
521
309
522
-
orderedByPullId := []*Pull{}
310
+
orderedByPullId := []*models.Pull{}
523
311
for _, p := range pulls {
524
312
orderedByPullId = append(orderedByPullId, p)
525
313
}
···
530
318
return orderedByPullId, nil
531
319
}
532
320
533
-
func GetPulls(e Execer, filters ...filter) ([]*Pull, error) {
321
+
func GetPulls(e Execer, filters ...filter) ([]*models.Pull, error) {
534
322
return GetPullsWithLimit(e, 0, filters...)
535
323
}
536
324
537
-
func GetPull(e Execer, repoAt syntax.ATURI, pullId int) (*Pull, error) {
325
+
func GetPull(e Execer, repoAt syntax.ATURI, pullId int) (*models.Pull, error) {
538
326
query := `
539
327
select
540
328
owner_did,
···
558
346
`
559
347
row := e.QueryRow(query, repoAt, pullId)
560
348
561
-
var pull Pull
349
+
var pull models.Pull
562
350
var createdAt string
563
351
var sourceBranch, sourceRepoAt, stackId, changeId, parentChangeId sql.NullString
564
352
err := row.Scan(
···
589
377
590
378
// populate source
591
379
if sourceBranch.Valid {
592
-
pull.PullSource = &PullSource{
380
+
pull.PullSource = &models.PullSource{
593
381
Branch: sourceBranch.String,
594
382
}
595
383
if sourceRepoAt.Valid {
···
625
413
}
626
414
defer submissionsRows.Close()
627
415
628
-
submissionsMap := make(map[int]*PullSubmission)
416
+
submissionsMap := make(map[int]*models.PullSubmission)
629
417
630
418
for submissionsRows.Next() {
631
-
var submission PullSubmission
419
+
var submission models.PullSubmission
632
420
var submissionCreatedStr string
633
421
var submissionSourceRev sql.NullString
634
422
err := submissionsRows.Scan(
···
692
480
defer commentsRows.Close()
693
481
694
482
for commentsRows.Next() {
695
-
var comment PullComment
483
+
var comment models.PullComment
696
484
var commentCreatedStr string
697
485
err := commentsRows.Scan(
698
486
&comment.ID,
···
736
524
}
737
525
}
738
526
739
-
pull.Submissions = make([]*PullSubmission, len(submissionsMap))
527
+
pull.Submissions = make([]*models.PullSubmission, len(submissionsMap))
740
528
for _, submission := range submissionsMap {
741
529
pull.Submissions[submission.RoundNumber] = submission
742
530
}
···
746
534
747
535
// timeframe here is directly passed into the sql query filter, and any
748
536
// timeframe in the past should be negative; e.g.: "-3 months"
749
-
func GetPullsByOwnerDid(e Execer, did, timeframe string) ([]Pull, error) {
750
-
var pulls []Pull
537
+
func GetPullsByOwnerDid(e Execer, did, timeframe string) ([]models.Pull, error) {
538
+
var pulls []models.Pull
751
539
752
540
rows, err := e.Query(`
753
541
select
···
776
564
defer rows.Close()
777
565
778
566
for rows.Next() {
779
-
var pull Pull
567
+
var pull models.Pull
780
568
var repo models.Repo
781
569
var pullCreatedAt, repoCreatedAt string
782
570
err := rows.Scan(
···
820
608
return pulls, nil
821
609
}
822
610
823
-
func NewPullComment(e Execer, comment *PullComment) (int64, error) {
611
+
func NewPullComment(e Execer, comment *models.PullComment) (int64, error) {
824
612
query := `insert into pull_comments (owner_did, repo_at, submission_id, comment_at, pull_id, body) values (?, ?, ?, ?, ?, ?)`
825
613
res, err := e.Exec(
826
614
query,
···
843
631
return i, nil
844
632
}
845
633
846
-
func SetPullState(e Execer, repoAt syntax.ATURI, pullId int, pullState PullState) error {
634
+
func SetPullState(e Execer, repoAt syntax.ATURI, pullId int, pullState models.PullState) error {
847
635
_, err := e.Exec(
848
636
`update pulls set state = ? where repo_at = ? and pull_id = ? and (state <> ? or state <> ?)`,
849
637
pullState,
850
638
repoAt,
851
639
pullId,
852
-
PullDeleted, // only update state of non-deleted pulls
853
-
PullMerged, // only update state of non-merged pulls
640
+
models.PullDeleted, // only update state of non-deleted pulls
641
+
models.PullMerged, // only update state of non-merged pulls
854
642
)
855
643
return err
856
644
}
857
645
858
646
func ClosePull(e Execer, repoAt syntax.ATURI, pullId int) error {
859
-
err := SetPullState(e, repoAt, pullId, PullClosed)
647
+
err := SetPullState(e, repoAt, pullId, models.PullClosed)
860
648
return err
861
649
}
862
650
863
651
func ReopenPull(e Execer, repoAt syntax.ATURI, pullId int) error {
864
-
err := SetPullState(e, repoAt, pullId, PullOpen)
652
+
err := SetPullState(e, repoAt, pullId, models.PullOpen)
865
653
return err
866
654
}
867
655
868
656
func MergePull(e Execer, repoAt syntax.ATURI, pullId int) error {
869
-
err := SetPullState(e, repoAt, pullId, PullMerged)
657
+
err := SetPullState(e, repoAt, pullId, models.PullMerged)
870
658
return err
871
659
}
872
660
873
661
func DeletePull(e Execer, repoAt syntax.ATURI, pullId int) error {
874
-
err := SetPullState(e, repoAt, pullId, PullDeleted)
662
+
err := SetPullState(e, repoAt, pullId, models.PullDeleted)
875
663
return err
876
664
}
877
665
878
-
func ResubmitPull(e Execer, pull *Pull, newPatch, sourceRev string) error {
666
+
func ResubmitPull(e Execer, pull *models.Pull, newPatch, sourceRev string) error {
879
667
newRoundNumber := len(pull.Submissions)
880
668
_, err := e.Exec(`
881
669
insert into pull_submissions (pull_id, repo_at, round_number, patch, source_rev)
···
941
729
count(case when state = ? then 1 end) as deleted_count
942
730
from pulls
943
731
where repo_at = ?`,
944
-
PullOpen,
945
-
PullMerged,
946
-
PullClosed,
947
-
PullDeleted,
732
+
models.PullOpen,
733
+
models.PullMerged,
734
+
models.PullClosed,
735
+
models.PullDeleted,
948
736
repoAt,
949
737
)
950
738
···
956
744
return count, nil
957
745
}
958
746
959
-
type Stack []*Pull
960
-
961
747
// change-id parent-change-id
962
748
//
963
749
// 4 w ,-------- z (TOP)
···
966
752
// 1 x <------' nil (BOT)
967
753
//
968
754
// `w` is parent of none, so it is the top of the stack
969
-
func GetStack(e Execer, stackId string) (Stack, error) {
755
+
func GetStack(e Execer, stackId string) (models.Stack, error) {
970
756
unorderedPulls, err := GetPulls(
971
757
e,
972
758
FilterEq("stack_id", stackId),
973
-
FilterNotEq("state", PullDeleted),
759
+
FilterNotEq("state", models.PullDeleted),
974
760
)
975
761
if err != nil {
976
762
return nil, err
977
763
}
978
764
// map of parent-change-id to pull
979
-
changeIdMap := make(map[string]*Pull, len(unorderedPulls))
980
-
parentMap := make(map[string]*Pull, len(unorderedPulls))
765
+
changeIdMap := make(map[string]*models.Pull, len(unorderedPulls))
766
+
parentMap := make(map[string]*models.Pull, len(unorderedPulls))
981
767
for _, p := range unorderedPulls {
982
768
changeIdMap[p.ChangeId] = p
983
769
if p.ParentChangeId != "" {
···
986
772
}
987
773
988
774
// the top of the stack is the pull that is not a parent of any pull
989
-
var topPull *Pull
775
+
var topPull *models.Pull
990
776
for _, maybeTop := range unorderedPulls {
991
777
if _, ok := parentMap[maybeTop.ChangeId]; !ok {
992
778
topPull = maybeTop
···
994
780
}
995
781
}
996
782
997
-
pulls := []*Pull{}
783
+
pulls := []*models.Pull{}
998
784
for {
999
785
pulls = append(pulls, topPull)
1000
786
if topPull.ParentChangeId != "" {
···
1011
797
return pulls, nil
1012
798
}
1013
799
1014
-
func GetAbandonedPulls(e Execer, stackId string) ([]*Pull, error) {
800
+
func GetAbandonedPulls(e Execer, stackId string) ([]*models.Pull, error) {
1015
801
pulls, err := GetPulls(
1016
802
e,
1017
803
FilterEq("stack_id", stackId),
1018
-
FilterEq("state", PullDeleted),
804
+
FilterEq("state", models.PullDeleted),
1019
805
)
1020
806
if err != nil {
1021
807
return nil, err
···
1023
809
1024
810
return pulls, nil
1025
811
}
1026
-
1027
-
// position of this pull in the stack
1028
-
func (stack Stack) Position(pull *Pull) int {
1029
-
return slices.IndexFunc(stack, func(p *Pull) bool {
1030
-
return p.ChangeId == pull.ChangeId
1031
-
})
1032
-
}
1033
-
1034
-
// all pulls below this pull (including self) in this stack
1035
-
//
1036
-
// nil if this pull does not belong to this stack
1037
-
func (stack Stack) Below(pull *Pull) Stack {
1038
-
position := stack.Position(pull)
1039
-
1040
-
if position < 0 {
1041
-
return nil
1042
-
}
1043
-
1044
-
return stack[position:]
1045
-
}
1046
-
1047
-
// all pulls below this pull (excluding self) in this stack
1048
-
func (stack Stack) StrictlyBelow(pull *Pull) Stack {
1049
-
below := stack.Below(pull)
1050
-
1051
-
if len(below) > 0 {
1052
-
return below[1:]
1053
-
}
1054
-
1055
-
return nil
1056
-
}
1057
-
1058
-
// all pulls above this pull (including self) in this stack
1059
-
func (stack Stack) Above(pull *Pull) Stack {
1060
-
position := stack.Position(pull)
1061
-
1062
-
if position < 0 {
1063
-
return nil
1064
-
}
1065
-
1066
-
return stack[:position+1]
1067
-
}
1068
-
1069
-
// all pulls below this pull (excluding self) in this stack
1070
-
func (stack Stack) StrictlyAbove(pull *Pull) Stack {
1071
-
above := stack.Above(pull)
1072
-
1073
-
if len(above) > 0 {
1074
-
return above[:len(above)-1]
1075
-
}
1076
-
1077
-
return nil
1078
-
}
1079
-
1080
-
// the combined format-patches of all the newest submissions in this stack
1081
-
func (stack Stack) CombinedPatch() string {
1082
-
// go in reverse order because the bottom of the stack is the last element in the slice
1083
-
var combined strings.Builder
1084
-
for idx := range stack {
1085
-
pull := stack[len(stack)-1-idx]
1086
-
combined.WriteString(pull.LatestPatch())
1087
-
combined.WriteString("\n")
1088
-
}
1089
-
return combined.String()
1090
-
}
1091
-
1092
-
// filter out PRs that are "active"
1093
-
//
1094
-
// PRs that are still open are active
1095
-
func (stack Stack) Mergeable() Stack {
1096
-
var mergeable Stack
1097
-
1098
-
for _, p := range stack {
1099
-
// stop at the first merged PR
1100
-
if p.State == PullMerged || p.State == PullClosed {
1101
-
break
1102
-
}
1103
-
1104
-
// skip over deleted PRs
1105
-
if p.State != PullDeleted {
1106
-
mergeable = append(mergeable, p)
1107
-
}
1108
-
}
1109
-
1110
-
return mergeable
1111
-
}
+4
-4
appview/db/repos.go
+4
-4
appview/db/repos.go
···
237
237
inClause,
238
238
)
239
239
args = append([]any{
240
-
PullOpen,
241
-
PullMerged,
242
-
PullClosed,
243
-
PullDeleted,
240
+
models.PullOpen,
241
+
models.PullMerged,
242
+
models.PullClosed,
243
+
models.PullDeleted,
244
244
}, args...)
245
245
rows, err = e.Query(
246
246
pullCountQuery,
+310
appview/models/pull.go
+310
appview/models/pull.go
···
1
+
package models
2
+
3
+
import (
4
+
"fmt"
5
+
"log"
6
+
"slices"
7
+
"strings"
8
+
"time"
9
+
10
+
"github.com/bluesky-social/indigo/atproto/syntax"
11
+
"tangled.org/core/api/tangled"
12
+
"tangled.org/core/patchutil"
13
+
"tangled.org/core/types"
14
+
)
15
+
16
+
type PullState int
17
+
18
+
const (
19
+
PullClosed PullState = iota
20
+
PullOpen
21
+
PullMerged
22
+
PullDeleted
23
+
)
24
+
25
+
func (p PullState) String() string {
26
+
switch p {
27
+
case PullOpen:
28
+
return "open"
29
+
case PullMerged:
30
+
return "merged"
31
+
case PullClosed:
32
+
return "closed"
33
+
case PullDeleted:
34
+
return "deleted"
35
+
default:
36
+
return "closed"
37
+
}
38
+
}
39
+
40
+
func (p PullState) IsOpen() bool {
41
+
return p == PullOpen
42
+
}
43
+
func (p PullState) IsMerged() bool {
44
+
return p == PullMerged
45
+
}
46
+
func (p PullState) IsClosed() bool {
47
+
return p == PullClosed
48
+
}
49
+
func (p PullState) IsDeleted() bool {
50
+
return p == PullDeleted
51
+
}
52
+
53
+
type Pull struct {
54
+
// ids
55
+
ID int
56
+
PullId int
57
+
58
+
// at ids
59
+
RepoAt syntax.ATURI
60
+
OwnerDid string
61
+
Rkey string
62
+
63
+
// content
64
+
Title string
65
+
Body string
66
+
TargetBranch string
67
+
State PullState
68
+
Submissions []*PullSubmission
69
+
70
+
// stacking
71
+
StackId string // nullable string
72
+
ChangeId string // nullable string
73
+
ParentChangeId string // nullable string
74
+
75
+
// meta
76
+
Created time.Time
77
+
PullSource *PullSource
78
+
79
+
// optionally, populate this when querying for reverse mappings
80
+
Repo *Repo
81
+
}
82
+
83
+
func (p Pull) AsRecord() tangled.RepoPull {
84
+
var source *tangled.RepoPull_Source
85
+
if p.PullSource != nil {
86
+
s := p.PullSource.AsRecord()
87
+
source = &s
88
+
source.Sha = p.LatestSha()
89
+
}
90
+
91
+
record := tangled.RepoPull{
92
+
Title: p.Title,
93
+
Body: &p.Body,
94
+
CreatedAt: p.Created.Format(time.RFC3339),
95
+
Target: &tangled.RepoPull_Target{
96
+
Repo: p.RepoAt.String(),
97
+
Branch: p.TargetBranch,
98
+
},
99
+
Patch: p.LatestPatch(),
100
+
Source: source,
101
+
}
102
+
return record
103
+
}
104
+
105
+
type PullSource struct {
106
+
Branch string
107
+
RepoAt *syntax.ATURI
108
+
109
+
// optionally populate this for reverse mappings
110
+
Repo *Repo
111
+
}
112
+
113
+
func (p PullSource) AsRecord() tangled.RepoPull_Source {
114
+
var repoAt *string
115
+
if p.RepoAt != nil {
116
+
s := p.RepoAt.String()
117
+
repoAt = &s
118
+
}
119
+
record := tangled.RepoPull_Source{
120
+
Branch: p.Branch,
121
+
Repo: repoAt,
122
+
}
123
+
return record
124
+
}
125
+
126
+
type PullSubmission struct {
127
+
// ids
128
+
ID int
129
+
PullId int
130
+
131
+
// at ids
132
+
RepoAt syntax.ATURI
133
+
134
+
// content
135
+
RoundNumber int
136
+
Patch string
137
+
Comments []PullComment
138
+
SourceRev string // include the rev that was used to create this submission: only for branch/fork PRs
139
+
140
+
// meta
141
+
Created time.Time
142
+
}
143
+
144
+
type PullComment struct {
145
+
// ids
146
+
ID int
147
+
PullId int
148
+
SubmissionId int
149
+
150
+
// at ids
151
+
RepoAt string
152
+
OwnerDid string
153
+
CommentAt string
154
+
155
+
// content
156
+
Body string
157
+
158
+
// meta
159
+
Created time.Time
160
+
}
161
+
162
+
func (p *Pull) LatestPatch() string {
163
+
latestSubmission := p.Submissions[p.LastRoundNumber()]
164
+
return latestSubmission.Patch
165
+
}
166
+
167
+
func (p *Pull) LatestSha() string {
168
+
latestSubmission := p.Submissions[p.LastRoundNumber()]
169
+
return latestSubmission.SourceRev
170
+
}
171
+
172
+
func (p *Pull) PullAt() syntax.ATURI {
173
+
return syntax.ATURI(fmt.Sprintf("at://%s/%s/%s", p.OwnerDid, tangled.RepoPullNSID, p.Rkey))
174
+
}
175
+
176
+
func (p *Pull) LastRoundNumber() int {
177
+
return len(p.Submissions) - 1
178
+
}
179
+
180
+
func (p *Pull) IsPatchBased() bool {
181
+
return p.PullSource == nil
182
+
}
183
+
184
+
func (p *Pull) IsBranchBased() bool {
185
+
if p.PullSource != nil {
186
+
if p.PullSource.RepoAt != nil {
187
+
return p.PullSource.RepoAt == &p.RepoAt
188
+
} else {
189
+
// no repo specified
190
+
return true
191
+
}
192
+
}
193
+
return false
194
+
}
195
+
196
+
func (p *Pull) IsForkBased() bool {
197
+
if p.PullSource != nil {
198
+
if p.PullSource.RepoAt != nil {
199
+
// make sure repos are different
200
+
return p.PullSource.RepoAt != &p.RepoAt
201
+
}
202
+
}
203
+
return false
204
+
}
205
+
206
+
func (p *Pull) IsStacked() bool {
207
+
return p.StackId != ""
208
+
}
209
+
210
+
func (s PullSubmission) IsFormatPatch() bool {
211
+
return patchutil.IsFormatPatch(s.Patch)
212
+
}
213
+
214
+
func (s PullSubmission) AsFormatPatch() []types.FormatPatch {
215
+
patches, err := patchutil.ExtractPatches(s.Patch)
216
+
if err != nil {
217
+
log.Println("error extracting patches from submission:", err)
218
+
return []types.FormatPatch{}
219
+
}
220
+
221
+
return patches
222
+
}
223
+
224
+
type Stack []*Pull
225
+
226
+
// position of this pull in the stack
227
+
func (stack Stack) Position(pull *Pull) int {
228
+
return slices.IndexFunc(stack, func(p *Pull) bool {
229
+
return p.ChangeId == pull.ChangeId
230
+
})
231
+
}
232
+
233
+
// all pulls below this pull (including self) in this stack
234
+
//
235
+
// nil if this pull does not belong to this stack
236
+
func (stack Stack) Below(pull *Pull) Stack {
237
+
position := stack.Position(pull)
238
+
239
+
if position < 0 {
240
+
return nil
241
+
}
242
+
243
+
return stack[position:]
244
+
}
245
+
246
+
// all pulls below this pull (excluding self) in this stack
247
+
func (stack Stack) StrictlyBelow(pull *Pull) Stack {
248
+
below := stack.Below(pull)
249
+
250
+
if len(below) > 0 {
251
+
return below[1:]
252
+
}
253
+
254
+
return nil
255
+
}
256
+
257
+
// all pulls above this pull (including self) in this stack
258
+
func (stack Stack) Above(pull *Pull) Stack {
259
+
position := stack.Position(pull)
260
+
261
+
if position < 0 {
262
+
return nil
263
+
}
264
+
265
+
return stack[:position+1]
266
+
}
267
+
268
+
// all pulls below this pull (excluding self) in this stack
269
+
func (stack Stack) StrictlyAbove(pull *Pull) Stack {
270
+
above := stack.Above(pull)
271
+
272
+
if len(above) > 0 {
273
+
return above[:len(above)-1]
274
+
}
275
+
276
+
return nil
277
+
}
278
+
279
+
// the combined format-patches of all the newest submissions in this stack
280
+
func (stack Stack) CombinedPatch() string {
281
+
// go in reverse order because the bottom of the stack is the last element in the slice
282
+
var combined strings.Builder
283
+
for idx := range stack {
284
+
pull := stack[len(stack)-1-idx]
285
+
combined.WriteString(pull.LatestPatch())
286
+
combined.WriteString("\n")
287
+
}
288
+
return combined.String()
289
+
}
290
+
291
+
// filter out PRs that are "active"
292
+
//
293
+
// PRs that are still open are active
294
+
func (stack Stack) Mergeable() Stack {
295
+
var mergeable Stack
296
+
297
+
for _, p := range stack {
298
+
// stop at the first merged PR
299
+
if p.State == PullMerged || p.State == PullClosed {
300
+
break
301
+
}
302
+
303
+
// skip over deleted PRs
304
+
if p.State != PullDeleted {
305
+
mergeable = append(mergeable, p)
306
+
}
307
+
}
308
+
309
+
return mergeable
310
+
}
+2
-2
appview/notify/merged_notifier.go
+2
-2
appview/notify/merged_notifier.go
···
51
51
}
52
52
}
53
53
54
-
func (m *mergedNotifier) NewPull(ctx context.Context, pull *db.Pull) {
54
+
func (m *mergedNotifier) NewPull(ctx context.Context, pull *models.Pull) {
55
55
for _, notifier := range m.notifiers {
56
56
notifier.NewPull(ctx, pull)
57
57
}
58
58
}
59
-
func (m *mergedNotifier) NewPullComment(ctx context.Context, comment *db.PullComment) {
59
+
func (m *mergedNotifier) NewPullComment(ctx context.Context, comment *models.PullComment) {
60
60
for _, notifier := range m.notifiers {
61
61
notifier.NewPullComment(ctx, comment)
62
62
}
+4
-4
appview/notify/notifier.go
+4
-4
appview/notify/notifier.go
···
18
18
NewFollow(ctx context.Context, follow *models.Follow)
19
19
DeleteFollow(ctx context.Context, follow *models.Follow)
20
20
21
-
NewPull(ctx context.Context, pull *db.Pull)
22
-
NewPullComment(ctx context.Context, comment *db.PullComment)
21
+
NewPull(ctx context.Context, pull *models.Pull)
22
+
NewPullComment(ctx context.Context, comment *models.PullComment)
23
23
24
24
UpdateProfile(ctx context.Context, profile *db.Profile)
25
25
···
43
43
func (m *BaseNotifier) NewFollow(ctx context.Context, follow *models.Follow) {}
44
44
func (m *BaseNotifier) DeleteFollow(ctx context.Context, follow *models.Follow) {}
45
45
46
-
func (m *BaseNotifier) NewPull(ctx context.Context, pull *db.Pull) {}
47
-
func (m *BaseNotifier) NewPullComment(ctx context.Context, comment *db.PullComment) {}
46
+
func (m *BaseNotifier) NewPull(ctx context.Context, pull *models.Pull) {}
47
+
func (m *BaseNotifier) NewPullComment(ctx context.Context, models *models.PullComment) {}
48
48
49
49
func (m *BaseNotifier) UpdateProfile(ctx context.Context, profile *db.Profile) {}
50
50
+14
-14
appview/pages/pages.go
+14
-14
appview/pages/pages.go
···
1019
1019
type RepoPullsParams struct {
1020
1020
LoggedInUser *oauth.User
1021
1021
RepoInfo repoinfo.RepoInfo
1022
-
Pulls []*db.Pull
1022
+
Pulls []*models.Pull
1023
1023
Active string
1024
-
FilteringBy db.PullState
1025
-
Stacks map[string]db.Stack
1024
+
FilteringBy models.PullState
1025
+
Stacks map[string]models.Stack
1026
1026
Pipelines map[string]db.Pipeline
1027
1027
}
1028
1028
···
1053
1053
LoggedInUser *oauth.User
1054
1054
RepoInfo repoinfo.RepoInfo
1055
1055
Active string
1056
-
Pull *db.Pull
1057
-
Stack db.Stack
1058
-
AbandonedPulls []*db.Pull
1056
+
Pull *models.Pull
1057
+
Stack models.Stack
1058
+
AbandonedPulls []*models.Pull
1059
1059
MergeCheck types.MergeCheckResponse
1060
1060
ResubmitCheck ResubmitResult
1061
1061
Pipelines map[string]db.Pipeline
···
1073
1073
type RepoPullPatchParams struct {
1074
1074
LoggedInUser *oauth.User
1075
1075
RepoInfo repoinfo.RepoInfo
1076
-
Pull *db.Pull
1077
-
Stack db.Stack
1076
+
Pull *models.Pull
1077
+
Stack models.Stack
1078
1078
Diff *types.NiceDiff
1079
1079
Round int
1080
-
Submission *db.PullSubmission
1080
+
Submission *models.PullSubmission
1081
1081
OrderedReactionKinds []db.ReactionKind
1082
1082
DiffOpts types.DiffOpts
1083
1083
}
···
1090
1090
type RepoPullInterdiffParams struct {
1091
1091
LoggedInUser *oauth.User
1092
1092
RepoInfo repoinfo.RepoInfo
1093
-
Pull *db.Pull
1093
+
Pull *models.Pull
1094
1094
Round int
1095
1095
Interdiff *patchutil.InterdiffResult
1096
1096
OrderedReactionKinds []db.ReactionKind
···
1143
1143
type PullResubmitParams struct {
1144
1144
LoggedInUser *oauth.User
1145
1145
RepoInfo repoinfo.RepoInfo
1146
-
Pull *db.Pull
1146
+
Pull *models.Pull
1147
1147
SubmissionId int
1148
1148
}
1149
1149
···
1154
1154
type PullActionsParams struct {
1155
1155
LoggedInUser *oauth.User
1156
1156
RepoInfo repoinfo.RepoInfo
1157
-
Pull *db.Pull
1157
+
Pull *models.Pull
1158
1158
RoundNumber int
1159
1159
MergeCheck types.MergeCheckResponse
1160
1160
ResubmitCheck ResubmitResult
1161
-
Stack db.Stack
1161
+
Stack models.Stack
1162
1162
}
1163
1163
1164
1164
func (p *Pages) PullActionsFragment(w io.Writer, params PullActionsParams) error {
···
1168
1168
type PullNewCommentParams struct {
1169
1169
LoggedInUser *oauth.User
1170
1170
RepoInfo repoinfo.RepoInfo
1171
-
Pull *db.Pull
1171
+
Pull *models.Pull
1172
1172
RoundNumber int
1173
1173
}
1174
1174
+2
-2
appview/posthog/notifier.go
+2
-2
appview/posthog/notifier.go
···
71
71
}
72
72
}
73
73
74
-
func (n *posthogNotifier) NewPull(ctx context.Context, pull *db.Pull) {
74
+
func (n *posthogNotifier) NewPull(ctx context.Context, pull *models.Pull) {
75
75
err := n.client.Enqueue(posthog.Capture{
76
76
DistinctId: pull.OwnerDid,
77
77
Event: "new_pull",
···
85
85
}
86
86
}
87
87
88
-
func (n *posthogNotifier) NewPullComment(ctx context.Context, comment *db.PullComment) {
88
+
func (n *posthogNotifier) NewPullComment(ctx context.Context, comment *models.PullComment) {
89
89
err := n.client.Enqueue(posthog.Capture{
90
90
DistinctId: comment.OwnerDid,
91
91
Event: "new_pull_comment",
+54
-54
appview/pulls/pulls.go
+54
-54
appview/pulls/pulls.go
···
76
76
return
77
77
}
78
78
79
-
pull, ok := r.Context().Value("pull").(*db.Pull)
79
+
pull, ok := r.Context().Value("pull").(*models.Pull)
80
80
if !ok {
81
81
log.Println("failed to get pull")
82
82
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")
···
84
84
}
85
85
86
86
// can be nil if this pull is not stacked
87
-
stack, _ := r.Context().Value("stack").(db.Stack)
87
+
stack, _ := r.Context().Value("stack").(models.Stack)
88
88
89
89
roundNumberStr := chi.URLParam(r, "round")
90
90
roundNumber, err := strconv.Atoi(roundNumberStr)
···
124
124
return
125
125
}
126
126
127
-
pull, ok := r.Context().Value("pull").(*db.Pull)
127
+
pull, ok := r.Context().Value("pull").(*models.Pull)
128
128
if !ok {
129
129
log.Println("failed to get pull")
130
130
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")
···
132
132
}
133
133
134
134
// can be nil if this pull is not stacked
135
-
stack, _ := r.Context().Value("stack").(db.Stack)
136
-
abandonedPulls, _ := r.Context().Value("abandonedPulls").([]*db.Pull)
135
+
stack, _ := r.Context().Value("stack").(models.Stack)
136
+
abandonedPulls, _ := r.Context().Value("abandonedPulls").([]*models.Pull)
137
137
138
138
totalIdents := 1
139
139
for _, submission := range pull.Submissions {
···
216
216
})
217
217
}
218
218
219
-
func (s *Pulls) mergeCheck(r *http.Request, f *reporesolver.ResolvedRepo, pull *db.Pull, stack db.Stack) types.MergeCheckResponse {
220
-
if pull.State == db.PullMerged {
219
+
func (s *Pulls) mergeCheck(r *http.Request, f *reporesolver.ResolvedRepo, pull *models.Pull, stack models.Stack) types.MergeCheckResponse {
220
+
if pull.State == models.PullMerged {
221
221
return types.MergeCheckResponse{}
222
222
}
223
223
···
283
283
return result
284
284
}
285
285
286
-
func (s *Pulls) resubmitCheck(r *http.Request, f *reporesolver.ResolvedRepo, pull *db.Pull, stack db.Stack) pages.ResubmitResult {
287
-
if pull.State == db.PullMerged || pull.State == db.PullDeleted || pull.PullSource == nil {
286
+
func (s *Pulls) resubmitCheck(r *http.Request, f *reporesolver.ResolvedRepo, pull *models.Pull, stack models.Stack) pages.ResubmitResult {
287
+
if pull.State == models.PullMerged || pull.State == models.PullDeleted || pull.PullSource == nil {
288
288
return pages.Unknown
289
289
}
290
290
···
357
357
diffOpts.Split = true
358
358
}
359
359
360
-
pull, ok := r.Context().Value("pull").(*db.Pull)
360
+
pull, ok := r.Context().Value("pull").(*models.Pull)
361
361
if !ok {
362
362
log.Println("failed to get pull")
363
363
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")
364
364
return
365
365
}
366
366
367
-
stack, _ := r.Context().Value("stack").(db.Stack)
367
+
stack, _ := r.Context().Value("stack").(models.Stack)
368
368
369
369
roundId := chi.URLParam(r, "round")
370
370
roundIdInt, err := strconv.Atoi(roundId)
···
404
404
diffOpts.Split = true
405
405
}
406
406
407
-
pull, ok := r.Context().Value("pull").(*db.Pull)
407
+
pull, ok := r.Context().Value("pull").(*models.Pull)
408
408
if !ok {
409
409
log.Println("failed to get pull")
410
410
s.pages.Notice(w, "pull-error", "Failed to get pull.")
···
452
452
}
453
453
454
454
func (s *Pulls) RepoPullPatchRaw(w http.ResponseWriter, r *http.Request) {
455
-
pull, ok := r.Context().Value("pull").(*db.Pull)
455
+
pull, ok := r.Context().Value("pull").(*models.Pull)
456
456
if !ok {
457
457
log.Println("failed to get pull")
458
458
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")
···
475
475
user := s.oauth.GetUser(r)
476
476
params := r.URL.Query()
477
477
478
-
state := db.PullOpen
478
+
state := models.PullOpen
479
479
switch params.Get("state") {
480
480
case "closed":
481
-
state = db.PullClosed
481
+
state = models.PullClosed
482
482
case "merged":
483
-
state = db.PullMerged
483
+
state = models.PullMerged
484
484
}
485
485
486
486
f, err := s.repoResolver.Resolve(r)
···
516
516
}
517
517
518
518
// we want to group all stacked PRs into just one list
519
-
stacks := make(map[string]db.Stack)
519
+
stacks := make(map[string]models.Stack)
520
520
var shas []string
521
521
n := 0
522
522
for _, p := range pulls {
···
575
575
return
576
576
}
577
577
578
-
pull, ok := r.Context().Value("pull").(*db.Pull)
578
+
pull, ok := r.Context().Value("pull").(*models.Pull)
579
579
if !ok {
580
580
log.Println("failed to get pull")
581
581
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")
···
648
648
return
649
649
}
650
650
651
-
comment := &db.PullComment{
651
+
comment := &models.PullComment{
652
652
OwnerDid: user.Did,
653
653
RepoAt: f.RepoAt().String(),
654
654
PullId: pull.PullId,
···
891
891
return
892
892
}
893
893
894
-
pullSource := &db.PullSource{
894
+
pullSource := &models.PullSource{
895
895
Branch: sourceBranch,
896
896
}
897
897
recordPullSource := &tangled.RepoPull_Source{
···
1001
1001
forkAtUri := fork.RepoAt()
1002
1002
forkAtUriStr := forkAtUri.String()
1003
1003
1004
-
pullSource := &db.PullSource{
1004
+
pullSource := &models.PullSource{
1005
1005
Branch: sourceBranch,
1006
1006
RepoAt: &forkAtUri,
1007
1007
}
···
1022
1022
title, body, targetBranch string,
1023
1023
patch string,
1024
1024
sourceRev string,
1025
-
pullSource *db.PullSource,
1025
+
pullSource *models.PullSource,
1026
1026
recordPullSource *tangled.RepoPull_Source,
1027
1027
isStacked bool,
1028
1028
) {
···
1074
1074
}
1075
1075
1076
1076
rkey := tid.TID()
1077
-
initialSubmission := db.PullSubmission{
1077
+
initialSubmission := models.PullSubmission{
1078
1078
Patch: patch,
1079
1079
SourceRev: sourceRev,
1080
1080
}
1081
-
pull := &db.Pull{
1081
+
pull := &models.Pull{
1082
1082
Title: title,
1083
1083
Body: body,
1084
1084
TargetBranch: targetBranch,
1085
1085
OwnerDid: user.Did,
1086
1086
RepoAt: f.RepoAt(),
1087
1087
Rkey: rkey,
1088
-
Submissions: []*db.PullSubmission{
1088
+
Submissions: []*models.PullSubmission{
1089
1089
&initialSubmission,
1090
1090
},
1091
1091
PullSource: pullSource,
···
1144
1144
targetBranch string,
1145
1145
patch string,
1146
1146
sourceRev string,
1147
-
pullSource *db.PullSource,
1147
+
pullSource *models.PullSource,
1148
1148
) {
1149
1149
// run some necessary checks for stacked-prs first
1150
1150
···
1452
1452
return
1453
1453
}
1454
1454
1455
-
pull, ok := r.Context().Value("pull").(*db.Pull)
1455
+
pull, ok := r.Context().Value("pull").(*models.Pull)
1456
1456
if !ok {
1457
1457
log.Println("failed to get pull")
1458
1458
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")
···
1483
1483
func (s *Pulls) resubmitPatch(w http.ResponseWriter, r *http.Request) {
1484
1484
user := s.oauth.GetUser(r)
1485
1485
1486
-
pull, ok := r.Context().Value("pull").(*db.Pull)
1486
+
pull, ok := r.Context().Value("pull").(*models.Pull)
1487
1487
if !ok {
1488
1488
log.Println("failed to get pull")
1489
1489
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")
···
1510
1510
func (s *Pulls) resubmitBranch(w http.ResponseWriter, r *http.Request) {
1511
1511
user := s.oauth.GetUser(r)
1512
1512
1513
-
pull, ok := r.Context().Value("pull").(*db.Pull)
1513
+
pull, ok := r.Context().Value("pull").(*models.Pull)
1514
1514
if !ok {
1515
1515
log.Println("failed to get pull")
1516
1516
s.pages.Notice(w, "resubmit-error", "Failed to edit patch. Try again later.")
···
1573
1573
func (s *Pulls) resubmitFork(w http.ResponseWriter, r *http.Request) {
1574
1574
user := s.oauth.GetUser(r)
1575
1575
1576
-
pull, ok := r.Context().Value("pull").(*db.Pull)
1576
+
pull, ok := r.Context().Value("pull").(*models.Pull)
1577
1577
if !ok {
1578
1578
log.Println("failed to get pull")
1579
1579
s.pages.Notice(w, "resubmit-error", "Failed to edit patch. Try again later.")
···
1666
1666
}
1667
1667
1668
1668
// validate a resubmission against a pull request
1669
-
func validateResubmittedPatch(pull *db.Pull, patch string) error {
1669
+
func validateResubmittedPatch(pull *models.Pull, patch string) error {
1670
1670
if patch == "" {
1671
1671
return fmt.Errorf("Patch is empty.")
1672
1672
}
···
1687
1687
r *http.Request,
1688
1688
f *reporesolver.ResolvedRepo,
1689
1689
user *oauth.User,
1690
-
pull *db.Pull,
1690
+
pull *models.Pull,
1691
1691
patch string,
1692
1692
sourceRev string,
1693
1693
) {
···
1791
1791
r *http.Request,
1792
1792
f *reporesolver.ResolvedRepo,
1793
1793
user *oauth.User,
1794
-
pull *db.Pull,
1794
+
pull *models.Pull,
1795
1795
patch string,
1796
1796
stackId string,
1797
1797
) {
1798
1798
targetBranch := pull.TargetBranch
1799
1799
1800
-
origStack, _ := r.Context().Value("stack").(db.Stack)
1800
+
origStack, _ := r.Context().Value("stack").(models.Stack)
1801
1801
newStack, err := newStack(f, user, targetBranch, patch, pull.PullSource, stackId)
1802
1802
if err != nil {
1803
1803
log.Println("failed to create resubmitted stack", err)
···
1806
1806
}
1807
1807
1808
1808
// find the diff between the stacks, first, map them by changeId
1809
-
origById := make(map[string]*db.Pull)
1810
-
newById := make(map[string]*db.Pull)
1809
+
origById := make(map[string]*models.Pull)
1810
+
newById := make(map[string]*models.Pull)
1811
1811
for _, p := range origStack {
1812
1812
origById[p.ChangeId] = p
1813
1813
}
···
1820
1820
// commits that got updated: corresponding pull is resubmitted & new round begins
1821
1821
//
1822
1822
// for commits that were unchanged: no changes, parent-change-id is updated as necessary
1823
-
additions := make(map[string]*db.Pull)
1824
-
deletions := make(map[string]*db.Pull)
1823
+
additions := make(map[string]*models.Pull)
1824
+
deletions := make(map[string]*models.Pull)
1825
1825
unchanged := make(map[string]struct{})
1826
1826
updated := make(map[string]struct{})
1827
1827
···
1881
1881
// deleted pulls are marked as deleted in the DB
1882
1882
for _, p := range deletions {
1883
1883
// do not do delete already merged PRs
1884
-
if p.State == db.PullMerged {
1884
+
if p.State == models.PullMerged {
1885
1885
continue
1886
1886
}
1887
1887
···
1926
1926
np, _ := newById[id]
1927
1927
1928
1928
// do not update already merged PRs
1929
-
if op.State == db.PullMerged {
1929
+
if op.State == models.PullMerged {
1930
1930
continue
1931
1931
}
1932
1932
···
2047
2047
return
2048
2048
}
2049
2049
2050
-
pull, ok := r.Context().Value("pull").(*db.Pull)
2050
+
pull, ok := r.Context().Value("pull").(*models.Pull)
2051
2051
if !ok {
2052
2052
log.Println("failed to get pull")
2053
2053
s.pages.Notice(w, "pull-merge-error", "Failed to merge patch. Try again later.")
2054
2054
return
2055
2055
}
2056
2056
2057
-
var pullsToMerge db.Stack
2057
+
var pullsToMerge models.Stack
2058
2058
pullsToMerge = append(pullsToMerge, pull)
2059
2059
if pull.IsStacked() {
2060
-
stack, ok := r.Context().Value("stack").(db.Stack)
2060
+
stack, ok := r.Context().Value("stack").(models.Stack)
2061
2061
if !ok {
2062
2062
log.Println("failed to get stack")
2063
2063
s.pages.Notice(w, "pull-merge-error", "Failed to merge patch. Try again later.")
···
2159
2159
return
2160
2160
}
2161
2161
2162
-
pull, ok := r.Context().Value("pull").(*db.Pull)
2162
+
pull, ok := r.Context().Value("pull").(*models.Pull)
2163
2163
if !ok {
2164
2164
log.Println("failed to get pull")
2165
2165
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")
···
2187
2187
}
2188
2188
defer tx.Rollback()
2189
2189
2190
-
var pullsToClose []*db.Pull
2190
+
var pullsToClose []*models.Pull
2191
2191
pullsToClose = append(pullsToClose, pull)
2192
2192
2193
2193
// if this PR is stacked, then we want to close all PRs below this one on the stack
2194
2194
if pull.IsStacked() {
2195
-
stack := r.Context().Value("stack").(db.Stack)
2195
+
stack := r.Context().Value("stack").(models.Stack)
2196
2196
subStack := stack.StrictlyBelow(pull)
2197
2197
pullsToClose = append(pullsToClose, subStack...)
2198
2198
}
···
2227
2227
return
2228
2228
}
2229
2229
2230
-
pull, ok := r.Context().Value("pull").(*db.Pull)
2230
+
pull, ok := r.Context().Value("pull").(*models.Pull)
2231
2231
if !ok {
2232
2232
log.Println("failed to get pull")
2233
2233
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")
···
2255
2255
}
2256
2256
defer tx.Rollback()
2257
2257
2258
-
var pullsToReopen []*db.Pull
2258
+
var pullsToReopen []*models.Pull
2259
2259
pullsToReopen = append(pullsToReopen, pull)
2260
2260
2261
2261
// if this PR is stacked, then we want to reopen all PRs above this one on the stack
2262
2262
if pull.IsStacked() {
2263
-
stack := r.Context().Value("stack").(db.Stack)
2263
+
stack := r.Context().Value("stack").(models.Stack)
2264
2264
subStack := stack.StrictlyAbove(pull)
2265
2265
pullsToReopen = append(pullsToReopen, subStack...)
2266
2266
}
···
2285
2285
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId))
2286
2286
}
2287
2287
2288
-
func newStack(f *reporesolver.ResolvedRepo, user *oauth.User, targetBranch, patch string, pullSource *db.PullSource, stackId string) (db.Stack, error) {
2288
+
func newStack(f *reporesolver.ResolvedRepo, user *oauth.User, targetBranch, patch string, pullSource *models.PullSource, stackId string) (models.Stack, error) {
2289
2289
formatPatches, err := patchutil.ExtractPatches(patch)
2290
2290
if err != nil {
2291
2291
return nil, fmt.Errorf("Failed to extract patches: %v", err)
···
2297
2297
}
2298
2298
2299
2299
// the stack is identified by a UUID
2300
-
var stack db.Stack
2300
+
var stack models.Stack
2301
2301
parentChangeId := ""
2302
2302
for _, fp := range formatPatches {
2303
2303
// all patches must have a jj change-id
···
2310
2310
body := fp.Body
2311
2311
rkey := tid.TID()
2312
2312
2313
-
initialSubmission := db.PullSubmission{
2313
+
initialSubmission := models.PullSubmission{
2314
2314
Patch: fp.Raw,
2315
2315
SourceRev: fp.SHA,
2316
2316
}
2317
-
pull := db.Pull{
2317
+
pull := models.Pull{
2318
2318
Title: title,
2319
2319
Body: body,
2320
2320
TargetBranch: targetBranch,
2321
2321
OwnerDid: user.Did,
2322
2322
RepoAt: f.RepoAt(),
2323
2323
Rkey: rkey,
2324
-
Submissions: []*db.PullSubmission{
2324
+
Submissions: []*models.PullSubmission{
2325
2325
&initialSubmission,
2326
2326
},
2327
2327
PullSource: pullSource,
+5
-5
appview/repo/feed.go
+5
-5
appview/repo/feed.go
···
71
71
return feed, nil
72
72
}
73
73
74
-
func (rp *Repo) createPullItems(ctx context.Context, pull *db.Pull, f *reporesolver.ResolvedRepo) ([]*feeds.Item, error) {
74
+
func (rp *Repo) createPullItems(ctx context.Context, pull *models.Pull, f *reporesolver.ResolvedRepo) ([]*feeds.Item, error) {
75
75
owner, err := rp.idResolver.ResolveIdent(ctx, pull.OwnerDid)
76
76
if err != nil {
77
77
return nil, err
···
129
129
}, nil
130
130
}
131
131
132
-
func (rp *Repo) getPullState(pull *db.Pull) string {
133
-
if pull.State == db.PullOpen {
132
+
func (rp *Repo) getPullState(pull *models.Pull) string {
133
+
if pull.State == models.PullOpen {
134
134
return "opened"
135
135
}
136
136
return pull.State.String()
137
137
}
138
138
139
-
func (rp *Repo) buildPullDescription(handle syntax.Handle, state string, pull *db.Pull, repoName string) string {
139
+
func (rp *Repo) buildPullDescription(handle syntax.Handle, state string, pull *models.Pull, repoName string) string {
140
140
base := fmt.Sprintf("@%s %s pull request #%d", handle, state, pull.PullId)
141
141
142
-
if pull.State == db.PullMerged {
142
+
if pull.State == models.PullMerged {
143
143
return fmt.Sprintf("%s (on round #%d) in %s", base, pull.LastRoundNumber(), repoName)
144
144
}
145
145
+2
-2
appview/state/profile.go
+2
-2
appview/state/profile.go
···
454
454
return &feed, nil
455
455
}
456
456
457
-
func (s *State) addPullRequestItems(ctx context.Context, feed *feeds.Feed, pulls []*db.Pull, author *feeds.Author) error {
457
+
func (s *State) addPullRequestItems(ctx context.Context, feed *feeds.Feed, pulls []*models.Pull, author *feeds.Author) error {
458
458
for _, pull := range pulls {
459
459
owner, err := s.idResolver.ResolveIdent(ctx, pull.Repo.Did)
460
460
if err != nil {
···
490
490
return nil
491
491
}
492
492
493
-
func (s *State) createPullRequestItem(pull *db.Pull, owner *identity.Identity, author *feeds.Author) *feeds.Item {
493
+
func (s *State) createPullRequestItem(pull *models.Pull, owner *identity.Identity, author *feeds.Author) *feeds.Item {
494
494
return &feeds.Item{
495
495
Title: fmt.Sprintf("%s created pull request '%s' in @%s/%s", author.Name, pull.Title, owner.Handle, pull.Repo.Name),
496
496
Link: &feeds.Link{Href: fmt.Sprintf("%s/@%s/%s/pulls/%d", s.config.Core.AppviewHost, owner.Handle, pull.Repo.Name, pull.PullId), Type: "text/html", Rel: "alternate"},