forked from tangled.org/core
Monorepo for Tangled — https://tangled.org

fix branch switcher

Changed files
+50 -54
appview
pages
templates
state
knotserver
types
-2
appview/pages/pages.go
···
LoggedInUser *auth.User
RepoInfo RepoInfo
Active string
-
Branches []types.Branch
-
Tags []*types.TagReference
types.RepoIndexResponse
}
+1 -1
appview/pages/templates/repo/blob.html
···
{{ if ne $idx (sub (len $.BreadCrumbs) 1) }}
<a href="{{ index . 1}}" class="text-bold text-gray-500 {{ $linkstyle }}">{{ index . 0 }}</a> /
{{ else }}
-
<a href="{{ index . 1}}" class="text-bold text-gray-500 {{ $linkstyle }}">{{ index . 0 }}</a>
+
<span class="text-bold text-gray-500">{{ index . 0 }}</span>
{{ end }}
{{ end }}
</div>
+5 -9
appview/pages/templates/repo/index.html
···
{{ $containerstyle := "py-1" }}
{{ $linkstyle := "no-underline hover:underline" }}
-
<div class="flex justify-end">
<select
-
hx-get="/{{ .RepoInfo.FullName }}/tree/"
-
hx-on::config-request = "event.detail.path += this.value"
-
hx-trigger="change"
-
hx-target="#repo-content"
-
hx-select="#repo-content"
-
hx-push-url="true"
+
onchange="window.location.href = '/{{ .RepoInfo.FullName }}/tree/' + this.value"
class="p-1 border border-gray-500 bg-white"
>
-
<optgroup label="branches" class="font-semibold">
+
<optgroup label="branches" class="uppercase bold text-sm">
{{ range .Branches }}
<option
value="{{ .Reference.Name }}"
class="py-1"
+
{{if eq .Reference.Name $.Ref}}selected{{end}}
>
{{ .Reference.Name }}
</option>
{{ end }}
</optgroup>
-
<optgroup label="tags" class="font-semibold">
+
<optgroup label="tags" class="uppercase bold text-sm">
{{ range .Tags }}
<option
value="{{ .Reference.Name }}"
class="py-1"
+
{{if eq .Reference.Name $.Ref}}selected{{end}}
>
{{ .Reference.Name }}
</option>
-42
appview/state/repo.go
···
return
}
-
branchesResp, err := http.Get(fmt.Sprintf("http://%s/%s/%s/branches", f.Knot, f.OwnerDid(), f.RepoName))
-
if err != nil {
-
log.Println("failed to reach knotserver for branches", err)
-
return
-
}
-
defer branchesResp.Body.Close()
-
-
tagsResp, err := http.Get(fmt.Sprintf("http://%s/%s/%s/tags", f.Knot, f.OwnerDid(), f.RepoName))
-
if err != nil {
-
log.Println("failed to reach knotserver for tags", err)
-
return
-
}
-
defer tagsResp.Body.Close()
-
-
branchesBody, err := io.ReadAll(branchesResp.Body)
-
if err != nil {
-
log.Println("failed to read branches response", err)
-
return
-
}
-
-
tagsBody, err := io.ReadAll(tagsResp.Body)
-
if err != nil {
-
log.Println("failed to read tags response", err)
-
return
-
}
-
-
var branchesResult types.RepoBranchesResponse
-
err = json.Unmarshal(branchesBody, &branchesResult)
-
if err != nil {
-
log.Println("failed to parse branches response", err)
-
return
-
}
-
-
var tagsResult types.RepoTagsResponse
-
err = json.Unmarshal(tagsBody, &tagsResult)
-
if err != nil {
-
log.Println("failed to parse tags response", err)
-
return
-
}
-
log.Println(resp.Status, result)
user := s.auth.GetUser(r)
···
SettingsAllowed: settingsAllowed(s, user, f),
},
RepoIndexResponse: result,
-
Branches: branchesResult.Branches,
-
Tags: tagsResult.Tags,
})
return
+42
knotserver/routes.go
···
return
}
}
+
commits, err := gr.Commits()
if err != nil {
writeError(w, err.Error(), http.StatusInternalServerError)
···
}
if len(commits) > 10 {
commits = commits[:10]
+
}
+
+
branches, err := gr.Branches()
+
if err != nil {
+
l.Error("getting branches", "error", err.Error())
+
writeError(w, err.Error(), http.StatusInternalServerError)
+
return
+
}
+
+
bs := []types.Branch{}
+
for _, branch := range branches {
+
b := types.Branch{}
+
b.Hash = branch.Hash().String()
+
b.Name = branch.Name().Short()
+
bs = append(bs, b)
+
}
+
+
tags, err := gr.Tags()
+
if err != nil {
+
// Non-fatal, we *should* have at least one branch to show.
+
l.Warn("getting tags", "error", err.Error())
+
}
+
+
rtags := []*types.TagReference{}
+
for _, tag := range tags {
+
tr := types.TagReference{
+
Tag: tag.TagObject(),
+
}
+
+
tr.Reference = types.Reference{
+
Name: tag.Name(),
+
Hash: tag.Hash().String(),
+
}
+
+
if tag.Message() != "" {
+
tr.Message = tag.Message()
+
}
+
+
rtags = append(rtags, &tr)
}
var readmeContent template.HTML
···
Description: getDescription(path),
Readme: readmeContent,
Files: files,
+
Branches: bs,
+
Tags: rtags,
}
writeJSON(w, resp)
+2
types/repo.go
···
Commits []*object.Commit `json:"commits,omitempty"`
Description string `json:"description,omitempty"`
Files []NiceTree `json:"files,omitempty"`
+
Branches []Branch `json:"branches,omitempty"`
+
Tags []*TagReference `json:"tags,omitempty"`
}
type RepoLogResponse struct {