Skip to content

Extract go version constraint from go.mod#1457

Merged
j178 merged 1 commit intomasterfrom
go-version
Jan 22, 2026
Merged

Extract go version constraint from go.mod#1457
j178 merged 1 commit intomasterfrom
go-version

Conversation

@j178
Copy link
Owner

@j178 j178 commented Jan 22, 2026

Closes #987

@j178 j178 added the enhancement New feature or request label Jan 22, 2026
@codecov
Copy link

codecov bot commented Jan 22, 2026

Codecov Report

❌ Patch coverage is 94.25287% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.99%. Comparing base (f10484a) to head (974384b).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
crates/prek/src/languages/golang/gomod.rs 92.09% 14 Missing ⚠️
crates/prek/src/languages/golang/version.rs 98.78% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1457      +/-   ##
==========================================
+ Coverage   90.87%   90.99%   +0.11%     
==========================================
  Files          86       86              
  Lines       17924    18182     +258     
==========================================
+ Hits        16289    16545     +256     
- Misses       1635     1637       +2     

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

@github-actions
Copy link

github-actions bot commented Jan 22, 2026

📦 Cargo Bloat Comparison

Binary size change: +0.00% (22.8 MiB → 22.8 MiB)

Expand for cargo-bloat output

Head Branch Results

 File  .text    Size        Crate Name
 0.3%   0.8% 72.5KiB        prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.2%   0.6% 58.0KiB         prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.6% 53.0KiB         prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 46.3KiB         prek prek::run::{{closure}}
 0.2%   0.5% 43.6KiB         prek prek::cli::run::run::run::{{closure}}
 0.2%   0.5% 42.7KiB         prek prek::identify::by_extension::{{closure}}
 0.2%   0.4% 36.5KiB         prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.1%   0.3% 32.0KiB        prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.3% 30.0KiB  serde_json? <&mut serde_json::de::Deserializer<R> as serde_core::de::Deserializer>::deserialize_struct
 0.1%   0.2% 22.3KiB         prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 22.0KiB         prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 21.5KiB         prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 21.3KiB clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 20.0KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 19.7KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 19.6KiB         prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
 0.1%   0.2% 18.8KiB         prek prek::hook::HookBuilder::build::{{closure}}
 0.1%   0.2% 18.8KiB         prek prek::hook::HookBuilder::build::{{closure}}
 0.1%   0.2% 18.8KiB         prek prek::hook::HookBuilder::build::{{closure}}
 0.1%   0.2% 18.6KiB         ring ring_core_0_17_14__x25519_ge_frombytes_vartime
36.9%  91.6%  8.4MiB              And 20036 smaller methods. Use -n N to show more.
40.3% 100.0%  9.2MiB              .text section size, the file size is 22.8MiB

Base Branch Results

 File  .text    Size        Crate Name
 0.3%   0.8% 72.5KiB        prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.2%   0.6% 58.0KiB         prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.6% 53.0KiB         prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 46.3KiB         prek prek::run::{{closure}}
 0.2%   0.5% 43.8KiB         prek prek::cli::run::run::run::{{closure}}
 0.2%   0.5% 42.7KiB         prek prek::identify::by_extension::{{closure}}
 0.2%   0.4% 36.5KiB         prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.1%   0.3% 32.0KiB        prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.3% 30.0KiB  serde_json? <&mut serde_json::de::Deserializer<R> as serde_core::de::Deserializer>::deserialize_struct
 0.1%   0.2% 22.3KiB         prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 22.0KiB         prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 21.3KiB clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 21.2KiB         prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 20.0KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 19.6KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 19.6KiB         prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
 0.1%   0.2% 18.6KiB         ring ring_core_0_17_14__x25519_ge_frombytes_vartime
 0.1%   0.2% 18.2KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 18.2KiB   hyper_util hyper_util::client::legacy::client::Client<C,B>::send_request::{{closure}}
 0.1%   0.2% 18.1KiB    [Unknown] fe_loose_invert
36.9%  91.6%  8.4MiB              And 20046 smaller methods. Use -n N to show more.
40.3% 100.0%  9.2MiB              .text section size, the file size is 22.8MiB

Copy link
Contributor

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 implements automatic extraction of Go version constraints from go.mod files for remote hooks, addressing issue #987. Previously, users had to manually specify language_version for Go hooks when the remote hook required a specific Go version; now prek automatically reads the go or toolchain directives from the remote hook's go.mod file.

Changes:

  • Implemented go.mod parsing to extract go and toolchain directives
  • Added version normalization to convert Go versions (e.g., "1.23") to semver ranges (e.g., ">= 1.23.0")
  • Enhanced error messages in the Go installer to include the version constraint being resolved
  • Added Display implementation for GoRequest to support better error messages
  • Added comprehensive unit tests for parsing, normalization, and Display implementation
  • Added integration test verifying the end-to-end flow with an unrealistic version

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
crates/prek/src/languages/golang/gomod.rs Implements parsing of go.mod files to extract go and toolchain directives, version normalization, and integration with hook metadata extraction
crates/prek/src/languages/golang/version.rs Adds Display implementation for GoRequest enum and comprehensive unit tests for parsing, matching, and display functionality
crates/prek/src/languages/golang/installer.rs Improves error messages to include the version constraint being resolved
crates/prek/tests/languages/golang.rs Adds integration test verifying automatic version extraction from remote hook's go.mod file

@j178 j178 marked this pull request as ready for review January 22, 2026 09:46
@j178 j178 merged commit eee6fc3 into master Jan 22, 2026
22 checks passed
@j178 j178 deleted the go-version branch January 22, 2026 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Needs language_version for go with gitleaks whereas pre-commit does not

1 participant