diff --git a/appview/db/pulls.go b/appview/db/pulls.go index 7bc6a2af..bb321980 100644 --- a/appview/db/pulls.go +++ b/appview/db/pulls.go @@ -1,6 +1,7 @@ package db import ( + "cmp" "database/sql" "fmt" "maps" @@ -229,6 +230,16 @@ func GetPullsWithLimit(e Execer, limit int, filters ...filter) ([]*models.Pull, p.Submissions = submissions } } + // collect allLabels for each issue + allLabels, err := GetLabels(e, FilterIn("subject", pullAts)) + if err != nil { + return nil, fmt.Errorf("failed to query labels: %w", err) + } + for pullAt, labels := range allLabels { + if p, ok := pulls[pullAt]; ok { + p.Labels = labels + } + } orderedByPullId := []*models.Pull{} for _, p := range pulls { @@ -339,12 +350,19 @@ func GetPullSubmissions(e Execer, filters ...filter) (map[syntax.ATURI][]*models } } - // order the submissions by pull_at + // group the submissions by pull_at m := make(map[syntax.ATURI][]*models.PullSubmission) for _, s := range submissionMap { m[s.PullAt] = append(m[s.PullAt], s) } + // sort each one by round number + for _, s := range m { + slices.SortFunc(s, func(a, b *models.PullSubmission) int { + return cmp.Compare(a.RoundNumber, b.RoundNumber) + }) + } + return m, nil } diff --git a/appview/issues/issues.go b/appview/issues/issues.go index 88984e44..8e4ed732 100644 --- a/appview/issues/issues.go +++ b/appview/issues/issues.go @@ -798,7 +798,11 @@ func (rp *Issues) RepoIssues(w http.ResponseWriter, r *http.Request) { return } - labelDefs, err := db.GetLabelDefinitions(rp.db, db.FilterIn("at_uri", f.Repo.Labels)) + labelDefs, err := db.GetLabelDefinitions( + rp.db, + db.FilterIn("at_uri", f.Repo.Labels), + db.FilterContains("scope", tangled.RepoIssueNSID), + ) if err != nil { log.Println("failed to fetch labels", err) rp.pages.Error503(w) diff --git a/appview/models/pull.go b/appview/models/pull.go index e17f96ae..39a7dcbb 100644 --- a/appview/models/pull.go +++ b/appview/models/pull.go @@ -77,7 +77,8 @@ type Pull struct { PullSource *PullSource // optionally, populate this when querying for reverse mappings - Repo *Repo + Labels LabelState + Repo *Repo } func (p Pull) AsRecord() tangled.RepoPull { @@ -206,6 +207,28 @@ func (p *Pull) IsStacked() bool { return p.StackId != "" } +func (p *Pull) Participants() []string { + participantSet := make(map[string]struct{}) + participants := []string{} + + addParticipant := func(did string) { + if _, exists := participantSet[did]; !exists { + participantSet[did] = struct{}{} + participants = append(participants, did) + } + } + + addParticipant(p.OwnerDid) + + for _, s := range p.Submissions { + for _, sp := range s.Participants() { + addParticipant(sp) + } + } + + return participants +} + func (s PullSubmission) IsFormatPatch() bool { return patchutil.IsFormatPatch(s.Patch) } @@ -220,6 +243,26 @@ func (s PullSubmission) AsFormatPatch() []types.FormatPatch { return patches } +func (s *PullSubmission) Participants() []string { + participantSet := make(map[string]struct{}) + participants := []string{} + + addParticipant := func(did string) { + if _, exists := participantSet[did]; !exists { + participantSet[did] = struct{}{} + participants = append(participants, did) + } + } + + addParticipant(s.PullAt.Authority().String()) + + for _, c := range s.Comments { + addParticipant(c.OwnerDid) + } + + return participants +} + type Stack []*Pull // position of this pull in the stack diff --git a/appview/pages/pages.go b/appview/pages/pages.go index 6825dc9f..5f04de25 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -1087,6 +1087,7 @@ type RepoPullsParams struct { FilteringBy models.PullState Stacks map[string]models.Stack Pipelines map[string]models.Pipeline + LabelDefs map[string]*models.LabelDefinition } func (p *Pages) RepoPulls(w io.Writer, params RepoPullsParams) error { @@ -1126,6 +1127,8 @@ type RepoSinglePullParams struct { OrderedReactionKinds []models.ReactionKind Reactions map[models.ReactionKind]int UserReacted map[models.ReactionKind]bool + + LabelDefs map[string]*models.LabelDefinition } func (p *Pages) RepoSinglePull(w io.Writer, params RepoSinglePullParams) error { diff --git a/appview/pages/templates/repo/fragments/labelPanel.html b/appview/pages/templates/repo/fragments/labelPanel.html index f475bdb8..e735d186 100644 --- a/appview/pages/templates/repo/fragments/labelPanel.html +++ b/appview/pages/templates/repo/fragments/labelPanel.html @@ -1,5 +1,5 @@ {{ define "repo/fragments/labelPanel" }} -