From 1a455273512a2a72035f07ee61165930365a8432 Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Tue, 20 May 2025 11:59:02 +0300 Subject: [PATCH] appview: state: show most recent branch in pulls Sorts branches by update time (and in same-repo comparisons we drop the default branch) and preselects the most recent branch. --- .../pulls/fragments/pullCompareBranches.html | 12 ++++++++++- .../fragments/pullCompareForksBranches.html | 12 ++++++++++- appview/state/pull.go | 21 ++++++++++++++++++- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/appview/pages/templates/repo/pulls/fragments/pullCompareBranches.html b/appview/pages/templates/repo/pulls/fragments/pullCompareBranches.html index 890f17c..bd34590 100644 --- a/appview/pages/templates/repo/pulls/fragments/pullCompareBranches.html +++ b/appview/pages/templates/repo/pulls/fragments/pullCompareBranches.html @@ -9,9 +9,19 @@ class="p-1 border border-gray-200 bg-white dark:bg-gray-700 dark:text-white dark:border-gray-600" > + + {{ $recent := index .Branches 0 }} {{ range .Branches }} - {{ end }} diff --git a/appview/pages/templates/repo/pulls/fragments/pullCompareForksBranches.html b/appview/pages/templates/repo/pulls/fragments/pullCompareForksBranches.html index d2dc3bb..cc426f5 100644 --- a/appview/pages/templates/repo/pulls/fragments/pullCompareForksBranches.html +++ b/appview/pages/templates/repo/pulls/fragments/pullCompareForksBranches.html @@ -5,9 +5,19 @@ class="p-1 border border-gray-200 bg-white dark:bg-gray-700 dark:text-white dark:border-gray-600" > + + {{ $recent := index .SourceBranches 0 }} {{ range .SourceBranches }} - {{ end }} diff --git a/appview/state/pull.go b/appview/state/pull.go index 6bb2ac2..bee6a77 100644 --- a/appview/state/pull.go +++ b/appview/state/pull.go @@ -8,6 +8,7 @@ import ( "io" "log" "net/http" + "sort" "strconv" "time" @@ -991,9 +992,22 @@ func (s *State) CompareBranchesFragment(w http.ResponseWriter, r *http.Request) return } + branches := result.Branches + sort.Slice(branches, func(i int, j int) bool { + return branches[i].Commit.Committer.When.After(branches[j].Commit.Committer.When) + }) + + withoutDefault := []types.Branch{} + for _, b := range branches { + if b.IsDefault { + continue + } + withoutDefault = append(withoutDefault, b) + } + s.pages.PullCompareBranchesFragment(w, pages.PullCompareBranchesParams{ RepoInfo: f.RepoInfo(s, user), - Branches: result.Branches, + Branches: withoutDefault, }) } @@ -1089,6 +1103,11 @@ func (s *State) CompareForksBranchesFragment(w http.ResponseWriter, r *http.Requ return } + sourceBranches := sourceResult.Branches + sort.Slice(sourceBranches, func(i int, j int) bool { + return sourceBranches[i].Commit.Committer.When.After(sourceBranches[j].Commit.Committer.When) + }) + s.pages.PullCompareForkBranchesFragment(w, pages.PullCompareForkBranchesParams{ RepoInfo: f.RepoInfo(s, user), SourceBranches: sourceResult.Branches, -- 2.51.2