v0.23.2 bfd5eb4

check_update.go RawHistoryFolder

1package usecase
2
3import (
4	"context"
5
6	"github.com/bnema/dumber/internal/application/port"
7	"github.com/bnema/dumber/internal/domain/build"
8	"github.com/bnema/dumber/internal/logging"
9)
10
11// CheckUpdateInput holds the input for the check update use case.
12type CheckUpdateInput struct{}
13
14// CheckUpdateOutput holds the result of the update check.
15type CheckUpdateOutput struct {
16	// UpdateAvailable is true if a newer version exists.
17	UpdateAvailable bool
18	// CanAutoUpdate is true if the binary is writable and auto-update is possible.
19	CanAutoUpdate bool
20	// CurrentVersion is the version of the running binary.
21	CurrentVersion string
22	// LatestVersion is the latest available version.
23	LatestVersion string
24	// ReleaseURL is the URL to the GitHub release page.
25	ReleaseURL string
26	// DownloadURL is the direct download URL for the archive.
27	DownloadURL string
28}
29
30// CheckUpdateUseCase checks for available updates.
31type CheckUpdateUseCase struct {
32	checker   port.UpdateChecker
33	applier   port.UpdateApplier
34	buildInfo build.Info
35}
36
37// NewCheckUpdateUseCase creates a new check update use case.
38func NewCheckUpdateUseCase(
39	checker port.UpdateChecker,
40	applier port.UpdateApplier,
41	buildInfo build.Info,
42) *CheckUpdateUseCase {
43	return &CheckUpdateUseCase{
44		checker:   checker,
45		applier:   applier,
46		buildInfo: buildInfo,
47	}
48}
49
50// Execute checks for available updates.
51func (uc *CheckUpdateUseCase) Execute(ctx context.Context, _ CheckUpdateInput) (*CheckUpdateOutput, error) {
52	log := logging.FromContext(ctx)
53
54	info, err := uc.checker.CheckForUpdate(ctx, uc.buildInfo.Version)
55	if err != nil {
56		log.Warn().Err(err).Msg("update check failed")
57		return nil, err
58	}
59
60	canAutoUpdate := false
61	if info.IsNewer {
62		canAutoUpdate = uc.applier.CanSelfUpdate(ctx)
63	}
64
65	log.Debug().
66		Str("current", uc.buildInfo.Version).
67		Str("latest", info.LatestVersion).
68		Bool("update_available", info.IsNewer).
69		Bool("can_auto_update", canAutoUpdate).
70		Msg("update check completed")
71
72	return &CheckUpdateOutput{
73		UpdateAvailable: info.IsNewer,
74		CanAutoUpdate:   canAutoUpdate,
75		CurrentVersion:  info.CurrentVersion,
76		LatestVersion:   info.LatestVersion,
77		ReleaseURL:      info.ReleaseURL,
78		DownloadURL:     info.DownloadURL,
79	}, nil
80}

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 8

Tags 42

↑↓ moveenter openesc close