use serde::{Deserialize, Serialize};
use super::model::{ItemKind, MarkupFlavor};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ConversationCaps {
pub read: bool,
pub comment: bool,
pub reply_in_thread: bool,
pub start_thread: bool,
pub edit_own: bool,
pub delete_own: bool,
pub resolve: bool,
pub reactions: bool,
pub events: bool,
pub internal_notes: bool,
pub read_flavor: MarkupFlavor,
pub write_flavor: MarkupFlavor,
pub max_body: Option<usize>,
}
impl ConversationCaps {
pub const NONE: Self = Self {
read: false,
comment: false,
reply_in_thread: false,
start_thread: false,
edit_own: false,
delete_own: false,
resolve: false,
reactions: false,
events: false,
internal_notes: false,
read_flavor: MarkupFlavor::PlainText,
write_flavor: MarkupFlavor::PlainText,
max_body: None,
};
pub fn github(kind: ItemKind) -> Self {
Self {
read: true,
comment: true,
reply_in_thread: kind == ItemKind::PullRequest,
start_thread: false,
edit_own: true,
delete_own: true,
resolve: kind == ItemKind::PullRequest,
reactions: true,
events: true,
internal_notes: false,
read_flavor: MarkupFlavor::Gfm,
write_flavor: MarkupFlavor::Gfm,
max_body: Some(65_536),
}
}
pub fn gitea(kind: ItemKind, can_resolve: bool) -> Self {
let pr = kind == ItemKind::PullRequest;
Self {
read: true,
comment: true,
reply_in_thread: pr,
start_thread: false,
edit_own: true,
delete_own: true,
resolve: pr && can_resolve,
reactions: false,
events: true,
internal_notes: false,
read_flavor: MarkupFlavor::GiteaMd,
write_flavor: MarkupFlavor::GiteaMd,
max_body: None,
}
}
pub fn azure_devops(kind: ItemKind, server: bool) -> Self {
let pr = kind == ItemKind::PullRequest;
Self {
read: true,
comment: true,
reply_in_thread: pr,
start_thread: false,
edit_own: true,
delete_own: true,
resolve: false,
reactions: false,
events: pr,
internal_notes: false,
read_flavor: MarkupFlavor::AzureMd,
write_flavor: if pr || !server {
MarkupFlavor::AzureMd
} else {
MarkupFlavor::Html
},
max_body: Some(150_000),
}
}
pub fn bitbucket(kind: ItemKind) -> Self {
if kind == ItemKind::Issue {
return Self::NONE;
}
Self {
read: true,
comment: true,
reply_in_thread: true,
start_thread: false,
edit_own: true,
delete_own: true,
resolve: false,
reactions: false,
events: true,
internal_notes: false,
read_flavor: MarkupFlavor::BitbucketMd,
write_flavor: MarkupFlavor::BitbucketMd,
max_body: None,
}
}
pub fn gerrit(kind: ItemKind) -> Self {
if kind == ItemKind::Issue {
return Self::NONE;
}
Self {
read: true,
comment: true,
reply_in_thread: true,
start_thread: false,
edit_own: false,
delete_own: false,
resolve: true,
reactions: false,
events: true,
internal_notes: false,
read_flavor: MarkupFlavor::PlainText,
write_flavor: MarkupFlavor::PlainText,
max_body: None,
}
}
pub fn gitlab(kind: ItemKind) -> Self {
Self {
read: true,
comment: true,
reply_in_thread: true,
start_thread: false,
edit_own: true,
delete_own: true,
resolve: kind == ItemKind::PullRequest,
reactions: false,
events: true,
internal_notes: true,
read_flavor: MarkupFlavor::GitlabMd,
write_flavor: MarkupFlavor::GitlabMd,
max_body: Some(1_000_000),
}
}
fn tracker(kind: ItemKind, caps: Self) -> Self {
if kind == ItemKind::Issue {
caps
} else {
Self::NONE
}
}
pub fn jira(kind: ItemKind) -> Self {
Self::tracker(
kind,
Self {
read: true,
comment: true,
edit_own: true,
delete_own: true,
events: true,
read_flavor: MarkupFlavor::Gfm,
write_flavor: MarkupFlavor::JiraWiki,
max_body: Some(32_767),
..Self::NONE
},
)
}
pub fn linear(kind: ItemKind) -> Self {
Self::tracker(
kind,
Self {
read: true,
comment: true,
reply_in_thread: true,
edit_own: true,
delete_own: true,
events: true,
read_flavor: MarkupFlavor::Gfm,
write_flavor: MarkupFlavor::Gfm,
..Self::NONE
},
)
}
pub fn youtrack(kind: ItemKind) -> Self {
Self::tracker(
kind,
Self {
read: true,
comment: true,
edit_own: true,
delete_own: true,
read_flavor: MarkupFlavor::YoutrackMd,
write_flavor: MarkupFlavor::YoutrackMd,
..Self::NONE
},
)
}
pub fn redmine(kind: ItemKind, textile: bool) -> Self {
Self::tracker(
kind,
Self {
read: true,
comment: true,
edit_own: true,
events: true,
internal_notes: true,
read_flavor: MarkupFlavor::Gfm,
write_flavor: if textile {
MarkupFlavor::Textile
} else {
MarkupFlavor::Gfm
},
..Self::NONE
},
)
}
pub fn trello(kind: ItemKind) -> Self {
Self::tracker(
kind,
Self {
read: true,
comment: true,
edit_own: true,
delete_own: true,
events: true,
read_flavor: MarkupFlavor::TrelloMd,
write_flavor: MarkupFlavor::TrelloMd,
max_body: Some(16_384),
..Self::NONE
},
)
}
pub fn local_markdown(kind: ItemKind) -> Self {
Self::tracker(
kind,
Self {
read: true,
comment: true,
edit_own: true,
delete_own: true,
read_flavor: MarkupFlavor::ObsidianMd,
write_flavor: MarkupFlavor::ObsidianMd,
..Self::NONE
},
)
}
}