jj_ryu/platform/mod.rs
1//! Platform services for GitHub and GitLab
2//!
3//! Provides a unified interface for PR/MR operations across platforms.
4
5mod detection;
6mod factory;
7mod github;
8mod gitlab;
9
10pub use detection::{detect_platform, parse_repo_info};
11pub use factory::create_platform_service;
12pub use github::GitHubService;
13pub use gitlab::GitLabService;
14
15use crate::error::Result;
16use crate::types::{PlatformConfig, PrComment, PullRequest};
17use async_trait::async_trait;
18
19/// Platform service trait for PR/MR operations
20///
21/// This trait abstracts GitHub and GitLab operations, allowing the same
22/// submission logic to work with either platform.
23#[async_trait]
24pub trait PlatformService: Send + Sync {
25 /// Find an existing open PR for a head branch
26 async fn find_existing_pr(&self, head_branch: &str) -> Result<Option<PullRequest>>;
27
28 /// Create a new PR with default options (non-draft).
29 ///
30 /// This is a convenience method that delegates to [`create_pr_with_options`]
31 /// with `draft: false`. Implementors should override `create_pr_with_options`,
32 /// not this method.
33 ///
34 /// [`create_pr_with_options`]: Self::create_pr_with_options
35 async fn create_pr(&self, head: &str, base: &str, title: &str) -> Result<PullRequest> {
36 self.create_pr_with_options(head, base, title, false).await
37 }
38
39 /// Create a new PR with explicit draft option.
40 ///
41 /// Implementors must provide this method. The default [`create_pr`] method
42 /// delegates here with `draft: false`.
43 ///
44 /// [`create_pr`]: Self::create_pr
45 async fn create_pr_with_options(
46 &self,
47 head: &str,
48 base: &str,
49 title: &str,
50 draft: bool,
51 ) -> Result<PullRequest>;
52
53 /// Update the base branch of an existing PR
54 async fn update_pr_base(&self, pr_number: u64, new_base: &str) -> Result<PullRequest>;
55
56 /// Publish a draft PR (convert to ready for review)
57 async fn publish_pr(&self, pr_number: u64) -> Result<PullRequest>;
58
59 /// List comments on a PR
60 async fn list_pr_comments(&self, pr_number: u64) -> Result<Vec<PrComment>>;
61
62 /// Create a comment on a PR
63 async fn create_pr_comment(&self, pr_number: u64, body: &str) -> Result<()>;
64
65 /// Update an existing comment on a PR
66 async fn update_pr_comment(&self, pr_number: u64, comment_id: u64, body: &str) -> Result<()>;
67
68 /// Get the platform configuration
69 fn config(&self) -> &PlatformConfig;
70}