-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move versioning into its own support crate
Multiple components in application-services need to filter for the exact firefox version. Instead of duplicating the code, we move it into its own support crate, which other components can now make use of.
- Loading branch information
Showing
18 changed files
with
142 additions
and
56 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "firefox-versioning" | ||
version = "0.1.0" | ||
authors = ["Nimbus Team <[email protected]>"] | ||
license = "MPL-2.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
serde_json = "1.0" | ||
thiserror = "1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
use crate::error::VersionParsingError; | ||
use crate::version::Version; | ||
use serde_json::{json, Value}; | ||
use std::convert::TryFrom; | ||
|
||
pub type Result<T, E = VersionParsingError> = std::result::Result<T, E>; | ||
|
||
pub fn version_compare(args: &[Value]) -> Result<Value> { | ||
let curr_version = args.first().ok_or_else(|| { | ||
VersionParsingError::ParseError("current version doesn't exist in jexl transform".into()) | ||
})?; | ||
let curr_version = curr_version.as_str().ok_or_else(|| { | ||
VersionParsingError::ParseError("current version in jexl transform is not a string".into()) | ||
})?; | ||
let min_version = args.get(1).ok_or_else(|| { | ||
VersionParsingError::ParseError("minimum version doesn't exist in jexl transform".into()) | ||
})?; | ||
let min_version = min_version.as_str().ok_or_else(|| { | ||
VersionParsingError::ParseError("minimum version is not a string in jexl transform".into()) | ||
})?; | ||
let min_version = Version::try_from(min_version)?; | ||
let curr_version = Version::try_from(curr_version)?; | ||
Ok(json!(if curr_version > min_version { | ||
1 | ||
} else if curr_version < min_version { | ||
-1 | ||
} else { | ||
0 | ||
})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
/// The `VersioningError` indicates that a Firefox Version, being passed down as a `String`, | ||
/// cannot be parsed into a `Version`. | ||
/// | ||
/// It can either be caused by a non-ASCII character or a integer overflow. | ||
#[derive(Debug, PartialEq, thiserror::Error)] | ||
pub enum VersionParsingError { | ||
/// Indicates that a number overflowed. | ||
#[error("Overflow Error: {0}")] | ||
Overflow(String), | ||
/// Indicates a general parsing error. | ||
#[error("Parsing Error: {0}")] | ||
ParseError(String), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
pub mod compare; | ||
pub mod error; | ||
pub mod version; |
Oops, something went wrong.