Skip to main content

gitlab_version_req

Function gitlab_version_req 

Source
pub fn gitlab_version_req(raw: &str) -> Option<VersionReq>
Expand description

Parses raw as a semver::VersionReq, applying GitLab’s own partial-pin semantics.

Spec plan §7, rather than the semver crate’s implicit-caret default for a bare version: a partial-semver-shaped raw (1, 1.2) desugars via partial_version_req (~{raw}), everything else parses through semver::VersionReq::parse unchanged.

Shared by resolve_component_pin’s Partial arm (via partial_version_req directly, since it already knows the pin is partial-shaped) and GitlabCiRegistry::select_latest_matching’s generic requirement parsing, so the two paths cannot silently diverge on what a bare "1.2" means (#466 review M-b).

§Examples

use deps_gitlab_ci::component::gitlab_version_req;

// GitLab's tilde semantics for a bare partial pin, not the semver crate's caret default.
let req = gitlab_version_req("1.2").unwrap();
assert!(req.matches(&semver::Version::parse("1.2.9").unwrap()));
assert!(!req.matches(&semver::Version::parse("1.3.0").unwrap()));

// A non-partial-shaped requirement (an explicit operator, or already a full version)
// parses through `semver::VersionReq` unchanged.
let range = gitlab_version_req(">=1.2.0, <1.3.0").unwrap();
assert!(range.matches(&semver::Version::parse("1.2.9").unwrap()));
assert!(!range.matches(&semver::Version::parse("1.3.0").unwrap()));