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    pub author: Option<String>,
19}
20
21/// Where an issue originated.
22#[derive(Debug, Clone, PartialEq, Eq)]
23pub enum IssueOrigin {
24    Github,
25    Local,
26}
27
28impl IssueOrigin {
29    pub const fn as_str(&self) -> &str {
30        match self {
31            Self::Github => "github",
32            Self::Local => "local",
33        }
34    }
35}
36
37impl std::fmt::Display for IssueOrigin {
38    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39        f.write_str(self.as_str())
40    }
41}
42
43/// Trait for fetching and transitioning issues regardless of source.
44#[async_trait]
45pub trait IssueProvider: Send + Sync {
46    /// Fetch all open issues with the given label.
47    async fn get_ready_issues(&self, label: &str) -> Result<Vec<PipelineIssue>>;
48
49    /// Fetch a single issue by number.
50    async fn get_issue(&self, number: u32) -> Result<PipelineIssue>;
51
52    /// Transition an issue from one label to another.
53    async fn transition(&self, number: u32, from: &str, to: &str) -> Result<()>;
54
55    /// Post a comment on an issue (or append to the local issue body).
56    async fn comment(&self, number: u32, body: &str) -> Result<()>;
57
58    /// Close an issue.
59    async fn close(&self, number: u32, comment: Option<&str>) -> Result<()>;
60}