detached bca4041

fix: address review feedback for truncation and DTO mapping

commit
bca40419b9ab5fe5f0ad0c251f9fbdbf8f11cf21
author
brice · · 2026-01-17 13:29 UTC
parent
9e3332e
signature
unsigned
3 files · +27 -3
M internal/adapters/in/cli/routes.go +19 -0
@@ -23,6 +23,10 @@ var configPath string
2323 // For tags, truncates to maxLen with ellipsis if needed.
2424 func truncateImage(image string, maxLen int) string {
2525 // Handle digest references: image@sha256:abc123...
26+ if maxLen <= 0 {
27+ return ""
28+ }
29+
2630 if idx := strings.Index(image, "@sha256:"); idx != -1 {
2731 name := image[:idx]
2832 digest := image[idx+8:] // Skip "@sha256:"
@@ -33,8 +37,14 @@ func truncateImage(image string, maxLen int) string {
3337 if len(short) > maxLen {
3438 // Truncate from the end to maintain valid reference format
3539 if maxLen <= 3 {
40+ if len(short) < maxLen {
41+ return short
42+ }
3643 return short[:maxLen]
3744 }
45+ if len(short) <= maxLen {
46+ return short
47+ }
3848 return short[:maxLen-3] + "..."
3949 }
4050 return short
@@ -43,6 +53,9 @@ func truncateImage(image string, maxLen int) string {
4353 // Regular tag: truncate if needed
4454 if len(image) > maxLen {
4555 if maxLen <= 3 {
56+ if len(image) < maxLen {
57+ return image
58+ }
4659 return image[:maxLen]
4760 }
4861 return image[:maxLen-3] + "..."
@@ -54,8 +67,14 @@ func truncateNetwork(network string, maxLen int) string {
5467 if network == "" || network == "-" {
5568 return "-"
5669 }
70+ if maxLen <= 0 {
71+ return ""
72+ }
5773 if len(network) > maxLen {
5874 if maxLen <= 3 {
75+ if len(network) < maxLen {
76+ return network
77+ }
5978 return network[:maxLen]
6079 }
6180 return network[:maxLen-3] + "..."
@@ -23,6 +23,10 @@ var configPath string
23 // For tags, truncates to maxLen with ellipsis if needed.23 // For tags, truncates to maxLen with ellipsis if needed.
24 func truncateImage(image string, maxLen int) string {24 func truncateImage(image string, maxLen int) string {
25 // Handle digest references: image@sha256:abc123...25 // Handle digest references: image@sha256:abc123...
26+ if maxLen <= 0 {
27+ return ""
28+ }
29+
26 if idx := strings.Index(image, "@sha256:"); idx != -1 {30 if idx := strings.Index(image, "@sha256:"); idx != -1 {
27 name := image[:idx]31 name := image[:idx]
28 digest := image[idx+8:] // Skip "@sha256:"32 digest := image[idx+8:] // Skip "@sha256:"
@@ -33,8 +37,14 @@ func truncateImage(image string, maxLen int) string {
33 if len(short) > maxLen {37 if len(short) > maxLen {
34 // Truncate from the end to maintain valid reference format38 // Truncate from the end to maintain valid reference format
35 if maxLen <= 3 {39 if maxLen <= 3 {
40+ if len(short) < maxLen {
41+ return short
42+ }
36 return short[:maxLen]43 return short[:maxLen]
37 }44 }
45+ if len(short) <= maxLen {
46+ return short
47+ }
38 return short[:maxLen-3] + "..."48 return short[:maxLen-3] + "..."
39 }49 }
40 return short50 return short
@@ -43,6 +53,9 @@ func truncateImage(image string, maxLen int) string {
43 // Regular tag: truncate if needed53 // Regular tag: truncate if needed
44 if len(image) > maxLen {54 if len(image) > maxLen {
45 if maxLen <= 3 {55 if maxLen <= 3 {
56+ if len(image) < maxLen {
57+ return image
58+ }
46 return image[:maxLen]59 return image[:maxLen]
47 }60 }
48 return image[:maxLen-3] + "..."61 return image[:maxLen-3] + "..."
@@ -54,8 +67,14 @@ func truncateNetwork(network string, maxLen int) string {
54 if network == "" || network == "-" {67 if network == "" || network == "-" {
55 return "-"68 return "-"
56 }69 }
70+ if maxLen <= 0 {
71+ return ""
72+ }
57 if len(network) > maxLen {73 if len(network) > maxLen {
58 if maxLen <= 3 {74 if maxLen <= 3 {
75+ if len(network) < maxLen {
76+ return network
77+ }
59 return network[:maxLen]78 return network[:maxLen]
60 }79 }
61 return network[:maxLen-3] + "..."80 return network[:maxLen-3] + "..."
M internal/adapters/in/http/admin/handler.go +8 -1
@@ -361,12 +361,19 @@ func (h *Handler) handleNetworks(w http.ResponseWriter, r *http.Request) {
361361 if network == nil {
362362 continue
363363 }
364+ var labelsCopy map[string]string
365+ if network.Labels != nil {
366+ labelsCopy = make(map[string]string, len(network.Labels))
367+ for key, value := range network.Labels {
368+ labelsCopy[key] = value
369+ }
370+ }
364371 response = append(response, dto.Network{
365372 ID: network.ID,
366373 Name: network.Name,
367374 Driver: network.Driver,
368375 Containers: append([]string{}, network.Containers...),
369- Labels: network.Labels,
376+ Labels: labelsCopy,
370377 })
371378 }
372379
@@ -361,12 +361,19 @@ func (h *Handler) handleNetworks(w http.ResponseWriter, r *http.Request) {
361 if network == nil {361 if network == nil {
362 continue362 continue
363 }363 }
364+ var labelsCopy map[string]string
365+ if network.Labels != nil {
366+ labelsCopy = make(map[string]string, len(network.Labels))
367+ for key, value := range network.Labels {
368+ labelsCopy[key] = value
369+ }
370+ }
364 response = append(response, dto.Network{371 response = append(response, dto.Network{
365 ID: network.ID,372 ID: network.ID,
366 Name: network.Name,373 Name: network.Name,
367 Driver: network.Driver,374 Driver: network.Driver,
368 Containers: append([]string{}, network.Containers...),375 Containers: append([]string{}, network.Containers...),
369- Labels: network.Labels,376+ Labels: labelsCopy,
370 })377 })
371 }378 }
372 379
M internal/adapters/in/http/registry/handler_test.go +0 -2
@@ -94,8 +94,6 @@ func TestHandler_GetManifest_NotFound(t *testing.T) {
9494
9595 assert.Equal(t, http.StatusNotFound, rec.Code)
9696 assert.Equal(t, "application/json", rec.Header().Get("Content-Type"))
97-
98- assert.Equal(t, "application/json", rec.Header().Get("Content-Type"))
9997 }
10098
10199 func TestHandler_BlobRoutes_MethodNotAllowed(t *testing.T) {
@@ -94,8 +94,6 @@ func TestHandler_GetManifest_NotFound(t *testing.T) {
94 94
95 assert.Equal(t, http.StatusNotFound, rec.Code)95 assert.Equal(t, http.StatusNotFound, rec.Code)
96 assert.Equal(t, "application/json", rec.Header().Get("Content-Type"))96 assert.Equal(t, "application/json", rec.Header().Get("Content-Type"))
97-
98- assert.Equal(t, "application/json", rec.Header().Get("Content-Type"))
99 }97 }
100 98
101 func TestHandler_BlobRoutes_MethodNotAllowed(t *testing.T) {99 func TestHandler_BlobRoutes_MethodNotAllowed(t *testing.T) {

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close