Commit 7b5b1168 authored by Ben Boeckel's avatar Ben Boeckel
Browse files

api/common: impl From<bool> for EnableState

parent 09277528
......@@ -6,6 +6,7 @@
changed to match the actual API exposed by GitLab (with `None` and `Any`
options).
* The `api::projects::pipelines::PipelineVariables` endpoint is now pageable.
* All `EnableState` fields may now be set using `bool` values.
# v0.1210.2
......
......@@ -113,6 +113,16 @@ impl EnableState {
}
}
impl From<bool> for EnableState {
fn from(b: bool) -> Self {
if b {
EnableState::Enabled
} else {
EnableState::Disabled
}
}
}
impl ParamValue<'static> for EnableState {
fn as_value(self) -> Cow<'static, str> {
self.as_str().into()
......@@ -315,6 +325,15 @@ mod tests {
}
}
#[test]
fn enable_state_from_bool() {
let items = &[(EnableState::Enabled, true), (EnableState::Disabled, false)];
for (i, s) in items {
assert_eq!(*i, (*s).into());
}
}
#[test]
fn name_or_id_as_str() {
let items: &[(NameOrId, _)] = &[
......
......@@ -504,7 +504,7 @@ pub struct CreateProject<'a> {
build_timeout: Option<u64>,
/// Whether to automatically cancel pipelines when branches are updated when using a previous
/// version of th branch.
#[builder(default)]
#[builder(setter(into), default)]
auto_cancel_pending_pipelines: Option<EnableState>,
/// The default regular expression to use for build coverage extraction.
#[builder(setter(into), default)]
......
......@@ -127,7 +127,7 @@ pub struct EditProject<'a> {
build_timeout: Option<u64>,
/// Whether to automatically cancel pipelines when branches are updated when using a previous
/// version of th branch.
#[builder(default)]
#[builder(setter(into), default)]
auto_cancel_pending_pipelines: Option<EnableState>,
/// The default regular expression to use for build coverage extraction.
#[builder(setter(into), default)]
......
......@@ -118,7 +118,7 @@ pub struct Users<'a> {
#[builder(default)]
sort: Option<SortOrder>,
/// Return users with a two-factor enabled or not.
#[builder(default)]
#[builder(setter(into), default)]
two_factor: Option<EnableState>,
/// If set to `true`, filter out users without any projects.
#[builder(default)]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment