Commit 52746022 authored by Christophe Labouisse's avatar Christophe Labouisse
Browse files

Cleanup milestone:

@BREAKING CHANGES!i

- Make symetric constructor for group & project milestone
- Merge `Milestone::create*` method by removing thei
  `project_id`/`group_id` parameter

Issue #23
parent 71c00d51
Pipeline #158181 passed with stages
in 5 minutes and 52 seconds
...@@ -1198,32 +1198,15 @@ impl Gitlab { ...@@ -1198,32 +1198,15 @@ impl Gitlab {
} }
/// Create a new milestone /// Create a new milestone
pub fn create_milestone( pub fn create_milestone(&self, milestone: Milestone) -> GitlabResult<Milestone> {
&self, let path: String;
project: ProjectId,
milestone: Milestone,
) -> GitlabResult<Milestone> {
let path = format!("projects/{}/milestones", project);
self.create_generic_milestone(path, milestone)
}
/// Create a new group milestone if let Some(project) = milestone.project_id {
pub fn create_group_milestone( path = format!("projects/{}/milestones", project);
&self, } else {
group: GroupId, path = format!("groups/{}/milestones", milestone.group_id.unwrap());
milestone: Milestone, }
) -> GitlabResult<Milestone> {
let path = format!("groups/{}/milestones", group);
self.create_generic_milestone(path, milestone)
}
fn create_generic_milestone(
&self,
path: String,
milestone: Milestone,
) -> GitlabResult<Milestone> {
let mut params: Vec<(&str, String)> = Vec::new(); let mut params: Vec<(&str, String)> = Vec::new();
params.push(("title", milestone.title)); params.push(("title", milestone.title));
......
...@@ -1189,7 +1189,7 @@ pub struct Milestone { ...@@ -1189,7 +1189,7 @@ pub struct Milestone {
impl Milestone { impl Milestone {
/// Create a new blank milestone: it needs at least the ProjectId and title /// Create a new blank milestone: it needs at least the ProjectId and title
/// ProjectId and title are mandatory for new milestone API of Gitlab /// ProjectId and title are mandatory for new milestone API of Gitlab
pub fn new(project_id: ProjectId, title: String) -> Milestone { pub fn new_for_project(project_id: ProjectId, title: String) -> Milestone {
Milestone { Milestone {
id: MilestoneId::new(0), id: MilestoneId::new(0),
iid: MilestoneInternalId::new(0), iid: MilestoneInternalId::new(0),
...@@ -1206,7 +1206,7 @@ impl Milestone { ...@@ -1206,7 +1206,7 @@ impl Milestone {
} }
/// Create a new blank group milestone: it needs at least the GroupId and title /// Create a new blank group milestone: it needs at least the GroupId and title
/// GroupId and title are mandatory for new milestone API of Gitlab /// GroupId and title are mandatory for new milestone API of Gitlab
pub fn new_group(group_id: GroupId, title: String) -> Milestone { pub fn new_for_group(group_id: GroupId, title: String) -> Milestone {
Milestone { Milestone {
id: MilestoneId::new(0), id: MilestoneId::new(0),
iid: MilestoneInternalId::new(0), iid: MilestoneInternalId::new(0),
......
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