Add prerelease self-upgrade flag - #424
Conversation
Reviewer's GuideImplements an opt-in prerelease self-upgrade path by plumbing a --pre flag from the CLI into the binary upgrader, extending the GitHub registry client to select the latest non-draft prerelease, and updating tests and docs accordingly. Sequence diagram for prerelease self-upgrade flowsequenceDiagram
actor User
participant CobraCommand as CobraCommand_upgrade
participant BinaryUpgrader
participant RepoRegistry as GithubRegistry
User->>CobraCommand: lets self upgrade --pre
CobraCommand->>CobraCommand: Flags().GetBool(pre)
CobraCommand->>CobraCommand: upgrade.WithPrerelease
CobraCommand->>BinaryUpgrader: NewBinaryUpgrader(registry, version, options)
User->>BinaryUpgrader: Upgrade(ctx)
BinaryUpgrader->>BinaryUpgrader: latestVersion(ctx)
BinaryUpgrader->>RepoRegistry: GetLatestPrerelease(ctx)
RepoRegistry-->>BinaryUpgrader: tagName
BinaryUpgrader->>RepoRegistry: DownloadReleaseBinary(ctx, packageName, tagName, os, arch)
RepoRegistry-->>BinaryUpgrader: binary
BinaryUpgrader->>BinaryUpgrader: backupExecutable
BinaryUpgrader->>BinaryUpgrader: replaceExecutable
BinaryUpgrader-->>User: upgraded prerelease installed
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Consider exposing a sentinel error (e.g.
var ErrNoPrerelease = errors.New(...)) for theno prerelease foundcase inGetLatestPrereleaseInfoso callers can distinguish it from other failures without relying on error message text. - The prerelease lookup currently fetches only the first 100 releases (
per_page=100) without pagination, which may miss the true latest prerelease on repos with many releases; consider adding pagination or documenting this limitation if it’s acceptable.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider exposing a sentinel error (e.g. `var ErrNoPrerelease = errors.New(...)`) for the `no prerelease found` case in `GetLatestPrereleaseInfo` so callers can distinguish it from other failures without relying on error message text.
- The prerelease lookup currently fetches only the first 100 releases (`per_page=100`) without pagination, which may miss the true latest prerelease on repos with many releases; consider adding pagination or documenting this limitation if it’s acceptable.
## Individual Comments
### Comment 1
<location path="internal/upgrade/registry/registry.go" line_range="253-262" />
<code_context>
+ url := reg.apiURI + "/releases?per_page=100"
</code_context>
<issue_to_address>
**issue:** Hard-coded per_page=100 may miss the actual latest prerelease if there are many releases
Using GitHub’s max `per_page=100` is fine, but if a repo has >100 releases, you may miss a newer prerelease on later pages and pick an older one. If this is plausible for your use case, either document that only the first 100 releases are considered or add basic pagination (e.g., follow `Link` headers up to a sane page limit).
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| url := reg.apiURI + "/releases?per_page=100" | ||
|
|
||
| req, err := http.NewRequestWithContext( | ||
| requestCtx, | ||
| http.MethodGet, | ||
| url, | ||
| nil, | ||
| ) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to create request: %w", err) |
There was a problem hiding this comment.
issue: Hard-coded per_page=100 may miss the actual latest prerelease if there are many releases
Using GitHub’s max per_page=100 is fine, but if a repo has >100 releases, you may miss a newer prerelease on later pages and pick an older one. If this is plausible for your use case, either document that only the first 100 releases are considered or add basic pagination (e.g., follow Link headers up to a sane page limit).
Summary
Adds an opt-in
lets self upgrade --preflag for upgrading to the latest GitHub prerelease while leaving the defaultlets self upgradepath on stable releases.Changes
--preonlets self upgrade.Validation
lets fmtgo test ./...lets test-bats no_lets_file.batslets lintgo run ./cmd/lets self upgrade --helpSummary by Sourcery
Add support for upgrading the CLI to prerelease versions and wire it through the self-upgrade command and docs.
New Features:
Documentation:
Tests: