Monorepo for Tangled tangled.org

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.

anirudh.fi f30b0a4a 65defd9c

verified
Changed files
+42 -3
appview
pages
state
+11 -1
appview/pages/templates/repo/pulls/fragments/pullCompareBranches.html
··· 9 9 class="p-1 border border-gray-200 bg-white dark:bg-gray-700 dark:text-white dark:border-gray-600" 10 10 > 11 11 <option disabled selected>source branch</option> 12 + 13 + {{ $recent := index .Branches 0 }} 12 14 {{ range .Branches }} 13 - <option value="{{ .Reference.Name }}" class="py-1"> 15 + {{ $isRecent := eq .Reference.Name $recent.Reference.Name }} 16 + <option 17 + value="{{ .Reference.Name }}" 18 + {{ if $isRecent }} 19 + selected 20 + {{ end }} 21 + class="py-1" 22 + > 14 23 {{ .Reference.Name }} 24 + {{ if $isRecent }}(new){{ end }} 15 25 </option> 16 26 {{ end }} 17 27 </select>
+11 -1
appview/pages/templates/repo/pulls/fragments/pullCompareForksBranches.html
··· 5 5 class="p-1 border border-gray-200 bg-white dark:bg-gray-700 dark:text-white dark:border-gray-600" 6 6 > 7 7 <option disabled selected>source branch</option> 8 + 9 + {{ $recent := index .SourceBranches 0 }} 8 10 {{ range .SourceBranches }} 9 - <option value="{{ .Reference.Name }}" class="py-1"> 11 + {{ $isRecent := eq .Reference.Name $recent.Reference.Name }} 12 + <option 13 + value="{{ .Reference.Name }}" 14 + {{ if $isRecent }} 15 + selected 16 + {{ end }} 17 + class="py-1" 18 + > 10 19 {{ .Reference.Name }} 20 + {{ if $isRecent }}(new){{ end }} 11 21 </option> 12 22 {{ end }} 13 23 </select>
+20 -1
appview/state/pull.go
··· 8 8 "io" 9 9 "log" 10 10 "net/http" 11 + "sort" 11 12 "strconv" 12 13 "time" 13 14 ··· 991 992 return 992 993 } 993 994 995 + branches := result.Branches 996 + sort.Slice(branches, func(i int, j int) bool { 997 + return branches[i].Commit.Committer.When.After(branches[j].Commit.Committer.When) 998 + }) 999 + 1000 + withoutDefault := []types.Branch{} 1001 + for _, b := range branches { 1002 + if b.IsDefault { 1003 + continue 1004 + } 1005 + withoutDefault = append(withoutDefault, b) 1006 + } 1007 + 994 1008 s.pages.PullCompareBranchesFragment(w, pages.PullCompareBranchesParams{ 995 1009 RepoInfo: f.RepoInfo(s, user), 996 - Branches: result.Branches, 1010 + Branches: withoutDefault, 997 1011 }) 998 1012 } 999 1013 ··· 1088 1102 log.Println("failed to parse target branches response:", err) 1089 1103 return 1090 1104 } 1105 + 1106 + sourceBranches := sourceResult.Branches 1107 + sort.Slice(sourceBranches, func(i int, j int) bool { 1108 + return sourceBranches[i].Commit.Committer.When.After(sourceBranches[j].Commit.Committer.When) 1109 + }) 1091 1110 1092 1111 s.pages.PullCompareForkBranchesFragment(w, pages.PullCompareForkBranchesParams{ 1093 1112 RepoInfo: f.RepoInfo(s, user),