Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added backlog() basic method #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/backlog.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//! Interfaces for accessing and managing the backlog

use crate::{EmptyResponse, Jira, Result};

#[derive(Debug, Serialize)]
struct BacklogIssues {
issues: Vec<String>,
}

#[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<String>) -> Result<EmptyResponse> {
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);
}

}
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -109,6 +111,11 @@ impl Jira {
Sprints::new(self)
}

// return backlog interface
pub fn backlog(&self) -> Backlog {
Backlog::new(self)
}

fn post<D, S>(&self, api_name: &str, endpoint: &str, body: S) -> Result<D>
where
D: DeserializeOwned,
Expand Down Expand Up @@ -164,6 +171,7 @@ impl Jira {
}),
_ => {
let data = if body == "" { "null" } else { &body };

Ok(serde_json::from_str::<D>(data)?)
}
}
Expand Down
12 changes: 12 additions & 0 deletions tests/jira_test.rs
Original file line number Diff line number Diff line change
@@ -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");
}