Commit 4032ccdc authored by Ben Boeckel's avatar Ben Boeckel Committed by Kitware Robot
Browse files

Merge topic 'params'

b147cbff Add CreateGroupsParam argument for create_group method
3790be83 Update MSRV to 1.37. Add derive_builder  ~0.9
d81aaacc

 Update rustfmt.toml : skip_children = true
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Ben Boeckel's avatarBen Boeckel <ben.boeckel@kitware.com>
Merge-request: !192
parents 5509959a b147cbff
......@@ -50,7 +50,7 @@ before_script:
- cargo tarpaulin --frozen --exclude-files vendor --ignore-panics --all --verbose
.rust_minimum: &rust_minimum
image: "rust:1.36.0"
image: "rust:1.37.0"
variables:
CARGO_UPDATE_POLICY: newest
......
......@@ -19,6 +19,7 @@ percent-encoding = "^2.0"
reqwest = "~0.9"
rustversion = "^1.0"
thiserror = "^1.0.2"
derive_builder = "~0.9"
chrono = { version = "~0.4", features = ["serde"] }
serde = { version = "~1.0", features = ["derive"] }
......
......@@ -5,3 +5,4 @@ report_fixme = "Unnumbered"
struct_lit_single_line = false
trailing_comma = "Vertical"
license_template_path = ".license.template"
skip_children = true
......@@ -550,27 +550,41 @@ impl Gitlab {
}
/// Create a group
pub fn create_group<T: AsRef<str>, P: AsRef<str>>(
///
/// # Arguments:
/// * name: the name of the group
/// * path: the path of the group
/// * params: optional arguments for group creation
///
/// # Example
/// ```rust, no_run
/// use gitlab::{Gitlab, CreateGroupParams, GitlabBuilder};
///
/// let gitlab = GitlabBuilder::new("host", "token").build().unwrap();
/// let params = CreateGroupParams::builder()
/// .description("A description")
/// .auto_devops_enabled(false)
/// .build()
/// .unwrap();
/// gitlab.create_group("A group", "A path", Some(params));
/// ```
pub fn create_group<N: AsRef<str>, P: AsRef<str>>(
&self,
name: T,
name: N,
path: P,
parent_id: GroupId,
project_creation_level: AccessLevel,
auto_devops_enabled: T,
subgroup_creation_level: AccessLevel,
params: Option<CreateGroupParams>,
) -> GitlabResult<Group> {
let url = String::from("groups");
self.post_with_param(
url,
&[
("name", name.as_ref()),
("path", path.as_ref()),
("parent_id", &parent_id.to_string()),
("project_creation_level", project_creation_level.as_str()),
("auto_devops enabled", auto_devops_enabled.as_ref()),
("subgroup_creation_level", subgroup_creation_level.as_str()),
],
)
let mut merged_params = if let Some(p) = params {
p
} else {
CreateGroupParams::default()
};
merged_params.name = Some(name.as_ref().to_string());
merged_params.path = Some(path.as_ref().to_string());
self.post_with_param(url, &merged_params)
}
/// Get all accessible groups.
......
......@@ -11,6 +11,8 @@
#[macro_use]
extern crate log;
#[macro_use]
extern crate derive_builder;
mod crates {
// public
......
......@@ -2769,3 +2769,69 @@ impl ProjectFeatures {
}
}
}
/// Params for group creation.
///
/// Used with `create_group` method (see [doc here](../gitlab/struct.Gitlab.html#method.create_group))
#[derive(Debug, Clone, Builder, Serialize, Default)]
#[builder(default)]
#[builder(field(private))]
#[builder(setter(into, strip_option))]
pub struct CreateGroupParams {
/// The group name
#[builder(setter(skip))]
pub(crate) name: Option<String>,
/// The path of the group
#[builder(setter(skip))]
pub(crate) path: Option<String>,
/// The group description
description: Option<String>,
/// The group visibility level, can be `private`, `internal` or `public`
visibility: Option<VisibilityLevel>,
/// Prevent sharing a project with another group within this group
share_with_group_lock: Option<bool>,
/// Require all users in this group to setup two-factor authentication
require_two_factor_authentication: Option<bool>,
/// Time before two-factor authentication is enforced
two_factor_grace_period: Option<u64>,
/// Determine if developers can create projects in the group
#[builder(setter(name = "_project_creation_level"))]
project_creation_level: Option<String>,
/// Default to Auto Devops pipeline for all projects within this group
auto_devops_enabled: Option<bool>,
/// Role allowed to create subgroups
#[builder(setter(name = "_subgroup_creation_level"))]
subgroup_creation_level: Option<String>,
/// Disable email notification
emails_disabled: Option<bool>,
/// Disable the capability of a group from getting mentioned
mentions_disabled: Option<bool>,
/// Enable/disable Large File Storage (LFS) for the projects in this group
lfs_enabled: Option<bool>,
/// Allow users to request membership
request_access_enabled: Option<bool>,
/// The parent group ID for creating a nesting group
parent_id: Option<GroupId>,
/// [Gitlab Starter and higher] pipeline minutes quota for this group
shared_runners_minutes_limit: Option<u64>,
/// [Gitlab Starter and higher] extra pipeline minutes quota for this group
extra_shared_runners_minutes_limit: Option<u64>,
}
impl CreateGroupParams {
pub fn builder() -> CreateGroupParamsBuilder {
CreateGroupParamsBuilder::default()
}
}
impl CreateGroupParamsBuilder {
pub fn project_creation_level(&mut self, level: AccessLevel) -> &mut Self {
self.project_creation_level = Some(Some(level.as_str().to_string()));
self
}
pub fn subgroup_creation_level(&mut self, level: AccessLevel) -> &mut Self {
self.subgroup_creation_level = Some(Some(level.as_str().to_string()));
self
}
}
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