Allow milestones to be closed and reopened

This commit is contained in:
Georg Bauer
2026-08-01 14:58:49 +02:00
parent 3a69b70395
commit 047f0ab0dc
10 changed files with 64 additions and 23 deletions

View File

@@ -130,6 +130,7 @@ pub struct MilestoneDraft {
pub title: String,
pub description: String,
pub due_on: Option<String>,
pub state: String,
}
#[derive(Clone, Debug)]

View File

@@ -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");
}
}