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