-2
appview/pages/pages.go
-2
appview/pages/pages.go
+1
-1
appview/pages/templates/repo/blob.html
+1
-1
appview/pages/templates/repo/blob.html
+5
-9
appview/pages/templates/repo/index.html
+5
-9
appview/pages/templates/repo/index.html
···
8
{{ $containerstyle := "py-1" }}
9
{{ $linkstyle := "no-underline hover:underline" }}
10
11
-
12
<div class="flex justify-end">
13
<select
14
-
hx-get="/{{ .RepoInfo.FullName }}/tree/"
15
-
hx-on::config-request = "event.detail.path += this.value"
16
-
hx-trigger="change"
17
-
hx-target="#repo-content"
18
-
hx-select="#repo-content"
19
-
hx-push-url="true"
20
class="p-1 border border-gray-500 bg-white"
21
>
22
-
<optgroup label="branches" class="font-semibold">
23
{{ range .Branches }}
24
<option
25
value="{{ .Reference.Name }}"
26
class="py-1"
27
>
28
{{ .Reference.Name }}
29
</option>
30
{{ end }}
31
</optgroup>
32
-
<optgroup label="tags" class="font-semibold">
33
{{ range .Tags }}
34
<option
35
value="{{ .Reference.Name }}"
36
class="py-1"
37
>
38
{{ .Reference.Name }}
39
</option>
···
8
{{ $containerstyle := "py-1" }}
9
{{ $linkstyle := "no-underline hover:underline" }}
10
11
<div class="flex justify-end">
12
<select
13
+
onchange="window.location.href = '/{{ .RepoInfo.FullName }}/tree/' + this.value"
14
class="p-1 border border-gray-500 bg-white"
15
>
16
+
<optgroup label="branches" class="uppercase bold text-sm">
17
{{ range .Branches }}
18
<option
19
value="{{ .Reference.Name }}"
20
class="py-1"
21
+
{{if eq .Reference.Name $.Ref}}selected{{end}}
22
>
23
{{ .Reference.Name }}
24
</option>
25
{{ end }}
26
</optgroup>
27
+
<optgroup label="tags" class="uppercase bold text-sm">
28
{{ range .Tags }}
29
<option
30
value="{{ .Reference.Name }}"
31
class="py-1"
32
+
{{if eq .Reference.Name $.Ref}}selected{{end}}
33
>
34
{{ .Reference.Name }}
35
</option>
-42
appview/state/repo.go
-42
appview/state/repo.go
···
52
return
53
}
54
55
-
branchesResp, err := http.Get(fmt.Sprintf("http://%s/%s/%s/branches", f.Knot, f.OwnerDid(), f.RepoName))
56
-
if err != nil {
57
-
log.Println("failed to reach knotserver for branches", err)
58
-
return
59
-
}
60
-
defer branchesResp.Body.Close()
61
-
62
-
tagsResp, err := http.Get(fmt.Sprintf("http://%s/%s/%s/tags", f.Knot, f.OwnerDid(), f.RepoName))
63
-
if err != nil {
64
-
log.Println("failed to reach knotserver for tags", err)
65
-
return
66
-
}
67
-
defer tagsResp.Body.Close()
68
-
69
-
branchesBody, err := io.ReadAll(branchesResp.Body)
70
-
if err != nil {
71
-
log.Println("failed to read branches response", err)
72
-
return
73
-
}
74
-
75
-
tagsBody, err := io.ReadAll(tagsResp.Body)
76
-
if err != nil {
77
-
log.Println("failed to read tags response", err)
78
-
return
79
-
}
80
-
81
-
var branchesResult types.RepoBranchesResponse
82
-
err = json.Unmarshal(branchesBody, &branchesResult)
83
-
if err != nil {
84
-
log.Println("failed to parse branches response", err)
85
-
return
86
-
}
87
-
88
-
var tagsResult types.RepoTagsResponse
89
-
err = json.Unmarshal(tagsBody, &tagsResult)
90
-
if err != nil {
91
-
log.Println("failed to parse tags response", err)
92
-
return
93
-
}
94
-
95
log.Println(resp.Status, result)
96
97
user := s.auth.GetUser(r)
···
104
SettingsAllowed: settingsAllowed(s, user, f),
105
},
106
RepoIndexResponse: result,
107
-
Branches: branchesResult.Branches,
108
-
Tags: tagsResult.Tags,
109
})
110
111
return
+42
knotserver/routes.go
+42
knotserver/routes.go
···
48
return
49
}
50
}
51
commits, err := gr.Commits()
52
if err != nil {
53
writeError(w, err.Error(), http.StatusInternalServerError)
···
56
}
57
if len(commits) > 10 {
58
commits = commits[:10]
59
}
60
61
var readmeContent template.HTML
···
109
Description: getDescription(path),
110
Readme: readmeContent,
111
Files: files,
112
}
113
114
writeJSON(w, resp)
···
48
return
49
}
50
}
51
+
52
commits, err := gr.Commits()
53
if err != nil {
54
writeError(w, err.Error(), http.StatusInternalServerError)
···
57
}
58
if len(commits) > 10 {
59
commits = commits[:10]
60
+
}
61
+
62
+
branches, err := gr.Branches()
63
+
if err != nil {
64
+
l.Error("getting branches", "error", err.Error())
65
+
writeError(w, err.Error(), http.StatusInternalServerError)
66
+
return
67
+
}
68
+
69
+
bs := []types.Branch{}
70
+
for _, branch := range branches {
71
+
b := types.Branch{}
72
+
b.Hash = branch.Hash().String()
73
+
b.Name = branch.Name().Short()
74
+
bs = append(bs, b)
75
+
}
76
+
77
+
tags, err := gr.Tags()
78
+
if err != nil {
79
+
// Non-fatal, we *should* have at least one branch to show.
80
+
l.Warn("getting tags", "error", err.Error())
81
+
}
82
+
83
+
rtags := []*types.TagReference{}
84
+
for _, tag := range tags {
85
+
tr := types.TagReference{
86
+
Tag: tag.TagObject(),
87
+
}
88
+
89
+
tr.Reference = types.Reference{
90
+
Name: tag.Name(),
91
+
Hash: tag.Hash().String(),
92
+
}
93
+
94
+
if tag.Message() != "" {
95
+
tr.Message = tag.Message()
96
+
}
97
+
98
+
rtags = append(rtags, &tr)
99
}
100
101
var readmeContent template.HTML
···
149
Description: getDescription(path),
150
Readme: readmeContent,
151
Files: files,
152
+
Branches: bs,
153
+
Tags: rtags,
154
}
155
156
writeJSON(w, resp)
+2
types/repo.go
+2
types/repo.go