forked from tangled.org/core
this repo has no description

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.

Changed files
+42 -3
appview
pages
state
+11 -1
appview/pages/templates/repo/pulls/fragments/pullCompareBranches.html
···
class="p-1 border border-gray-200 bg-white dark:bg-gray-700 dark:text-white dark:border-gray-600"
>
<option disabled selected>source branch</option>
+
+
{{ $recent := index .Branches 0 }}
{{ range .Branches }}
-
<option value="{{ .Reference.Name }}" class="py-1">
+
{{ $isRecent := eq .Reference.Name $recent.Reference.Name }}
+
<option
+
value="{{ .Reference.Name }}"
+
{{ if $isRecent }}
+
selected
+
{{ end }}
+
class="py-1"
+
>
{{ .Reference.Name }}
+
{{ if $isRecent }}(new){{ end }}
</option>
{{ end }}
</select>
+11 -1
appview/pages/templates/repo/pulls/fragments/pullCompareForksBranches.html
···
class="p-1 border border-gray-200 bg-white dark:bg-gray-700 dark:text-white dark:border-gray-600"
>
<option disabled selected>source branch</option>
+
+
{{ $recent := index .SourceBranches 0 }}
{{ range .SourceBranches }}
-
<option value="{{ .Reference.Name }}" class="py-1">
+
{{ $isRecent := eq .Reference.Name $recent.Reference.Name }}
+
<option
+
value="{{ .Reference.Name }}"
+
{{ if $isRecent }}
+
selected
+
{{ end }}
+
class="py-1"
+
>
{{ .Reference.Name }}
+
{{ if $isRecent }}(new){{ end }}
</option>
{{ end }}
</select>
+20 -1
appview/state/pull.go
···
"io"
"log"
"net/http"
+
"sort"
"strconv"
"time"
···
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,
})
}
···
log.Println("failed to parse target branches response:", err)
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),