diff --git a/src/fetcher/mod.rs b/src/fetcher/mod.rs new file mode 100644 index 0000000..cfd56bf --- /dev/null +++ b/src/fetcher/mod.rs @@ -0,0 +1,56 @@ +use anyhow::Result; + +pub mod github; +pub mod gitlab; + +pub use github::fetch_github_issue; +pub use gitlab::fetch_gitlab_issue; + +pub struct IssueContent { + pub title: String, + pub body: String, + pub number: u64, + pub url: String, + pub labels: Vec, + pub author: String, + pub state: String, +} + +impl IssueContent { + pub fn new(title: String, body: String) -> Self { + IssueContent { + title, + body, + number: 0, + url: String::new(), + labels: Vec::new(), + author: String::new(), + state: String::new(), + } + } + + pub fn with_labels(mut self, labels: Vec) -> Self { + self.labels = labels; + self + } + + pub fn with_author(mut self, author: String) -> Self { + self.author = author; + self + } + + pub fn with_state(mut self, state: String) -> Self { + self.state = state; + self + } +} + +pub async fn fetch_issue_content(url: &str) -> Result { + if url.contains("github.com") { + fetch_github_issue(url).await + } else if url.contains("gitlab.com") { + fetch_gitlab_issue(url).await + } else { + anyhow::bail!("Unsupported Git provider. Only GitHub and GitLab are supported.") + } +}