diff --git a/src/backlog.rs b/src/backlog.rs new file mode 100644 index 0000000..29bcc0a --- /dev/null +++ b/src/backlog.rs @@ -0,0 +1,46 @@ +//! Interfaces for accessing and managing the backlog + +use crate::{EmptyResponse, Jira, Result}; + +#[derive(Debug, Serialize)] +struct BacklogIssues { + issues: Vec, +} + +#[derive(Debug)] +pub struct Backlog { + jira: Jira, +} + +impl Backlog { + pub fn new(jira: &Jira) -> Self { + Backlog { jira: jira.clone() } + } + + // See https://docs.atlassian.com/jira-software/REST/7.0.4/#agile/1.0/backlog + pub fn put(&self, issues: Vec) -> Result { + let data = BacklogIssues { issues }; + + self.jira.post("agile", "/backlog/issue", data) + } +} + +#[cfg(test)] +mod test { + extern crate serde_json; + + use super::*; + + #[test] + fn serialise_backlog_issue() { + let backlog = BacklogIssues { + issues: vec!["PR-1".to_owned(), "10001".to_owned(), "PR-3".to_owned()], + }; + + let result: String = serde_json::to_string(&backlog).unwrap(); + let expected = r#"{"issues":["PR-1","10001","PR-3"]}"#; + + assert_eq!(result, expected); + } + +} diff --git a/src/lib.rs b/src/lib.rs index fc8e70e..38c28b4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,6 +34,8 @@ pub mod resolution; pub use crate::boards::*; pub mod sprints; pub use crate::sprints::*; +pub mod backlog; +pub use crate::backlog::*; #[derive(Deserialize, Debug)] pub struct EmptyResponse; @@ -109,6 +111,11 @@ impl Jira { Sprints::new(self) } + // return backlog interface + pub fn backlog(&self) -> Backlog { + Backlog::new(self) + } + fn post(&self, api_name: &str, endpoint: &str, body: S) -> Result where D: DeserializeOwned, @@ -164,6 +171,7 @@ impl Jira { }), _ => { let data = if body == "" { "null" } else { &body }; + Ok(serde_json::from_str::(data)?) } } diff --git a/tests/jira_test.rs b/tests/jira_test.rs new file mode 100644 index 0000000..cae5903 --- /dev/null +++ b/tests/jira_test.rs @@ -0,0 +1,12 @@ +extern crate goji; +extern crate serde_json; + +use goji::*; + +#[test] +fn deserialise_empty_response() { + let empty_response_str = "null"; + let empty_response: EmptyResponse = serde_json::from_str(empty_response_str).unwrap(); + + assert_eq!(format!("{:#?}", empty_response), "EmptyResponse"); +}