Skip to content

refactor: ExtraOr, MustExtra #5685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 28, 2025
Merged

refactor: ExtraOr, MustExtra #5685

merged 2 commits into from
Mar 28, 2025

Conversation

caarlos0
Copy link
Member

  • a lot of places ExtraOr is being used we actually expect the key to be there
  • similarly, the previous Extra behavior was kind of the same of ExtraOr in some situations

This PR:

  • improves ExtraOr by only returning or if the key doesn't exist, and panics if it cannot be cast into the expected type - which is the intended usage
  • removes the Extra function
  • adds a MustExtra function which panics if the key doesn't exist, or if it cannot be cast to the expected type

@caarlos0 caarlos0 added the bug Something isn't working label Mar 28, 2025
@caarlos0 caarlos0 requested a review from Copilot March 28, 2025 02:25
@caarlos0 caarlos0 self-assigned this Mar 28, 2025
@pull-request-size pull-request-size bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Mar 28, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors how extra metadata is accessed in artifacts by replacing usage of Extra and ExtraOr with MustExtra, simplifying error handling by panicking when keys are missing or type assertions fail. It also removes the legacy Extra behavior and introduces the MustExtra function.

  • Replaces fallback logic with panic-based error handling for incorrectly set or missing keys.
  • Removes the Extra function and updates various tests and pipeline modules to use MustExtra consistently.
  • Adjusts related logic (e.g. in brew and archive code) to use the new MustExtra and artifact.Ext() helpers.

Reviewed Changes

Copilot reviewed 23 out of 25 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/pipe/scoop/scoop_test.go Updated tests to work with MustExtra usage changes.
internal/pipe/scoop/scoop.go Refactored artifact extra fetching via MustExtra.
internal/pipe/nix/nix.go Updated key fetching with cmp.Or and MustExtra.
internal/pipe/nfpm/nfpm_test.go Replaced ExtraOr calls with MustExtra.
internal/pipe/krew/krew.go Changed extra handling to use MustExtra.
internal/pipe/docker/{docker_test.go, docker.go} Replaced error-based extra fetching with MustExtra.
internal/pipe/chocolatey/chocolatey.go Updated to use MustExtra in publishing logic.
internal/pipe/checksums/checksums_test.go Updated to use MustExtra instead of Extra.
internal/pipe/brew/{brew_test.go, brew.go} Changed extra fetching; in brew.go ensure fallback removal.
internal/pipe/aursources/aursources.go Updated formatting extraction to use artifact.Format().
internal/pipe/aur/aur.go Refactored for MustExtra extractions.
internal/pipe/archive/{archive_test.go, archive.go} Replaced ExtraOr with MustExtra and artifact.Ext().
internal/artifact/{artifact_test.go, artifact.go} Central refactor of extra handling and tests.
Files not reviewed (2)
  • internal/pipe/scoop/testdata/TestRunPipePullRequest.json.golden: Language not supported
  • internal/pipe/scoop/testdata/Test_doRun/git_remote.json.golden: Language not supported
Comments suppressed due to low confidence (2)

internal/pipe/brew/brew.go:370

  • [nitpick] Replacing the default fallback with MustExtra here can lead to panics if 'ExtraBinary' is missing; ensure that 'ExtraBinary' is always populated or provide an explicit default to avoid runtime issues.
bin := artifact.MustExtra[string](*art, artifact.ExtraBinary)

internal/artifact/artifact_test.go:483

  • [nitpick] The test for unmarshal error depends on an exact JSON error message, which might change with library updates; consider checking for a substring or error type to make the test more resilient.
require.PanicsWithError(t, "json: unknown field \"repository\"", func() {

Copy link

codecov bot commented Mar 28, 2025

Codecov Report

Attention: Patch coverage is 95.91837% with 2 lines in your changes missing coverage. Please review.

Project coverage is 82.99%. Comparing base (bac3b81) to head (dc5a150).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/pipe/winget/winget.go 75.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5685      +/-   ##
==========================================
+ Coverage   82.81%   82.99%   +0.18%     
==========================================
  Files         158      158              
  Lines       15579    15545      -34     
==========================================
  Hits        12901    12901              
+ Misses       2111     2088      -23     
+ Partials      567      556      -11     

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

@caarlos0 caarlos0 mentioned this pull request Mar 28, 2025
@caarlos0 caarlos0 merged commit 8bca8c2 into main Mar 28, 2025
18 checks passed
@caarlos0 caarlos0 deleted the extra-or-2 branch March 28, 2025 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant