From dde635aa301795a1e80ccffabfffc978306ac6b5 Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Tue, 23 Sep 2025 10:30:52 +0100 Subject: [PATCH] appview/models: move db.Pull* into models Signed-off-by: oppiliappan --- appview/db/profile.go | 14 +- appview/db/pulls.go | 384 ++++-------------------------- appview/db/repos.go | 8 +- appview/models/pull.go | 310 ++++++++++++++++++++++++ appview/notify/merged_notifier.go | 4 +- appview/notify/notifier.go | 8 +- appview/pages/pages.go | 28 +-- appview/posthog/notifier.go | 4 +- appview/pulls/pulls.go | 108 ++++----- appview/repo/feed.go | 10 +- appview/state/profile.go | 4 +- 11 files changed, 446 insertions(+), 436 deletions(-) create mode 100644 appview/models/pull.go diff --git a/appview/db/profile.go b/appview/db/profile.go index 5cc5e3eb..a1f00364 100644 --- a/appview/db/profile.go +++ b/appview/db/profile.go @@ -75,18 +75,18 @@ func (i IssueEvents) Stats() IssueEventStats { } type PullEvents struct { - Items []*Pull + Items []*models.Pull } func (p PullEvents) Stats() PullEventStats { var open, merged, closed int for _, pull := range p.Items { switch pull.State { - case PullOpen: + case models.PullOpen: open += 1 - case PullMerged: + case models.PullMerged: merged += 1 - case PullClosed: + case models.PullClosed: closed += 1 } } @@ -546,13 +546,13 @@ func GetVanityStat(e Execer, did string, stat VanityStatKind) (uint64, error) { switch stat { case VanityStatMergedPRCount: query = `select count(id) from pulls where owner_did = ? and state = ?` - args = append(args, did, PullMerged) + args = append(args, did, models.PullMerged) case VanityStatClosedPRCount: query = `select count(id) from pulls where owner_did = ? and state = ?` - args = append(args, did, PullClosed) + args = append(args, did, models.PullClosed) case VanityStatOpenPRCount: query = `select count(id) from pulls where owner_did = ? and state = ?` - args = append(args, did, PullOpen) + args = append(args, did, models.PullOpen) case VanityStatOpenIssueCount: query = `select count(id) from issues where did = ? and open = 1` args = append(args, did) diff --git a/appview/db/pulls.go b/appview/db/pulls.go index 24722ac2..cdddd1f0 100644 --- a/appview/db/pulls.go +++ b/appview/db/pulls.go @@ -4,227 +4,15 @@ import ( "database/sql" "fmt" "log" - "slices" "sort" "strings" "time" "github.com/bluesky-social/indigo/atproto/syntax" - "tangled.org/core/api/tangled" "tangled.org/core/appview/models" - "tangled.org/core/patchutil" - "tangled.org/core/types" ) -type PullState int - -const ( - PullClosed PullState = iota - PullOpen - PullMerged - PullDeleted -) - -func (p PullState) String() string { - switch p { - case PullOpen: - return "open" - case PullMerged: - return "merged" - case PullClosed: - return "closed" - case PullDeleted: - return "deleted" - default: - return "closed" - } -} - -func (p PullState) IsOpen() bool { - return p == PullOpen -} -func (p PullState) IsMerged() bool { - return p == PullMerged -} -func (p PullState) IsClosed() bool { - return p == PullClosed -} -func (p PullState) IsDeleted() bool { - return p == PullDeleted -} - -type Pull struct { - // ids - ID int - PullId int - - // at ids - RepoAt syntax.ATURI - OwnerDid string - Rkey string - - // content - Title string - Body string - TargetBranch string - State PullState - Submissions []*PullSubmission - - // stacking - StackId string // nullable string - ChangeId string // nullable string - ParentChangeId string // nullable string - - // meta - Created time.Time - PullSource *PullSource - - // optionally, populate this when querying for reverse mappings - Repo *models.Repo -} - -func (p Pull) AsRecord() tangled.RepoPull { - var source *tangled.RepoPull_Source - if p.PullSource != nil { - s := p.PullSource.AsRecord() - source = &s - source.Sha = p.LatestSha() - } - - record := tangled.RepoPull{ - Title: p.Title, - Body: &p.Body, - CreatedAt: p.Created.Format(time.RFC3339), - Target: &tangled.RepoPull_Target{ - Repo: p.RepoAt.String(), - Branch: p.TargetBranch, - }, - Patch: p.LatestPatch(), - Source: source, - } - return record -} - -type PullSource struct { - Branch string - RepoAt *syntax.ATURI - - // optionally populate this for reverse mappings - Repo *models.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 - PullId int - - // at ids - RepoAt syntax.ATURI - - // content - RoundNumber int - Patch string - Comments []PullComment - SourceRev string // include the rev that was used to create this submission: only for branch/fork PRs - - // meta - Created time.Time -} - -type PullComment struct { - // ids - ID int - PullId int - SubmissionId int - - // at ids - RepoAt string - OwnerDid string - CommentAt string - - // content - Body string - - // meta - Created time.Time -} - -func (p *Pull) LatestPatch() string { - latestSubmission := p.Submissions[p.LastRoundNumber()] - return latestSubmission.Patch -} - -func (p *Pull) LatestSha() string { - latestSubmission := p.Submissions[p.LastRoundNumber()] - return latestSubmission.SourceRev -} - -func (p *Pull) PullAt() syntax.ATURI { - return syntax.ATURI(fmt.Sprintf("at://%s/%s/%s", p.OwnerDid, tangled.RepoPullNSID, p.Rkey)) -} - -func (p *Pull) LastRoundNumber() int { - return len(p.Submissions) - 1 -} - -func (p *Pull) IsPatchBased() bool { - return p.PullSource == nil -} - -func (p *Pull) IsBranchBased() bool { - if p.PullSource != nil { - if p.PullSource.RepoAt != nil { - return p.PullSource.RepoAt == &p.RepoAt - } else { - // no repo specified - return true - } - } - return false -} - -func (p *Pull) IsForkBased() bool { - if p.PullSource != nil { - if p.PullSource.RepoAt != nil { - // make sure repos are different - return p.PullSource.RepoAt != &p.RepoAt - } - } - return false -} - -func (p *Pull) IsStacked() bool { - return p.StackId != "" -} - -func (s PullSubmission) IsFormatPatch() bool { - return patchutil.IsFormatPatch(s.Patch) -} - -func (s PullSubmission) AsFormatPatch() []types.FormatPatch { - patches, err := patchutil.ExtractPatches(s.Patch) - if err != nil { - log.Println("error extracting patches from submission:", err) - return []types.FormatPatch{} - } - - return patches -} - -func NewPull(tx *sql.Tx, pull *Pull) error { +func NewPull(tx *sql.Tx, pull *models.Pull) error { _, err := tx.Exec(` insert or ignore into repo_pull_seqs (repo_at, next_pull_id) values (?, 1) @@ -245,7 +33,7 @@ func NewPull(tx *sql.Tx, pull *Pull) error { } pull.PullId = nextId - pull.State = PullOpen + pull.State = models.PullOpen var sourceBranch, sourceRepoAt *string if pull.PullSource != nil { @@ -312,8 +100,8 @@ func NextPullId(e Execer, repoAt syntax.ATURI) (int, error) { return pullId - 1, err } -func GetPullsWithLimit(e Execer, limit int, filters ...filter) ([]*Pull, error) { - pulls := make(map[int]*Pull) +func GetPullsWithLimit(e Execer, limit int, filters ...filter) ([]*models.Pull, error) { + pulls := make(map[int]*models.Pull) var conditions []string var args []any @@ -362,7 +150,7 @@ func GetPullsWithLimit(e Execer, limit int, filters ...filter) ([]*Pull, error) defer rows.Close() for rows.Next() { - var pull Pull + var pull models.Pull var createdAt string var sourceBranch, sourceRepoAt, stackId, changeId, parentChangeId sql.NullString err := rows.Scan( @@ -392,7 +180,7 @@ func GetPullsWithLimit(e Execer, limit int, filters ...filter) ([]*Pull, error) pull.Created = createdTime if sourceBranch.Valid { - pull.PullSource = &PullSource{ + pull.PullSource = &models.PullSource{ Branch: sourceBranch.String, } if sourceRepoAt.Valid { @@ -445,7 +233,7 @@ func GetPullsWithLimit(e Execer, limit int, filters ...filter) ([]*Pull, error) defer submissionsRows.Close() for submissionsRows.Next() { - var s PullSubmission + var s models.PullSubmission var sourceRev sql.NullString var createdAt string err := submissionsRows.Scan( @@ -471,7 +259,7 @@ func GetPullsWithLimit(e Execer, limit int, filters ...filter) ([]*Pull, error) } if p, ok := pulls[s.PullId]; ok { - p.Submissions = make([]*PullSubmission, s.RoundNumber+1) + p.Submissions = make([]*models.PullSubmission, s.RoundNumber+1) p.Submissions[s.RoundNumber] = &s } } @@ -512,14 +300,14 @@ func GetPullsWithLimit(e Execer, limit int, filters ...filter) ([]*Pull, error) return nil, err } if p, ok := pulls[pullId]; ok { - p.Submissions[p.LastRoundNumber()].Comments = make([]PullComment, commentCount) + p.Submissions[p.LastRoundNumber()].Comments = make([]models.PullComment, commentCount) } } if err := rows.Err(); err != nil { return nil, err } - orderedByPullId := []*Pull{} + orderedByPullId := []*models.Pull{} for _, p := range pulls { orderedByPullId = append(orderedByPullId, p) } @@ -530,11 +318,11 @@ func GetPullsWithLimit(e Execer, limit int, filters ...filter) ([]*Pull, error) return orderedByPullId, nil } -func GetPulls(e Execer, filters ...filter) ([]*Pull, error) { +func GetPulls(e Execer, filters ...filter) ([]*models.Pull, error) { return GetPullsWithLimit(e, 0, filters...) } -func GetPull(e Execer, repoAt syntax.ATURI, pullId int) (*Pull, error) { +func GetPull(e Execer, repoAt syntax.ATURI, pullId int) (*models.Pull, error) { query := ` select owner_did, @@ -558,7 +346,7 @@ func GetPull(e Execer, repoAt syntax.ATURI, pullId int) (*Pull, error) { ` row := e.QueryRow(query, repoAt, pullId) - var pull Pull + var pull models.Pull var createdAt string var sourceBranch, sourceRepoAt, stackId, changeId, parentChangeId sql.NullString err := row.Scan( @@ -589,7 +377,7 @@ func GetPull(e Execer, repoAt syntax.ATURI, pullId int) (*Pull, error) { // populate source if sourceBranch.Valid { - pull.PullSource = &PullSource{ + pull.PullSource = &models.PullSource{ Branch: sourceBranch.String, } if sourceRepoAt.Valid { @@ -625,10 +413,10 @@ func GetPull(e Execer, repoAt syntax.ATURI, pullId int) (*Pull, error) { } defer submissionsRows.Close() - submissionsMap := make(map[int]*PullSubmission) + submissionsMap := make(map[int]*models.PullSubmission) for submissionsRows.Next() { - var submission PullSubmission + var submission models.PullSubmission var submissionCreatedStr string var submissionSourceRev sql.NullString err := submissionsRows.Scan( @@ -692,7 +480,7 @@ func GetPull(e Execer, repoAt syntax.ATURI, pullId int) (*Pull, error) { defer commentsRows.Close() for commentsRows.Next() { - var comment PullComment + var comment models.PullComment var commentCreatedStr string err := commentsRows.Scan( &comment.ID, @@ -736,7 +524,7 @@ func GetPull(e Execer, repoAt syntax.ATURI, pullId int) (*Pull, error) { } } - pull.Submissions = make([]*PullSubmission, len(submissionsMap)) + pull.Submissions = make([]*models.PullSubmission, len(submissionsMap)) for _, submission := range submissionsMap { pull.Submissions[submission.RoundNumber] = submission } @@ -746,8 +534,8 @@ func GetPull(e Execer, repoAt syntax.ATURI, pullId int) (*Pull, error) { // timeframe here is directly passed into the sql query filter, and any // timeframe in the past should be negative; e.g.: "-3 months" -func GetPullsByOwnerDid(e Execer, did, timeframe string) ([]Pull, error) { - var pulls []Pull +func GetPullsByOwnerDid(e Execer, did, timeframe string) ([]models.Pull, error) { + var pulls []models.Pull rows, err := e.Query(` select @@ -776,7 +564,7 @@ func GetPullsByOwnerDid(e Execer, did, timeframe string) ([]Pull, error) { defer rows.Close() for rows.Next() { - var pull Pull + var pull models.Pull var repo models.Repo var pullCreatedAt, repoCreatedAt string err := rows.Scan( @@ -820,7 +608,7 @@ func GetPullsByOwnerDid(e Execer, did, timeframe string) ([]Pull, error) { return pulls, nil } -func NewPullComment(e Execer, comment *PullComment) (int64, error) { +func NewPullComment(e Execer, comment *models.PullComment) (int64, error) { query := `insert into pull_comments (owner_did, repo_at, submission_id, comment_at, pull_id, body) values (?, ?, ?, ?, ?, ?)` res, err := e.Exec( query, @@ -843,39 +631,39 @@ func NewPullComment(e Execer, comment *PullComment) (int64, error) { return i, nil } -func SetPullState(e Execer, repoAt syntax.ATURI, pullId int, pullState PullState) error { +func SetPullState(e Execer, repoAt syntax.ATURI, pullId int, pullState models.PullState) error { _, err := e.Exec( `update pulls set state = ? where repo_at = ? and pull_id = ? and (state <> ? or state <> ?)`, pullState, repoAt, pullId, - PullDeleted, // only update state of non-deleted pulls - PullMerged, // only update state of non-merged pulls + models.PullDeleted, // only update state of non-deleted pulls + models.PullMerged, // only update state of non-merged pulls ) return err } func ClosePull(e Execer, repoAt syntax.ATURI, pullId int) error { - err := SetPullState(e, repoAt, pullId, PullClosed) + err := SetPullState(e, repoAt, pullId, models.PullClosed) return err } func ReopenPull(e Execer, repoAt syntax.ATURI, pullId int) error { - err := SetPullState(e, repoAt, pullId, PullOpen) + err := SetPullState(e, repoAt, pullId, models.PullOpen) return err } func MergePull(e Execer, repoAt syntax.ATURI, pullId int) error { - err := SetPullState(e, repoAt, pullId, PullMerged) + err := SetPullState(e, repoAt, pullId, models.PullMerged) return err } func DeletePull(e Execer, repoAt syntax.ATURI, pullId int) error { - err := SetPullState(e, repoAt, pullId, PullDeleted) + err := SetPullState(e, repoAt, pullId, models.PullDeleted) return err } -func ResubmitPull(e Execer, pull *Pull, newPatch, sourceRev string) error { +func ResubmitPull(e Execer, pull *models.Pull, newPatch, sourceRev string) error { newRoundNumber := len(pull.Submissions) _, err := e.Exec(` insert into pull_submissions (pull_id, repo_at, round_number, patch, source_rev) @@ -941,10 +729,10 @@ func GetPullCount(e Execer, repoAt syntax.ATURI) (models.PullCount, error) { count(case when state = ? then 1 end) as deleted_count from pulls where repo_at = ?`, - PullOpen, - PullMerged, - PullClosed, - PullDeleted, + models.PullOpen, + models.PullMerged, + models.PullClosed, + models.PullDeleted, repoAt, ) @@ -956,8 +744,6 @@ func GetPullCount(e Execer, repoAt syntax.ATURI) (models.PullCount, error) { return count, nil } -type Stack []*Pull - // change-id parent-change-id // // 4 w ,-------- z (TOP) @@ -966,18 +752,18 @@ type Stack []*Pull // 1 x <------' nil (BOT) // // `w` is parent of none, so it is the top of the stack -func GetStack(e Execer, stackId string) (Stack, error) { +func GetStack(e Execer, stackId string) (models.Stack, error) { unorderedPulls, err := GetPulls( e, FilterEq("stack_id", stackId), - FilterNotEq("state", PullDeleted), + FilterNotEq("state", models.PullDeleted), ) if err != nil { return nil, err } // map of parent-change-id to pull - changeIdMap := make(map[string]*Pull, len(unorderedPulls)) - parentMap := make(map[string]*Pull, len(unorderedPulls)) + changeIdMap := make(map[string]*models.Pull, len(unorderedPulls)) + parentMap := make(map[string]*models.Pull, len(unorderedPulls)) for _, p := range unorderedPulls { changeIdMap[p.ChangeId] = p if p.ParentChangeId != "" { @@ -986,7 +772,7 @@ func GetStack(e Execer, stackId string) (Stack, error) { } // the top of the stack is the pull that is not a parent of any pull - var topPull *Pull + var topPull *models.Pull for _, maybeTop := range unorderedPulls { if _, ok := parentMap[maybeTop.ChangeId]; !ok { topPull = maybeTop @@ -994,7 +780,7 @@ func GetStack(e Execer, stackId string) (Stack, error) { } } - pulls := []*Pull{} + pulls := []*models.Pull{} for { pulls = append(pulls, topPull) if topPull.ParentChangeId != "" { @@ -1011,11 +797,11 @@ func GetStack(e Execer, stackId string) (Stack, error) { return pulls, nil } -func GetAbandonedPulls(e Execer, stackId string) ([]*Pull, error) { +func GetAbandonedPulls(e Execer, stackId string) ([]*models.Pull, error) { pulls, err := GetPulls( e, FilterEq("stack_id", stackId), - FilterEq("state", PullDeleted), + FilterEq("state", models.PullDeleted), ) if err != nil { return nil, err @@ -1023,89 +809,3 @@ func GetAbandonedPulls(e Execer, stackId string) ([]*Pull, error) { return pulls, nil } - -// position of this pull in the stack -func (stack Stack) Position(pull *Pull) int { - return slices.IndexFunc(stack, func(p *Pull) bool { - return p.ChangeId == pull.ChangeId - }) -} - -// all pulls below this pull (including self) in this stack -// -// nil if this pull does not belong to this stack -func (stack Stack) Below(pull *Pull) Stack { - position := stack.Position(pull) - - if position < 0 { - return nil - } - - return stack[position:] -} - -// all pulls below this pull (excluding self) in this stack -func (stack Stack) StrictlyBelow(pull *Pull) Stack { - below := stack.Below(pull) - - if len(below) > 0 { - return below[1:] - } - - return nil -} - -// all pulls above this pull (including self) in this stack -func (stack Stack) Above(pull *Pull) Stack { - position := stack.Position(pull) - - if position < 0 { - return nil - } - - return stack[:position+1] -} - -// all pulls below this pull (excluding self) in this stack -func (stack Stack) StrictlyAbove(pull *Pull) Stack { - above := stack.Above(pull) - - if len(above) > 0 { - return above[:len(above)-1] - } - - return nil -} - -// the combined format-patches of all the newest submissions in this stack -func (stack Stack) CombinedPatch() string { - // go in reverse order because the bottom of the stack is the last element in the slice - var combined strings.Builder - for idx := range stack { - pull := stack[len(stack)-1-idx] - combined.WriteString(pull.LatestPatch()) - combined.WriteString("\n") - } - return combined.String() -} - -// filter out PRs that are "active" -// -// PRs that are still open are active -func (stack Stack) Mergeable() Stack { - var mergeable Stack - - for _, p := range stack { - // stop at the first merged PR - if p.State == PullMerged || p.State == PullClosed { - break - } - - // skip over deleted PRs - if p.State != PullDeleted { - mergeable = append(mergeable, p) - } - } - - return mergeable -} diff --git a/appview/db/repos.go b/appview/db/repos.go index 3583bf65..52ce305f 100644 --- a/appview/db/repos.go +++ b/appview/db/repos.go @@ -237,10 +237,10 @@ func GetRepos(e Execer, limit int, filters ...filter) ([]models.Repo, error) { inClause, ) args = append([]any{ - PullOpen, - PullMerged, - PullClosed, - PullDeleted, + models.PullOpen, + models.PullMerged, + models.PullClosed, + models.PullDeleted, }, args...) rows, err = e.Query( pullCountQuery, diff --git a/appview/models/pull.go b/appview/models/pull.go new file mode 100644 index 00000000..2826b00b --- /dev/null +++ b/appview/models/pull.go @@ -0,0 +1,310 @@ +package models + +import ( + "fmt" + "log" + "slices" + "strings" + "time" + + "github.com/bluesky-social/indigo/atproto/syntax" + "tangled.org/core/api/tangled" + "tangled.org/core/patchutil" + "tangled.org/core/types" +) + +type PullState int + +const ( + PullClosed PullState = iota + PullOpen + PullMerged + PullDeleted +) + +func (p PullState) String() string { + switch p { + case PullOpen: + return "open" + case PullMerged: + return "merged" + case PullClosed: + return "closed" + case PullDeleted: + return "deleted" + default: + return "closed" + } +} + +func (p PullState) IsOpen() bool { + return p == PullOpen +} +func (p PullState) IsMerged() bool { + return p == PullMerged +} +func (p PullState) IsClosed() bool { + return p == PullClosed +} +func (p PullState) IsDeleted() bool { + return p == PullDeleted +} + +type Pull struct { + // ids + ID int + PullId int + + // at ids + RepoAt syntax.ATURI + OwnerDid string + Rkey string + + // content + Title string + Body string + TargetBranch string + State PullState + Submissions []*PullSubmission + + // stacking + StackId string // nullable string + ChangeId string // nullable string + ParentChangeId string // nullable string + + // meta + Created time.Time + PullSource *PullSource + + // optionally, populate this when querying for reverse mappings + Repo *Repo +} + +func (p Pull) AsRecord() tangled.RepoPull { + var source *tangled.RepoPull_Source + if p.PullSource != nil { + s := p.PullSource.AsRecord() + source = &s + source.Sha = p.LatestSha() + } + + record := tangled.RepoPull{ + Title: p.Title, + Body: &p.Body, + CreatedAt: p.Created.Format(time.RFC3339), + Target: &tangled.RepoPull_Target{ + Repo: p.RepoAt.String(), + Branch: p.TargetBranch, + }, + Patch: p.LatestPatch(), + Source: source, + } + return record +} + +type PullSource struct { + Branch string + RepoAt *syntax.ATURI + + // optionally populate this for reverse mappings + 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 + PullId int + + // at ids + RepoAt syntax.ATURI + + // content + RoundNumber int + Patch string + Comments []PullComment + SourceRev string // include the rev that was used to create this submission: only for branch/fork PRs + + // meta + Created time.Time +} + +type PullComment struct { + // ids + ID int + PullId int + SubmissionId int + + // at ids + RepoAt string + OwnerDid string + CommentAt string + + // content + Body string + + // meta + Created time.Time +} + +func (p *Pull) LatestPatch() string { + latestSubmission := p.Submissions[p.LastRoundNumber()] + return latestSubmission.Patch +} + +func (p *Pull) LatestSha() string { + latestSubmission := p.Submissions[p.LastRoundNumber()] + return latestSubmission.SourceRev +} + +func (p *Pull) PullAt() syntax.ATURI { + return syntax.ATURI(fmt.Sprintf("at://%s/%s/%s", p.OwnerDid, tangled.RepoPullNSID, p.Rkey)) +} + +func (p *Pull) LastRoundNumber() int { + return len(p.Submissions) - 1 +} + +func (p *Pull) IsPatchBased() bool { + return p.PullSource == nil +} + +func (p *Pull) IsBranchBased() bool { + if p.PullSource != nil { + if p.PullSource.RepoAt != nil { + return p.PullSource.RepoAt == &p.RepoAt + } else { + // no repo specified + return true + } + } + return false +} + +func (p *Pull) IsForkBased() bool { + if p.PullSource != nil { + if p.PullSource.RepoAt != nil { + // make sure repos are different + return p.PullSource.RepoAt != &p.RepoAt + } + } + return false +} + +func (p *Pull) IsStacked() bool { + return p.StackId != "" +} + +func (s PullSubmission) IsFormatPatch() bool { + return patchutil.IsFormatPatch(s.Patch) +} + +func (s PullSubmission) AsFormatPatch() []types.FormatPatch { + patches, err := patchutil.ExtractPatches(s.Patch) + if err != nil { + log.Println("error extracting patches from submission:", err) + return []types.FormatPatch{} + } + + return patches +} + +type Stack []*Pull + +// position of this pull in the stack +func (stack Stack) Position(pull *Pull) int { + return slices.IndexFunc(stack, func(p *Pull) bool { + return p.ChangeId == pull.ChangeId + }) +} + +// all pulls below this pull (including self) in this stack +// +// nil if this pull does not belong to this stack +func (stack Stack) Below(pull *Pull) Stack { + position := stack.Position(pull) + + if position < 0 { + return nil + } + + return stack[position:] +} + +// all pulls below this pull (excluding self) in this stack +func (stack Stack) StrictlyBelow(pull *Pull) Stack { + below := stack.Below(pull) + + if len(below) > 0 { + return below[1:] + } + + return nil +} + +// all pulls above this pull (including self) in this stack +func (stack Stack) Above(pull *Pull) Stack { + position := stack.Position(pull) + + if position < 0 { + return nil + } + + return stack[:position+1] +} + +// all pulls below this pull (excluding self) in this stack +func (stack Stack) StrictlyAbove(pull *Pull) Stack { + above := stack.Above(pull) + + if len(above) > 0 { + return above[:len(above)-1] + } + + return nil +} + +// the combined format-patches of all the newest submissions in this stack +func (stack Stack) CombinedPatch() string { + // go in reverse order because the bottom of the stack is the last element in the slice + var combined strings.Builder + for idx := range stack { + pull := stack[len(stack)-1-idx] + combined.WriteString(pull.LatestPatch()) + combined.WriteString("\n") + } + return combined.String() +} + +// filter out PRs that are "active" +// +// PRs that are still open are active +func (stack Stack) Mergeable() Stack { + var mergeable Stack + + for _, p := range stack { + // stop at the first merged PR + if p.State == PullMerged || p.State == PullClosed { + break + } + + // skip over deleted PRs + if p.State != PullDeleted { + mergeable = append(mergeable, p) + } + } + + return mergeable +} diff --git a/appview/notify/merged_notifier.go b/appview/notify/merged_notifier.go index 984332aa..e478a57a 100644 --- a/appview/notify/merged_notifier.go +++ b/appview/notify/merged_notifier.go @@ -51,12 +51,12 @@ func (m *mergedNotifier) DeleteFollow(ctx context.Context, follow *models.Follow } } -func (m *mergedNotifier) NewPull(ctx context.Context, pull *db.Pull) { +func (m *mergedNotifier) NewPull(ctx context.Context, pull *models.Pull) { for _, notifier := range m.notifiers { notifier.NewPull(ctx, pull) } } -func (m *mergedNotifier) NewPullComment(ctx context.Context, comment *db.PullComment) { +func (m *mergedNotifier) NewPullComment(ctx context.Context, comment *models.PullComment) { for _, notifier := range m.notifiers { notifier.NewPullComment(ctx, comment) } diff --git a/appview/notify/notifier.go b/appview/notify/notifier.go index c9cda054..adde6d5a 100644 --- a/appview/notify/notifier.go +++ b/appview/notify/notifier.go @@ -18,8 +18,8 @@ type Notifier interface { NewFollow(ctx context.Context, follow *models.Follow) DeleteFollow(ctx context.Context, follow *models.Follow) - NewPull(ctx context.Context, pull *db.Pull) - NewPullComment(ctx context.Context, comment *db.PullComment) + NewPull(ctx context.Context, pull *models.Pull) + NewPullComment(ctx context.Context, comment *models.PullComment) UpdateProfile(ctx context.Context, profile *db.Profile) @@ -43,8 +43,8 @@ func (m *BaseNotifier) NewIssue(ctx context.Context, issue *models.Issue) {} func (m *BaseNotifier) NewFollow(ctx context.Context, follow *models.Follow) {} func (m *BaseNotifier) DeleteFollow(ctx context.Context, follow *models.Follow) {} -func (m *BaseNotifier) NewPull(ctx context.Context, pull *db.Pull) {} -func (m *BaseNotifier) NewPullComment(ctx context.Context, comment *db.PullComment) {} +func (m *BaseNotifier) NewPull(ctx context.Context, pull *models.Pull) {} +func (m *BaseNotifier) NewPullComment(ctx context.Context, models *models.PullComment) {} func (m *BaseNotifier) UpdateProfile(ctx context.Context, profile *db.Profile) {} diff --git a/appview/pages/pages.go b/appview/pages/pages.go index 12d730ea..b6e2ae38 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -1019,10 +1019,10 @@ func (p *Pages) RepoNewPull(w io.Writer, params RepoNewPullParams) error { type RepoPullsParams struct { LoggedInUser *oauth.User RepoInfo repoinfo.RepoInfo - Pulls []*db.Pull + Pulls []*models.Pull Active string - FilteringBy db.PullState - Stacks map[string]db.Stack + FilteringBy models.PullState + Stacks map[string]models.Stack Pipelines map[string]db.Pipeline } @@ -1053,9 +1053,9 @@ type RepoSinglePullParams struct { LoggedInUser *oauth.User RepoInfo repoinfo.RepoInfo Active string - Pull *db.Pull - Stack db.Stack - AbandonedPulls []*db.Pull + Pull *models.Pull + Stack models.Stack + AbandonedPulls []*models.Pull MergeCheck types.MergeCheckResponse ResubmitCheck ResubmitResult Pipelines map[string]db.Pipeline @@ -1073,11 +1073,11 @@ func (p *Pages) RepoSinglePull(w io.Writer, params RepoSinglePullParams) error { type RepoPullPatchParams struct { LoggedInUser *oauth.User RepoInfo repoinfo.RepoInfo - Pull *db.Pull - Stack db.Stack + Pull *models.Pull + Stack models.Stack Diff *types.NiceDiff Round int - Submission *db.PullSubmission + Submission *models.PullSubmission OrderedReactionKinds []db.ReactionKind DiffOpts types.DiffOpts } @@ -1090,7 +1090,7 @@ func (p *Pages) RepoPullPatchPage(w io.Writer, params RepoPullPatchParams) error type RepoPullInterdiffParams struct { LoggedInUser *oauth.User RepoInfo repoinfo.RepoInfo - Pull *db.Pull + Pull *models.Pull Round int Interdiff *patchutil.InterdiffResult OrderedReactionKinds []db.ReactionKind @@ -1143,7 +1143,7 @@ func (p *Pages) PullCompareForkBranchesFragment(w io.Writer, params PullCompareF type PullResubmitParams struct { LoggedInUser *oauth.User RepoInfo repoinfo.RepoInfo - Pull *db.Pull + Pull *models.Pull SubmissionId int } @@ -1154,11 +1154,11 @@ func (p *Pages) PullResubmitFragment(w io.Writer, params PullResubmitParams) err type PullActionsParams struct { LoggedInUser *oauth.User RepoInfo repoinfo.RepoInfo - Pull *db.Pull + Pull *models.Pull RoundNumber int MergeCheck types.MergeCheckResponse ResubmitCheck ResubmitResult - Stack db.Stack + Stack models.Stack } func (p *Pages) PullActionsFragment(w io.Writer, params PullActionsParams) error { @@ -1168,7 +1168,7 @@ func (p *Pages) PullActionsFragment(w io.Writer, params PullActionsParams) error type PullNewCommentParams struct { LoggedInUser *oauth.User RepoInfo repoinfo.RepoInfo - Pull *db.Pull + Pull *models.Pull RoundNumber int } diff --git a/appview/posthog/notifier.go b/appview/posthog/notifier.go index 8e277db4..7566bd84 100644 --- a/appview/posthog/notifier.go +++ b/appview/posthog/notifier.go @@ -71,7 +71,7 @@ func (n *posthogNotifier) NewIssue(ctx context.Context, issue *models.Issue) { } } -func (n *posthogNotifier) NewPull(ctx context.Context, pull *db.Pull) { +func (n *posthogNotifier) NewPull(ctx context.Context, pull *models.Pull) { err := n.client.Enqueue(posthog.Capture{ DistinctId: pull.OwnerDid, Event: "new_pull", @@ -85,7 +85,7 @@ func (n *posthogNotifier) NewPull(ctx context.Context, pull *db.Pull) { } } -func (n *posthogNotifier) NewPullComment(ctx context.Context, comment *db.PullComment) { +func (n *posthogNotifier) NewPullComment(ctx context.Context, comment *models.PullComment) { err := n.client.Enqueue(posthog.Capture{ DistinctId: comment.OwnerDid, Event: "new_pull_comment", diff --git a/appview/pulls/pulls.go b/appview/pulls/pulls.go index eccff0f9..ecc48dbf 100644 --- a/appview/pulls/pulls.go +++ b/appview/pulls/pulls.go @@ -76,7 +76,7 @@ func (s *Pulls) PullActions(w http.ResponseWriter, r *http.Request) { return } - pull, ok := r.Context().Value("pull").(*db.Pull) + pull, ok := r.Context().Value("pull").(*models.Pull) if !ok { log.Println("failed to get pull") s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.") @@ -84,7 +84,7 @@ func (s *Pulls) PullActions(w http.ResponseWriter, r *http.Request) { } // can be nil if this pull is not stacked - stack, _ := r.Context().Value("stack").(db.Stack) + stack, _ := r.Context().Value("stack").(models.Stack) roundNumberStr := chi.URLParam(r, "round") roundNumber, err := strconv.Atoi(roundNumberStr) @@ -124,7 +124,7 @@ func (s *Pulls) RepoSinglePull(w http.ResponseWriter, r *http.Request) { return } - pull, ok := r.Context().Value("pull").(*db.Pull) + pull, ok := r.Context().Value("pull").(*models.Pull) if !ok { log.Println("failed to get pull") s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.") @@ -132,8 +132,8 @@ func (s *Pulls) RepoSinglePull(w http.ResponseWriter, r *http.Request) { } // can be nil if this pull is not stacked - stack, _ := r.Context().Value("stack").(db.Stack) - abandonedPulls, _ := r.Context().Value("abandonedPulls").([]*db.Pull) + stack, _ := r.Context().Value("stack").(models.Stack) + abandonedPulls, _ := r.Context().Value("abandonedPulls").([]*models.Pull) totalIdents := 1 for _, submission := range pull.Submissions { @@ -216,8 +216,8 @@ func (s *Pulls) RepoSinglePull(w http.ResponseWriter, r *http.Request) { }) } -func (s *Pulls) mergeCheck(r *http.Request, f *reporesolver.ResolvedRepo, pull *db.Pull, stack db.Stack) types.MergeCheckResponse { - if pull.State == db.PullMerged { +func (s *Pulls) mergeCheck(r *http.Request, f *reporesolver.ResolvedRepo, pull *models.Pull, stack models.Stack) types.MergeCheckResponse { + if pull.State == models.PullMerged { return types.MergeCheckResponse{} } @@ -283,8 +283,8 @@ func (s *Pulls) mergeCheck(r *http.Request, f *reporesolver.ResolvedRepo, pull * return result } -func (s *Pulls) resubmitCheck(r *http.Request, f *reporesolver.ResolvedRepo, pull *db.Pull, stack db.Stack) pages.ResubmitResult { - if pull.State == db.PullMerged || pull.State == db.PullDeleted || pull.PullSource == nil { +func (s *Pulls) resubmitCheck(r *http.Request, f *reporesolver.ResolvedRepo, pull *models.Pull, stack models.Stack) pages.ResubmitResult { + if pull.State == models.PullMerged || pull.State == models.PullDeleted || pull.PullSource == nil { return pages.Unknown } @@ -357,14 +357,14 @@ func (s *Pulls) RepoPullPatch(w http.ResponseWriter, r *http.Request) { diffOpts.Split = true } - pull, ok := r.Context().Value("pull").(*db.Pull) + pull, ok := r.Context().Value("pull").(*models.Pull) if !ok { log.Println("failed to get pull") s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.") return } - stack, _ := r.Context().Value("stack").(db.Stack) + stack, _ := r.Context().Value("stack").(models.Stack) roundId := chi.URLParam(r, "round") roundIdInt, err := strconv.Atoi(roundId) @@ -404,7 +404,7 @@ func (s *Pulls) RepoPullInterdiff(w http.ResponseWriter, r *http.Request) { diffOpts.Split = true } - pull, ok := r.Context().Value("pull").(*db.Pull) + pull, ok := r.Context().Value("pull").(*models.Pull) if !ok { log.Println("failed to get pull") s.pages.Notice(w, "pull-error", "Failed to get pull.") @@ -452,7 +452,7 @@ func (s *Pulls) RepoPullInterdiff(w http.ResponseWriter, r *http.Request) { } func (s *Pulls) RepoPullPatchRaw(w http.ResponseWriter, r *http.Request) { - pull, ok := r.Context().Value("pull").(*db.Pull) + pull, ok := r.Context().Value("pull").(*models.Pull) if !ok { log.Println("failed to get pull") s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.") @@ -475,12 +475,12 @@ func (s *Pulls) RepoPulls(w http.ResponseWriter, r *http.Request) { user := s.oauth.GetUser(r) params := r.URL.Query() - state := db.PullOpen + state := models.PullOpen switch params.Get("state") { case "closed": - state = db.PullClosed + state = models.PullClosed case "merged": - state = db.PullMerged + state = models.PullMerged } f, err := s.repoResolver.Resolve(r) @@ -516,7 +516,7 @@ func (s *Pulls) RepoPulls(w http.ResponseWriter, r *http.Request) { } // we want to group all stacked PRs into just one list - stacks := make(map[string]db.Stack) + stacks := make(map[string]models.Stack) var shas []string n := 0 for _, p := range pulls { @@ -575,7 +575,7 @@ func (s *Pulls) PullComment(w http.ResponseWriter, r *http.Request) { return } - pull, ok := r.Context().Value("pull").(*db.Pull) + pull, ok := r.Context().Value("pull").(*models.Pull) if !ok { log.Println("failed to get pull") s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.") @@ -648,7 +648,7 @@ func (s *Pulls) PullComment(w http.ResponseWriter, r *http.Request) { return } - comment := &db.PullComment{ + comment := &models.PullComment{ OwnerDid: user.Did, RepoAt: f.RepoAt().String(), PullId: pull.PullId, @@ -891,7 +891,7 @@ func (s *Pulls) handleBranchBasedPull( return } - pullSource := &db.PullSource{ + pullSource := &models.PullSource{ Branch: sourceBranch, } recordPullSource := &tangled.RepoPull_Source{ @@ -1001,7 +1001,7 @@ func (s *Pulls) handleForkBasedPull(w http.ResponseWriter, r *http.Request, f *r forkAtUri := fork.RepoAt() forkAtUriStr := forkAtUri.String() - pullSource := &db.PullSource{ + pullSource := &models.PullSource{ Branch: sourceBranch, RepoAt: &forkAtUri, } @@ -1022,7 +1022,7 @@ func (s *Pulls) createPullRequest( title, body, targetBranch string, patch string, sourceRev string, - pullSource *db.PullSource, + pullSource *models.PullSource, recordPullSource *tangled.RepoPull_Source, isStacked bool, ) { @@ -1074,18 +1074,18 @@ func (s *Pulls) createPullRequest( } rkey := tid.TID() - initialSubmission := db.PullSubmission{ + initialSubmission := models.PullSubmission{ Patch: patch, SourceRev: sourceRev, } - pull := &db.Pull{ + pull := &models.Pull{ Title: title, Body: body, TargetBranch: targetBranch, OwnerDid: user.Did, RepoAt: f.RepoAt(), Rkey: rkey, - Submissions: []*db.PullSubmission{ + Submissions: []*models.PullSubmission{ &initialSubmission, }, PullSource: pullSource, @@ -1144,7 +1144,7 @@ func (s *Pulls) createStackedPullRequest( targetBranch string, patch string, sourceRev string, - pullSource *db.PullSource, + pullSource *models.PullSource, ) { // run some necessary checks for stacked-prs first @@ -1452,7 +1452,7 @@ func (s *Pulls) ResubmitPull(w http.ResponseWriter, r *http.Request) { return } - pull, ok := r.Context().Value("pull").(*db.Pull) + pull, ok := r.Context().Value("pull").(*models.Pull) if !ok { log.Println("failed to get pull") s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.") @@ -1483,7 +1483,7 @@ func (s *Pulls) ResubmitPull(w http.ResponseWriter, r *http.Request) { func (s *Pulls) resubmitPatch(w http.ResponseWriter, r *http.Request) { user := s.oauth.GetUser(r) - pull, ok := r.Context().Value("pull").(*db.Pull) + pull, ok := r.Context().Value("pull").(*models.Pull) if !ok { log.Println("failed to get pull") s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.") @@ -1510,7 +1510,7 @@ func (s *Pulls) resubmitPatch(w http.ResponseWriter, r *http.Request) { func (s *Pulls) resubmitBranch(w http.ResponseWriter, r *http.Request) { user := s.oauth.GetUser(r) - pull, ok := r.Context().Value("pull").(*db.Pull) + pull, ok := r.Context().Value("pull").(*models.Pull) if !ok { log.Println("failed to get pull") s.pages.Notice(w, "resubmit-error", "Failed to edit patch. Try again later.") @@ -1573,7 +1573,7 @@ func (s *Pulls) resubmitBranch(w http.ResponseWriter, r *http.Request) { func (s *Pulls) resubmitFork(w http.ResponseWriter, r *http.Request) { user := s.oauth.GetUser(r) - pull, ok := r.Context().Value("pull").(*db.Pull) + pull, ok := r.Context().Value("pull").(*models.Pull) if !ok { log.Println("failed to get pull") s.pages.Notice(w, "resubmit-error", "Failed to edit patch. Try again later.") @@ -1666,7 +1666,7 @@ func (s *Pulls) resubmitFork(w http.ResponseWriter, r *http.Request) { } // validate a resubmission against a pull request -func validateResubmittedPatch(pull *db.Pull, patch string) error { +func validateResubmittedPatch(pull *models.Pull, patch string) error { if patch == "" { return fmt.Errorf("Patch is empty.") } @@ -1687,7 +1687,7 @@ func (s *Pulls) resubmitPullHelper( r *http.Request, f *reporesolver.ResolvedRepo, user *oauth.User, - pull *db.Pull, + pull *models.Pull, patch string, sourceRev string, ) { @@ -1791,13 +1791,13 @@ func (s *Pulls) resubmitStackedPullHelper( r *http.Request, f *reporesolver.ResolvedRepo, user *oauth.User, - pull *db.Pull, + pull *models.Pull, patch string, stackId string, ) { targetBranch := pull.TargetBranch - origStack, _ := r.Context().Value("stack").(db.Stack) + origStack, _ := r.Context().Value("stack").(models.Stack) newStack, err := newStack(f, user, targetBranch, patch, pull.PullSource, stackId) if err != nil { log.Println("failed to create resubmitted stack", err) @@ -1806,8 +1806,8 @@ func (s *Pulls) resubmitStackedPullHelper( } // find the diff between the stacks, first, map them by changeId - origById := make(map[string]*db.Pull) - newById := make(map[string]*db.Pull) + origById := make(map[string]*models.Pull) + newById := make(map[string]*models.Pull) for _, p := range origStack { origById[p.ChangeId] = p } @@ -1820,8 +1820,8 @@ func (s *Pulls) resubmitStackedPullHelper( // commits that got updated: corresponding pull is resubmitted & new round begins // // for commits that were unchanged: no changes, parent-change-id is updated as necessary - additions := make(map[string]*db.Pull) - deletions := make(map[string]*db.Pull) + additions := make(map[string]*models.Pull) + deletions := make(map[string]*models.Pull) unchanged := make(map[string]struct{}) updated := make(map[string]struct{}) @@ -1881,7 +1881,7 @@ func (s *Pulls) resubmitStackedPullHelper( // deleted pulls are marked as deleted in the DB for _, p := range deletions { // do not do delete already merged PRs - if p.State == db.PullMerged { + if p.State == models.PullMerged { continue } @@ -1926,7 +1926,7 @@ func (s *Pulls) resubmitStackedPullHelper( np, _ := newById[id] // do not update already merged PRs - if op.State == db.PullMerged { + if op.State == models.PullMerged { continue } @@ -2047,17 +2047,17 @@ func (s *Pulls) MergePull(w http.ResponseWriter, r *http.Request) { return } - pull, ok := r.Context().Value("pull").(*db.Pull) + pull, ok := r.Context().Value("pull").(*models.Pull) if !ok { log.Println("failed to get pull") s.pages.Notice(w, "pull-merge-error", "Failed to merge patch. Try again later.") return } - var pullsToMerge db.Stack + var pullsToMerge models.Stack pullsToMerge = append(pullsToMerge, pull) if pull.IsStacked() { - stack, ok := r.Context().Value("stack").(db.Stack) + stack, ok := r.Context().Value("stack").(models.Stack) if !ok { log.Println("failed to get stack") s.pages.Notice(w, "pull-merge-error", "Failed to merge patch. Try again later.") @@ -2159,7 +2159,7 @@ func (s *Pulls) ClosePull(w http.ResponseWriter, r *http.Request) { return } - pull, ok := r.Context().Value("pull").(*db.Pull) + pull, ok := r.Context().Value("pull").(*models.Pull) if !ok { log.Println("failed to get pull") s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.") @@ -2187,12 +2187,12 @@ func (s *Pulls) ClosePull(w http.ResponseWriter, r *http.Request) { } defer tx.Rollback() - var pullsToClose []*db.Pull + var pullsToClose []*models.Pull pullsToClose = append(pullsToClose, pull) // if this PR is stacked, then we want to close all PRs below this one on the stack if pull.IsStacked() { - stack := r.Context().Value("stack").(db.Stack) + stack := r.Context().Value("stack").(models.Stack) subStack := stack.StrictlyBelow(pull) pullsToClose = append(pullsToClose, subStack...) } @@ -2227,7 +2227,7 @@ func (s *Pulls) ReopenPull(w http.ResponseWriter, r *http.Request) { return } - pull, ok := r.Context().Value("pull").(*db.Pull) + pull, ok := r.Context().Value("pull").(*models.Pull) if !ok { log.Println("failed to get pull") s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.") @@ -2255,12 +2255,12 @@ func (s *Pulls) ReopenPull(w http.ResponseWriter, r *http.Request) { } defer tx.Rollback() - var pullsToReopen []*db.Pull + var pullsToReopen []*models.Pull pullsToReopen = append(pullsToReopen, pull) // if this PR is stacked, then we want to reopen all PRs above this one on the stack if pull.IsStacked() { - stack := r.Context().Value("stack").(db.Stack) + stack := r.Context().Value("stack").(models.Stack) subStack := stack.StrictlyAbove(pull) pullsToReopen = append(pullsToReopen, subStack...) } @@ -2285,7 +2285,7 @@ func (s *Pulls) ReopenPull(w http.ResponseWriter, r *http.Request) { s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId)) } -func newStack(f *reporesolver.ResolvedRepo, user *oauth.User, targetBranch, patch string, pullSource *db.PullSource, stackId string) (db.Stack, error) { +func newStack(f *reporesolver.ResolvedRepo, user *oauth.User, targetBranch, patch string, pullSource *models.PullSource, stackId string) (models.Stack, error) { formatPatches, err := patchutil.ExtractPatches(patch) if err != nil { return nil, fmt.Errorf("Failed to extract patches: %v", err) @@ -2297,7 +2297,7 @@ func newStack(f *reporesolver.ResolvedRepo, user *oauth.User, targetBranch, patc } // the stack is identified by a UUID - var stack db.Stack + var stack models.Stack parentChangeId := "" for _, fp := range formatPatches { // all patches must have a jj change-id @@ -2310,18 +2310,18 @@ func newStack(f *reporesolver.ResolvedRepo, user *oauth.User, targetBranch, patc body := fp.Body rkey := tid.TID() - initialSubmission := db.PullSubmission{ + initialSubmission := models.PullSubmission{ Patch: fp.Raw, SourceRev: fp.SHA, } - pull := db.Pull{ + pull := models.Pull{ Title: title, Body: body, TargetBranch: targetBranch, OwnerDid: user.Did, RepoAt: f.RepoAt(), Rkey: rkey, - Submissions: []*db.PullSubmission{ + Submissions: []*models.PullSubmission{ &initialSubmission, }, PullSource: pullSource, diff --git a/appview/repo/feed.go b/appview/repo/feed.go index f4660871..31d194e3 100644 --- a/appview/repo/feed.go +++ b/appview/repo/feed.go @@ -71,7 +71,7 @@ func (rp *Repo) getRepoFeed(ctx context.Context, f *reporesolver.ResolvedRepo) ( return feed, nil } -func (rp *Repo) createPullItems(ctx context.Context, pull *db.Pull, f *reporesolver.ResolvedRepo) ([]*feeds.Item, error) { +func (rp *Repo) createPullItems(ctx context.Context, pull *models.Pull, f *reporesolver.ResolvedRepo) ([]*feeds.Item, error) { owner, err := rp.idResolver.ResolveIdent(ctx, pull.OwnerDid) if err != nil { return nil, err @@ -129,17 +129,17 @@ func (rp *Repo) createIssueItem(ctx context.Context, issue models.Issue, f *repo }, nil } -func (rp *Repo) getPullState(pull *db.Pull) string { - if pull.State == db.PullOpen { +func (rp *Repo) getPullState(pull *models.Pull) string { + if pull.State == models.PullOpen { return "opened" } return pull.State.String() } -func (rp *Repo) buildPullDescription(handle syntax.Handle, state string, pull *db.Pull, repoName string) string { +func (rp *Repo) buildPullDescription(handle syntax.Handle, state string, pull *models.Pull, repoName string) string { base := fmt.Sprintf("@%s %s pull request #%d", handle, state, pull.PullId) - if pull.State == db.PullMerged { + if pull.State == models.PullMerged { return fmt.Sprintf("%s (on round #%d) in %s", base, pull.LastRoundNumber(), repoName) } diff --git a/appview/state/profile.go b/appview/state/profile.go index 361dbb19..c00781c1 100644 --- a/appview/state/profile.go +++ b/appview/state/profile.go @@ -454,7 +454,7 @@ func (s *State) getProfileFeed(ctx context.Context, id *identity.Identity) (*fee return &feed, nil } -func (s *State) addPullRequestItems(ctx context.Context, feed *feeds.Feed, pulls []*db.Pull, author *feeds.Author) error { +func (s *State) addPullRequestItems(ctx context.Context, feed *feeds.Feed, pulls []*models.Pull, author *feeds.Author) error { for _, pull := range pulls { owner, err := s.idResolver.ResolveIdent(ctx, pull.Repo.Did) if err != nil { @@ -490,7 +490,7 @@ func (s *State) addRepoItems(ctx context.Context, feed *feeds.Feed, repos []db.R return nil } -func (s *State) createPullRequestItem(pull *db.Pull, owner *identity.Identity, author *feeds.Author) *feeds.Item { +func (s *State) createPullRequestItem(pull *models.Pull, owner *identity.Identity, author *feeds.Author) *feeds.Item { return &feeds.Item{ Title: fmt.Sprintf("%s created pull request '%s' in @%s/%s", author.Name, pull.Title, owner.Handle, pull.Repo.Name), 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"}, -- 2.51.2