Skip to main content

oven_cli/issues/
mod.rs

1pub mod github;
2pub mod local;
3
4use anyhow::Result;
5use async_trait::async_trait;
6
7/// A normalized issue from any source.
8///
9/// Both GitHub and local issues are converted to this struct before
10/// entering the pipeline. This keeps the pipeline source-agnostic.
11#[derive(Debug, Clone)]
12pub struct PipelineIssue {
13    pub number: u32,
14    pub title: String,
15    pub body: String,
16    pub source: IssueOrigin,
17    pub target_repo: Option<String>,
18}
19
20/// Where an issue originated.
21#[derive(Debug, Clone, PartialEq, Eq)]
22pub enum IssueOrigin {
23    Github,
24    Local,
25}
26
27impl IssueOrigin {
28    pub const fn as_str(&self) -> &str {
29        match self {
30            Self::Github => "github",
31            Self::Local => "local",
32        }
33    }
34}
35
36impl std::fmt::Display for IssueOrigin {
37    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38        f.write_str(self.as_str())
39    }
40}
41
42/// Trait for fetching and transitioning issues regardless of source.
43#[async_trait]
44pub trait IssueProvider: Send + Sync {
45    /// Fetch all open issues with the given label.
46    async fn get_ready_issues(&self, label: &str) -> Result<Vec<PipelineIssue>>;
47
48    /// Fetch a single issue by number.
49    async fn get_issue(&self, number: u32) -> Result<PipelineIssue>;
50
51    /// Transition an issue from one label to another.
52    async fn transition(&self, number: u32, from: &str, to: &str) -> Result<()>;
53
54    /// Post a comment on an issue (or append to the local issue body).
55    async fn comment(&self, number: u32, body: &str) -> Result<()>;
56
57    /// Close an issue.
58    async fn close(&self, number: u32, comment: Option<&str>) -> Result<()>;
59}