Allow milestones to be closed and reopened
This commit is contained in:
@@ -130,6 +130,7 @@ pub struct MilestoneDraft {
|
||||
pub title: String,
|
||||
pub description: String,
|
||||
pub due_on: Option<String>,
|
||||
pub state: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
||||
@@ -164,6 +164,11 @@ impl Client {
|
||||
"milestone title must not be empty".into(),
|
||||
));
|
||||
}
|
||||
if !matches!(draft.state.as_str(), "open" | "closed") {
|
||||
return Err(Error::InvalidInput(
|
||||
"milestone state must be open or closed".into(),
|
||||
));
|
||||
}
|
||||
let endpoint = match id {
|
||||
Some(id) if id > 0 => format!(
|
||||
"repos/{}/{}/milestones/{id}",
|
||||
@@ -194,6 +199,7 @@ impl Client {
|
||||
title: draft.title,
|
||||
description: draft.description,
|
||||
due_on: draft.due_on,
|
||||
state: draft.state,
|
||||
});
|
||||
self.execute(request)
|
||||
.await?
|
||||
@@ -219,6 +225,7 @@ struct MilestoneRequest {
|
||||
title: String,
|
||||
description: String,
|
||||
due_on: Option<String>,
|
||||
state: String,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -231,8 +238,10 @@ mod tests {
|
||||
title: "Release".into(),
|
||||
description: String::new(),
|
||||
due_on: None,
|
||||
state: "closed".into(),
|
||||
})
|
||||
.unwrap();
|
||||
assert!(value.get("due_on").unwrap().is_null());
|
||||
assert_eq!(value["state"], "closed");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user