Skip to content

Commit

Permalink
Added assign() method on Issues
Browse files Browse the repository at this point in the history
  • Loading branch information
expobrain committed Aug 20, 2018
1 parent 2a28f5f commit cc2e4a0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use url::form_urlencoded;

// Ours
use {Board, Issue, Jira, Result, SearchOptions};
use {Board, EmptyResponse, Issue, Jira, Result, SearchOptions};

/// issue options
#[derive(Debug)]
Expand Down Expand Up @@ -75,6 +75,14 @@ pub struct IssueResults {
pub issues: Vec<Issue>,
}

impl Assignee {
pub fn new(name: &str) -> Self {
Assignee {
name: name.to_string(),
}
}
}

impl Issues {
pub fn new(jira: &Jira) -> Issues {
Issues { jira: jira.clone() }
Expand Down Expand Up @@ -108,6 +116,14 @@ impl Issues {
pub fn iter<'a>(&self, board: &'a Board, options: &'a SearchOptions) -> Result<IssuesIter<'a>> {
IssuesIter::new(board, options, &self.jira)
}

/// Assigne an issue to an user
/// https://docs.atlassian.com/software/jira/docs/api/REST/latest/#api/2/issue-assign
pub fn assign(&self, issue_id: &str, assignee: &Assignee) -> Result<EmptyResponse> {
let path = format!("/issue/{}/assignee", issue_id);

self.jira.put("api", &path, &assignee)
}
}

/// provides an iterator over multiple pages of search results
Expand Down
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ impl Jira {
self.request::<D>(Method::Post, api_name, endpoint, Some(data.into_bytes()))
}

fn put<D, S>(&self, api_name: &str, endpoint: &str, body: S) -> Result<D>
where
D: DeserializeOwned,
S: Serialize,
{
let data = serde_json::to_string::<S>(&body)?;
debug!("Json request: {}", data);
self.request::<D>(Method::Put, api_name, endpoint, Some(data.into_bytes()))
}

fn get<D>(&self, api_name: &str, endpoint: &str) -> Result<D>
where
D: DeserializeOwned,
Expand Down

0 comments on commit cc2e4a0

Please sign in to comment.