torii_lib/platforms/
issue.rs1use super::azure::AzureIssueClient;
2use super::bitbucket::BitbucketIssueClient;
3use super::gitea::GiteaIssueClient;
4use super::github::GitHubIssueClient;
5use super::gitlab::GitLabIssueClient;
6use super::radicle::RadicleIssueClient;
7use super::sourcehut::SourcehutIssueClient;
8use crate::error::{Result, ToriiError};
9use serde::{Deserialize, Serialize};
10
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct Issue {
13 pub number: u64,
14 pub title: String,
15 pub body: Option<String>,
16 pub state: String,
17 pub author: String,
18 pub url: String,
19 pub labels: Vec<String>,
20 pub assignees: Vec<String>,
21 pub created_at: String,
22 pub comments: u64,
23}
24
25#[derive(Debug, Clone)]
26pub struct CreateIssueOptions {
27 pub title: String,
28 pub body: Option<String>,
29}
30
31pub trait IssueClient: Send {
32 fn list(&self, owner: &str, repo: &str, state: &str) -> Result<Vec<Issue>>;
33 fn create(&self, owner: &str, repo: &str, opts: CreateIssueOptions) -> Result<Issue>;
34 fn close(&self, owner: &str, repo: &str, number: u64) -> Result<()>;
35 fn comment(&self, owner: &str, repo: &str, number: u64, body: &str) -> Result<()>;
36}
37
38pub fn get_issue_client(platform: &str) -> Result<Box<dyn IssueClient>> {
41 match platform.to_lowercase().as_str() {
42 "github" => Ok(Box::new(GitHubIssueClient::new()?)),
43 "gitlab" => Ok(Box::new(GitLabIssueClient::new()?)),
44 "gitea" => Ok(Box::new(GiteaIssueClient::new()?)),
45 "sourcehut" => Ok(Box::new(SourcehutIssueClient::new()?)),
46 "radicle" => Ok(Box::new(RadicleIssueClient::new()?)),
47 "bitbucket" => Ok(Box::new(BitbucketIssueClient::new()?)),
48 "azure" => Ok(Box::new(AzureIssueClient::new()?)),
49 other => Err(ToriiError::Unsupported(format!("Unsupported platform: {}. Supported: github, gitlab, gitea, sourcehut, radicle, bitbucket, azure", other))),
50 }
51}