Skip to content

Add prerelease self-upgrade flag - #424

Merged
kindermax merged 1 commit into
masterfrom
agent-add-self-upgrade-pre
Jul 29, 2026
Merged

Add prerelease self-upgrade flag#424
kindermax merged 1 commit into
masterfrom
agent-add-self-upgrade-pre

Conversation

@kindermax

@kindermax kindermax commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds an opt-in lets self upgrade --pre flag for upgrading to the latest GitHub prerelease while leaving the default lets self upgrade path on stable releases.

Changes

  • Registers --pre on lets self upgrade.
  • Adds a binary upgrader option that switches release selection to prereleases.
  • Adds GitHub registry support for finding the latest non-draft prerelease from the releases API.
  • Documents the new flag in installation and CLI docs, and adds a changelog entry.

Validation

  • lets fmt
  • go test ./...
  • lets test-bats no_lets_file.bats
  • lets lint
  • go run ./cmd/lets self upgrade --help

Summary by Sourcery

Add support for upgrading the CLI to prerelease versions and wire it through the self-upgrade command and docs.

New Features:

  • Add prerelease-aware release lookup in the GitHub registry, including filtering non-draft prereleases.
  • Introduce a prerelease mode for the binary upgrader and expose it via a new --pre flag on lets self upgrade.

Documentation:

  • Document the lets self upgrade --pre flag in installation and CLI docs and note it in the changelog.

Tests:

  • Add tests for prerelease selection in the GitHub registry and binary upgrader, and for wiring the --pre flag through the CLI.

@sourcery-ai

sourcery-ai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Implements 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 flow

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Add prerelease-aware release discovery in the GitHub registry client.
  • Extend RepoRegistry interface with a GetLatestPrerelease method and prerelease/draft metadata in ReleaseInfo.
  • Implement GetLatestPrerelease and GetLatestPrereleaseInfo to fetch releases from the GitHub API, filter out drafts and non-prereleases, and choose the most recently published prerelease.
  • Add tests to cover successful prerelease selection and the no-prerelease-found path, including query params and headers.
internal/upgrade/registry/registry.go
internal/upgrade/registry/registry_test.go
Teach BinaryUpgrader to upgrade to prereleases and improve logging of upgrade target.
  • Add a prerelease flag and WithPrerelease option to BinaryUpgrader to switch between stable and prerelease version resolution.
  • Refactor version lookup into latestVersion, returning both the target version and a human-readable release kind for logging and error messages.
  • Update Upgrade to use latestVersion, adjust error messages, and log whether a stable or prerelease version is being downloaded.
  • Adapt MockRegistry and notifier mocks to satisfy the extended RepoRegistry interface and use the requested version in tests.
internal/upgrade/upgrade.go
internal/upgrade/upgrade_test.go
internal/upgrade/notifier_test.go
Expose a --pre flag on lets self upgrade and ensure it is wired into the upgrader factory.
  • Update initUpgradeCommand to build BinaryUpgrader options dynamically, including WithProgress and conditionally WithPrerelease based on the --pre flag.
  • Register a Bool("pre") flag on the self upgrade command with a description indicating prerelease upgrades.
  • Add a root-level test that executes lets self upgrade --pre and verifies the flag value reaches the upgrader factory.
internal/cmd/upgrade.go
internal/cmd/root_test.go
Document prerelease self-upgrade behavior and changelog entry.
  • Document lets self upgrade --pre in the installation guide with an explicit example.
  • Extend CLI documentation to mention lets self upgrade --pre as the prerelease upgrade path.
  • Add an unreleased changelog entry describing the new prerelease self-upgrade option.
docs/docs/installation.mdx
docs/docs/cli.md
docs/docs/changelog.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@kindermax
kindermax marked this pull request as ready for review July 29, 2026 11:09
@kindermax
kindermax merged commit 465366e into master Jul 29, 2026
5 checks passed
@kindermax
kindermax deleted the agent-add-self-upgrade-pre branch July 29, 2026 11:10

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • 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.
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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +253 to +262
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant