detached aa8f6c2

fix: extract helpers to reduce cyclomatic complexity in attachments push

commit
aa8f6c2f45fd2d9230f805d6db031350ee2afafd
author
brice · · 2026-03-14 09:50 UTC
parent
1e66d5a
signature
unsigned
1 file · +17 -12
M internal/adapters/in/cli/attachments_push.go +17 -12
@@ -77,6 +77,18 @@ func runAttachmentsPush(ctx context.Context, imageArg, tag string, build bool, p
7777
7878 versionRef, latestRef := resolveImageRefs(registry, imageName, version)
7979
80+ if err := printAttachmentPushInfo(out, imageArg, targets, versionRef, latestRef, version); err != nil {
81+ return err
82+ }
83+
84+ if err := performAttachmentPush(ctx, build, version, platform, dockerfile, buildArgs, registry, imageName, versionRef, latestRef); err != nil {
85+ return err
86+ }
87+
88+ return cliWriteLine(out, styles.RenderSuccess("Push complete"))
89+}
90+
91+func printAttachmentPushInfo(out io.Writer, imageArg string, targets []string, versionRef, latestRef, version string) error {
8092 if err := cliWritef(out, "Attachment image: %s\n", styles.Theme.Bold.Render(imageArg)); err != nil {
8193 return err
8294 }
@@ -91,21 +103,14 @@ func runAttachmentsPush(ctx context.Context, imageArg, tag string, build bool, p
91103 return err
92104 }
93105 }
106+ return nil
107+}
94108
109+func performAttachmentPush(ctx context.Context, build bool, version, platform, dockerfile string, buildArgs []string, registry, imageName, versionRef, latestRef string) error {
95110 if build {
96- if err := buildAndPushFn(ctx, version, platform, dockerfile, buildArgs, versionRef, latestRef); err != nil {
97- return err
98- }
99- } else {
100- if err := tagAndPushFn(ctx, registry, imageName, version, versionRef, latestRef); err != nil {
101- return err
102- }
111+ return buildAndPushFn(ctx, version, platform, dockerfile, buildArgs, versionRef, latestRef)
103112 }
104-
105- if err := cliWriteLine(out, styles.RenderSuccess("Push complete")); err != nil {
106- return err
107- }
108- return nil
113+ return tagAndPushFn(ctx, registry, imageName, version, versionRef, latestRef)
109114 }
110115
111116 func resolveAttachmentImage(ctx context.Context, cp ControlPlane, imageArg string) (registry, imageName string, targets []string, err error) {
@@ -77,6 +77,18 @@ func runAttachmentsPush(ctx context.Context, imageArg, tag string, build bool, p
77 77
78 versionRef, latestRef := resolveImageRefs(registry, imageName, version)78 versionRef, latestRef := resolveImageRefs(registry, imageName, version)
79 79
80+ if err := printAttachmentPushInfo(out, imageArg, targets, versionRef, latestRef, version); err != nil {
81+ return err
82+ }
83+
84+ if err := performAttachmentPush(ctx, build, version, platform, dockerfile, buildArgs, registry, imageName, versionRef, latestRef); err != nil {
85+ return err
86+ }
87+
88+ return cliWriteLine(out, styles.RenderSuccess("Push complete"))
89+}
90+
91+func printAttachmentPushInfo(out io.Writer, imageArg string, targets []string, versionRef, latestRef, version string) error {
80 if err := cliWritef(out, "Attachment image: %s\n", styles.Theme.Bold.Render(imageArg)); err != nil {92 if err := cliWritef(out, "Attachment image: %s\n", styles.Theme.Bold.Render(imageArg)); err != nil {
81 return err93 return err
82 }94 }
@@ -91,21 +103,14 @@ func runAttachmentsPush(ctx context.Context, imageArg, tag string, build bool, p
91 return err103 return err
92 }104 }
93 }105 }
106+ return nil
107+}
94 108
109+func performAttachmentPush(ctx context.Context, build bool, version, platform, dockerfile string, buildArgs []string, registry, imageName, versionRef, latestRef string) error {
95 if build {110 if build {
96- if err := buildAndPushFn(ctx, version, platform, dockerfile, buildArgs, versionRef, latestRef); err != nil {111+ return buildAndPushFn(ctx, version, platform, dockerfile, buildArgs, versionRef, latestRef)
97- return err
98- }
99- } else {
100- if err := tagAndPushFn(ctx, registry, imageName, version, versionRef, latestRef); err != nil {
101- return err
102- }
103 }112 }
104-113+ return tagAndPushFn(ctx, registry, imageName, version, versionRef, latestRef)
105- if err := cliWriteLine(out, styles.RenderSuccess("Push complete")); err != nil {
106- return err
107- }
108- return nil
109 }114 }
110 115
111 func resolveAttachmentImage(ctx context.Context, cp ControlPlane, imageArg string) (registry, imageName string, targets []string, err error) {116 func resolveAttachmentImage(ctx context.Context, cp ControlPlane, imageArg string) (registry, imageName string, targets []string, err error) {

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