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 class="p-1 border border-gray-200 bg-white dark:bg-gray-700 dark:text-white dark:border-gray-600" 10 > 11 <option disabled selected>source branch</option> 12 {{ range .Branches }} 13 - <option value="{{ .Reference.Name }}" class="py-1"> 14 {{ .Reference.Name }} 15 </option> 16 {{ end }} 17 </select>
··· 9 class="p-1 border border-gray-200 bg-white dark:bg-gray-700 dark:text-white dark:border-gray-600" 10 > 11 <option disabled selected>source branch</option> 12 + 13 + {{ $recent := index .Branches 0 }} 14 {{ range .Branches }} 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 + > 23 {{ .Reference.Name }} 24 + {{ if $isRecent }}(new){{ end }} 25 </option> 26 {{ end }} 27 </select>
+11 -1
appview/pages/templates/repo/pulls/fragments/pullCompareForksBranches.html
··· 5 class="p-1 border border-gray-200 bg-white dark:bg-gray-700 dark:text-white dark:border-gray-600" 6 > 7 <option disabled selected>source branch</option> 8 {{ range .SourceBranches }} 9 - <option value="{{ .Reference.Name }}" class="py-1"> 10 {{ .Reference.Name }} 11 </option> 12 {{ end }} 13 </select>
··· 5 class="p-1 border border-gray-200 bg-white dark:bg-gray-700 dark:text-white dark:border-gray-600" 6 > 7 <option disabled selected>source branch</option> 8 + 9 + {{ $recent := index .SourceBranches 0 }} 10 {{ range .SourceBranches }} 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 + > 19 {{ .Reference.Name }} 20 + {{ if $isRecent }}(new){{ end }} 21 </option> 22 {{ end }} 23 </select>
+20 -1
appview/state/pull.go
··· 8 "io" 9 "log" 10 "net/http" 11 "strconv" 12 "time" 13 ··· 991 return 992 } 993 994 s.pages.PullCompareBranchesFragment(w, pages.PullCompareBranchesParams{ 995 RepoInfo: f.RepoInfo(s, user), 996 - Branches: result.Branches, 997 }) 998 } 999 ··· 1088 log.Println("failed to parse target branches response:", err) 1089 return 1090 } 1091 1092 s.pages.PullCompareForkBranchesFragment(w, pages.PullCompareForkBranchesParams{ 1093 RepoInfo: f.RepoInfo(s, user),
··· 8 "io" 9 "log" 10 "net/http" 11 + "sort" 12 "strconv" 13 "time" 14 ··· 992 return 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 + 1008 s.pages.PullCompareBranchesFragment(w, pages.PullCompareBranchesParams{ 1009 RepoInfo: f.RepoInfo(s, user), 1010 + Branches: withoutDefault, 1011 }) 1012 } 1013 ··· 1102 log.Println("failed to parse target branches response:", err) 1103 return 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 + }) 1110 1111 s.pages.PullCompareForkBranchesFragment(w, pages.PullCompareForkBranchesParams{ 1112 RepoInfo: f.RepoInfo(s, user),