Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2

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.

authored by anirudh.fi and committed by

Tangled 1a455273 50655c66

+42 -3
+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 ··· 992 991 return 993 992 } 994 993 994 + branches := result.Branches 995 + sort.Slice(branches, func(i int, j int) bool { 996 + return branches[i].Commit.Committer.When.After(branches[j].Commit.Committer.When) 997 + }) 998 + 999 + withoutDefault := []types.Branch{} 1000 + for _, b := range branches { 1001 + if b.IsDefault { 1002 + continue 1003 + } 1004 + withoutDefault = append(withoutDefault, b) 1005 + } 1006 + 995 1007 s.pages.PullCompareBranchesFragment(w, pages.PullCompareBranchesParams{ 996 1008 RepoInfo: f.RepoInfo(s, user), 997 - Branches: result.Branches, 1009 + Branches: withoutDefault, 998 1010 }) 999 1011 } 1000 1012 ··· 1102 1088 log.Println("failed to parse target branches response:", err) 1103 1089 return 1104 1090 } 1091 + 1092 + sourceBranches := sourceResult.Branches 1093 + sort.Slice(sourceBranches, func(i int, j int) bool { 1094 + return sourceBranches[i].Commit.Committer.When.After(sourceBranches[j].Commit.Committer.When) 1095 + }) 1105 1096 1106 1097 s.pages.PullCompareForkBranchesFragment(w, pages.PullCompareForkBranchesParams{ 1107 1098 RepoInfo: f.RepoInfo(s, user),