Skip to content

refactor: reorganize nar and narinfo helper logic into dedicated packages#821

Merged
kalbasit merged 3 commits intomainfrom
refactor-nar-narinfo-helper-packages
Feb 10, 2026
Merged

refactor: reorganize nar and narinfo helper logic into dedicated packages#821
kalbasit merged 3 commits intomainfrom
refactor-nar-narinfo-helper-packages

Conversation

@kalbasit
Copy link
Owner

Move NAR and NarInfo helper functions (file path generation and hash validation) from the generic pkg/helper package to specialized pkg/nar and pkg/narinfo packages. This change improves the internal architecture by co-locating logic with the data types they operate on, making the codebase more discoverable and maintainable.

Key changes:

  • Created pkg/nar package with FilePath and ValidateHash logic.
  • Created pkg/narinfo package with FilePath and ValidateHash logic.
  • Updated pkg/storage/local and pkg/storage/s3 to use these new packages.
  • Simplified pkg/helper to only contain the generic FilePathWithSharding logic.
  • Migrated all relevant tests and updated import paths across the project.

…ages

Move NAR and NarInfo helper functions (file path generation and hash validation) from the generic pkg/helper package to specialized pkg/nar and pkg/narinfo packages. This change improves the internal architecture by co-locating logic with the data types they operate on, making the codebase more discoverable and maintainable.

Key changes:
- Created pkg/nar package with FilePath and ValidateHash logic.
- Created pkg/narinfo package with FilePath and ValidateHash logic.
- Updated pkg/storage/local and pkg/storage/s3 to use these new packages.
- Simplified pkg/helper to only contain the generic FilePathWithSharding logic.
- Migrated all relevant tests and updated import paths across the project.
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request go Pull requests that update go code labels Feb 10, 2026
@dosubot
Copy link

dosubot bot commented Feb 10, 2026

Related Documentation

Checked 7 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

Copy link
Owner Author

kalbasit commented Feb 10, 2026

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @kalbasit, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the codebase by reorganizing helper functions related to NAR and NarInfo file path generation and hash validation. Previously located in a general pkg/helper package, these functions have been moved into specialized pkg/nar and pkg/narinfo packages. This change enhances the internal architecture by improving modularity, making the code more discoverable, and increasing maintainability by co-locating logic with the specific data types it operates on.

Highlights

  • New pkg/nar package: Created a dedicated pkg/nar package to encapsulate FilePath and ValidateHash logic specifically for NAR files.
  • New pkg/narinfo package: Introduced a pkg/narinfo package to house FilePath and ValidateHash logic tailored for NarInfo files.
  • Simplified pkg/helper: Refactored pkg/helper to retain only the generic FilePathWithSharding function, removing NAR and NarInfo specific helpers.
  • Updated storage implementations: Modified pkg/storage/local and pkg/storage/s3 to consume the newly organized functions from pkg/nar and pkg/narinfo.
  • Migrated tests and imports: All relevant tests and import paths across the project were updated to reflect the new package structure.
Changelog
  • pkg/helper/filepath.go
    • Removed NAR and NarInfo specific file path generation and hash validation functions.
    • Retained only the generic FilePathWithSharding function.
  • pkg/helper/filepath_test.go
    • Removed tests for NAR and NarInfo file path generation.
  • pkg/nar/filepath.go
    • Added FilePath function for NAR files.
  • pkg/nar/filepath_test.go
    • Added tests for nar.FilePath.
  • pkg/nar/hash.go
    • Added ValidateHash function for NAR hashes.
  • pkg/nar/url.go
    • Updated the NAR URL regular expression to use the new narHashPattern.
    • Modified ToFilePath to use the new nar.FilePath function.
  • pkg/narinfo/narinfo.go
    • Added ValidateHash and FilePath functions for NarInfo files.
  • pkg/narinfo/narinfo_test.go
    • Added tests for narinfo.FilePath.
  • pkg/ncps/migrate_narinfo_test.go
    • Updated imports to use the new pkg/nar and pkg/narinfo packages.
    • Modified calls to NarInfoFilePath and NarFilePath to use the new package functions.
  • pkg/storage/local/local.go
    • Updated imports to use the new pkg/narinfo package.
    • Modified calls to NarInfoFilePath and narinfo.Parse to use the new package functions and aliased narinfo from go-nix to narinfopkg.
  • pkg/storage/s3/s3.go
    • Updated imports to use the new pkg/narinfo package.
    • Modified calls to narInfoPath and narinfo.Parse to use the new package functions and aliased narinfo from go-nix to narinfopkg.
Activity
  • No human activity (comments, reviews, etc.) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@kalbasit kalbasit added the backport release-0.8 Backport PR automatically label Feb 10, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a great refactoring that improves the project's architecture by moving NAR and NarInfo helper functions into their own dedicated packages. This co-location of logic with the data types they operate on makes the codebase more modular and maintainable.

I've added a couple of suggestions to further improve the changes by strengthening the hash validation logic. The current validation is quite broad, and since this refactoring is already touching this code, it's a good opportunity to make it more specific to valid Nix hash formats.

kalbasit and others added 2 commits February 9, 2026 21:03
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@kalbasit kalbasit enabled auto-merge (squash) February 10, 2026 05:11
@codecov
Copy link

codecov bot commented Feb 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.41%. Comparing base (758749c) to head (9f8fca8).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #821   +/-   ##
=======================================
  Coverage   85.41%   85.41%           
=======================================
  Files           2        2           
  Lines         480      480           
=======================================
  Hits          410      410           
  Misses         65       65           
  Partials        5        5           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kalbasit kalbasit merged commit f1a1479 into main Feb 10, 2026
16 checks passed
@kalbasit kalbasit deleted the refactor-nar-narinfo-helper-packages branch February 10, 2026 05:22
@kalbasit
Copy link
Owner Author

Backport failed for release-0.8, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin release-0.8
git worktree add -d .worktree/backport-821-to-release-0.8 origin/release-0.8
cd .worktree/backport-821-to-release-0.8
git switch --create backport-821-to-release-0.8
git cherry-pick -x f1a147977549bc5e9e2d264a4e6a6bbe3dd52586

kalbasit added a commit that referenced this pull request Feb 10, 2026
…ages (#821)

Move NAR and NarInfo helper functions (file path generation and hash
validation) from the generic pkg/helper package to specialized pkg/nar
and pkg/narinfo packages. This change improves the internal architecture
by co-locating logic with the data types they operate on, making the
codebase more discoverable and maintainable.

Key changes:
- Created pkg/nar package with FilePath and ValidateHash logic.
- Created pkg/narinfo package with FilePath and ValidateHash logic.
- Updated pkg/storage/local and pkg/storage/s3 to use these new packages.
- Simplified pkg/helper to only contain the generic FilePathWithSharding logic.
- Migrated all relevant tests and updated import paths across the project.

(cherry picked from commit f1a1479)
kalbasit added a commit that referenced this pull request Feb 10, 2026
…ages [backport #821] (#825)

Move NAR and NarInfo helper functions (file path generation and hash
validation) from the generic pkg/helper package to specialized pkg/nar
and pkg/narinfo packages. This change improves the internal architecture
by co-locating logic with the data types they operate on, making the
codebase more discoverable and maintainable.

Key changes:
- Created pkg/nar package with FilePath and ValidateHash logic.
- Created pkg/narinfo package with FilePath and ValidateHash logic.
- Updated pkg/storage/local and pkg/storage/s3 to use these new
packages.
- Simplified pkg/helper to only contain the generic FilePathWithSharding
logic.
- Migrated all relevant tests and updated import paths across the
project.

(cherry picked from commit f1a1479)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport release-0.8 Backport PR automatically enhancement New feature or request go Pull requests that update go code size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant