Initial commit: git-issue-commit CLI tool
This commit is contained in:
56
src/fetcher/mod.rs
Normal file
56
src/fetcher/mod.rs
Normal file
@@ -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<String>,
|
||||||
|
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<String>) -> 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<IssueContent> {
|
||||||
|
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.")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user