Skip to content
Closed
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
122 changes: 122 additions & 0 deletions src/api/issue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@ pub struct IssueCount {
pub count: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct IssueCommentCount {
pub count: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct IssueCommentNotification {
pub id: u64,
pub already_read: bool,
pub reason: u64,
pub user: IssueUser,
pub resource_already_read: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct IssueComment {
Expand Down Expand Up @@ -181,6 +196,41 @@ impl BacklogClient {
let value = self.get(&format!("/issues/{}/attachments", key))?;
deserialize(value)
}

pub fn count_issue_comments(&self, key: &str) -> Result<IssueCommentCount> {
let value = self.get(&format!("/issues/{}/comments/count", key))?;
deserialize(value)
}

pub fn get_issue_comment(&self, key: &str, comment_id: u64) -> Result<IssueComment> {
let value = self.get(&format!("/issues/{}/comments/{}", key, comment_id))?;
deserialize(value)
}

pub fn get_issue_comment_notifications(
&self,
key: &str,
comment_id: u64,
) -> Result<Vec<IssueCommentNotification>> {
let value = self.get(&format!(
"/issues/{}/comments/{}/notifications",
key, comment_id
))?;
deserialize(value)
}

pub fn add_issue_comment_notifications(
&self,
key: &str,
comment_id: u64,
params: &[(String, String)],
) -> Result<Vec<IssueCommentNotification>> {
let value = self.post_form(
&format!("/issues/{}/comments/{}/notifications", key, comment_id),
params,
)?;
deserialize(value)
}
}

#[cfg(test)]
Expand Down Expand Up @@ -397,4 +447,76 @@ mod tests {
let issue: Issue = serde_json::from_value(v).unwrap();
assert!(issue.created_user.user_id.is_none());
}

fn notification_json() -> serde_json::Value {
json!({
"id": 1,
"alreadyRead": false,
"reason": 2,
"user": issue_user_json(),
"resourceAlreadyRead": false
})
}

#[test]
fn count_issue_comments_returns_count() {
let server = MockServer::start();
server.mock(|when, then| {
when.method(GET)
.path("/issues/TEST-1/comments/count")
.query_param("apiKey", TEST_KEY);
then.status(200).json_body(json!({"count": 7}));
});
let client = super::super::BacklogClient::new_with(&server.base_url(), TEST_KEY).unwrap();
let count = client.count_issue_comments("TEST-1").unwrap();
assert_eq!(count.count, 7);
}

#[test]
fn get_issue_comment_returns_single() {
let server = MockServer::start();
server.mock(|when, then| {
when.method(GET)
.path("/issues/TEST-1/comments/1")
.query_param("apiKey", TEST_KEY);
then.status(200).json_body(comment_json());
});
let client = super::super::BacklogClient::new_with(&server.base_url(), TEST_KEY).unwrap();
let comment = client.get_issue_comment("TEST-1", 1).unwrap();
assert_eq!(comment.content.as_deref(), Some("A comment"));
}

#[test]
fn get_issue_comment_notifications_returns_list() {
let server = MockServer::start();
server.mock(|when, then| {
when.method(GET)
.path("/issues/TEST-1/comments/1/notifications")
.query_param("apiKey", TEST_KEY);
then.status(200).json_body(json!([notification_json()]));
});
let client = super::super::BacklogClient::new_with(&server.base_url(), TEST_KEY).unwrap();
let notifications = client.get_issue_comment_notifications("TEST-1", 1).unwrap();
assert_eq!(notifications.len(), 1);
assert_eq!(notifications[0].id, 1);
assert!(!notifications[0].already_read);
}

#[test]
fn add_issue_comment_notifications_returns_list() {
let server = MockServer::start();
server.mock(|when, then| {
when.method(POST)
.path("/issues/TEST-1/comments/1/notifications")
.query_param("apiKey", TEST_KEY);
then.status(200).json_body(json!([notification_json()]));
});
let client = super::super::BacklogClient::new_with(&server.base_url(), TEST_KEY).unwrap();
let params = vec![("notifiedUserId[]".to_string(), "1".to_string())];
let notifications = client
.add_issue_comment_notifications("TEST-1", 1, &params)
.unwrap();
assert_eq!(notifications.len(), 1);
assert_eq!(notifications[0].user.name, "John Doe");
}
}
42 changes: 41 additions & 1 deletion src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ pub mod wiki;

use activity::Activity;
use disk_usage::DiskUsage;
use issue::{Issue, IssueAttachment, IssueComment, IssueCount};
use issue::{
Issue, IssueAttachment, IssueComment, IssueCommentCount, IssueCommentNotification, IssueCount,
};
use notification::{Notification, NotificationCount};
use project::{
Project, ProjectCategory, ProjectDiskUsage, ProjectIssueType, ProjectStatus, ProjectUser,
Expand Down Expand Up @@ -68,6 +70,19 @@ pub trait BacklogApi {
) -> Result<IssueComment>;
fn delete_issue_comment(&self, key: &str, comment_id: u64) -> Result<IssueComment>;
fn get_issue_attachments(&self, key: &str) -> Result<Vec<IssueAttachment>>;
fn count_issue_comments(&self, key: &str) -> Result<IssueCommentCount>;
fn get_issue_comment(&self, key: &str, comment_id: u64) -> Result<IssueComment>;
fn get_issue_comment_notifications(
&self,
key: &str,
comment_id: u64,
) -> Result<Vec<IssueCommentNotification>>;
fn add_issue_comment_notifications(
&self,
key: &str,
comment_id: u64,
params: &[(String, String)],
) -> Result<Vec<IssueCommentNotification>>;
fn get_wikis(&self, params: &[(String, String)]) -> Result<Vec<WikiListItem>>;
fn get_wiki(&self, wiki_id: u64) -> Result<Wiki>;
fn create_wiki(&self, params: &[(String, String)]) -> Result<Wiki>;
Expand Down Expand Up @@ -210,6 +225,31 @@ impl BacklogApi for BacklogClient {
self.get_issue_attachments(key)
}

fn count_issue_comments(&self, key: &str) -> Result<IssueCommentCount> {
self.count_issue_comments(key)
}

fn get_issue_comment(&self, key: &str, comment_id: u64) -> Result<IssueComment> {
self.get_issue_comment(key, comment_id)
}

fn get_issue_comment_notifications(
&self,
key: &str,
comment_id: u64,
) -> Result<Vec<IssueCommentNotification>> {
self.get_issue_comment_notifications(key, comment_id)
}

fn add_issue_comment_notifications(
&self,
key: &str,
comment_id: u64,
params: &[(String, String)],
) -> Result<Vec<IssueCommentNotification>> {
self.add_issue_comment_notifications(key, comment_id, params)
}

fn get_wikis(&self, params: &[(String, String)]) -> Result<Vec<WikiListItem>> {
self.get_wikis(params)
}
Expand Down
28 changes: 28 additions & 0 deletions src/cmd/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,34 @@ mod tests {
) -> anyhow::Result<Vec<crate::api::issue::IssueAttachment>> {
unimplemented!()
}
fn count_issue_comments(
&self,
_key: &str,
) -> anyhow::Result<crate::api::issue::IssueCommentCount> {
unimplemented!()
}
fn get_issue_comment(
&self,
_key: &str,
_comment_id: u64,
) -> anyhow::Result<crate::api::issue::IssueComment> {
unimplemented!()
}
fn get_issue_comment_notifications(
&self,
_key: &str,
_comment_id: u64,
) -> anyhow::Result<Vec<crate::api::issue::IssueCommentNotification>> {
unimplemented!()
}
fn add_issue_comment_notifications(
&self,
_key: &str,
_comment_id: u64,
_params: &[(String, String)],
) -> anyhow::Result<Vec<crate::api::issue::IssueCommentNotification>> {
unimplemented!()
}
fn get_wikis(
&self,
_params: &[(String, String)],
Expand Down
25 changes: 24 additions & 1 deletion src/cmd/issue/attachment/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ pub fn list_with(args: &IssueAttachmentListArgs, api: &dyn BacklogApi) -> Result
#[cfg(test)]
mod tests {
use super::*;
use crate::api::issue::{Issue, IssueAttachment, IssueComment, IssueCount, IssueUser};
use crate::api::issue::{
Issue, IssueAttachment, IssueComment, IssueCommentCount, IssueCount, IssueUser,
};
use anyhow::anyhow;
use std::collections::BTreeMap;

Expand Down Expand Up @@ -197,6 +199,27 @@ mod tests {
.clone()
.ok_or_else(|| anyhow!("no attachments"))
}
fn count_issue_comments(&self, _key: &str) -> anyhow::Result<IssueCommentCount> {
unimplemented!()
}
fn get_issue_comment(&self, _key: &str, _comment_id: u64) -> anyhow::Result<IssueComment> {
unimplemented!()
}
fn get_issue_comment_notifications(
&self,
_key: &str,
_comment_id: u64,
) -> anyhow::Result<Vec<crate::api::issue::IssueCommentNotification>> {
unimplemented!()
}
fn add_issue_comment_notifications(
&self,
_key: &str,
_comment_id: u64,
_params: &[(String, String)],
) -> anyhow::Result<Vec<crate::api::issue::IssueCommentNotification>> {
unimplemented!()
}
fn get_wikis(
&self,
_params: &[(String, String)],
Expand Down
23 changes: 22 additions & 1 deletion src/cmd/issue/comment/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn add_with(args: &IssueCommentAddArgs, api: &dyn BacklogApi) -> Result<()>
#[cfg(test)]
mod tests {
use super::*;
use crate::api::issue::{Issue, IssueAttachment, IssueComment, IssueCount};
use crate::api::issue::{Issue, IssueAttachment, IssueComment, IssueCommentCount, IssueCount};
use crate::cmd::issue::comment::list::sample_comment;
use anyhow::anyhow;

Expand Down Expand Up @@ -168,6 +168,27 @@ mod tests {
fn get_issue_attachments(&self, _key: &str) -> anyhow::Result<Vec<IssueAttachment>> {
unimplemented!()
}
fn count_issue_comments(&self, _key: &str) -> anyhow::Result<IssueCommentCount> {
unimplemented!()
}
fn get_issue_comment(&self, _key: &str, _comment_id: u64) -> anyhow::Result<IssueComment> {
unimplemented!()
}
fn get_issue_comment_notifications(
&self,
_key: &str,
_comment_id: u64,
) -> anyhow::Result<Vec<crate::api::issue::IssueCommentNotification>> {
unimplemented!()
}
fn add_issue_comment_notifications(
&self,
_key: &str,
_comment_id: u64,
_params: &[(String, String)],
) -> anyhow::Result<Vec<crate::api::issue::IssueCommentNotification>> {
unimplemented!()
}
fn get_wikis(
&self,
_params: &[(String, String)],
Expand Down
Loading
Loading