Skip to main content

aptu_core/facade/
pr_create.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! PR creation facade functions.
4
5#[cfg(not(target_arch = "wasm32"))]
6use tracing::instrument;
7
8#[cfg(not(target_arch = "wasm32"))]
9use crate::auth::TokenProvider;
10use crate::error::AptuError;
11#[cfg(not(target_arch = "wasm32"))]
12use crate::github::auth::create_client_from_provider;
13
14/// Creates a pull request on GitHub.
15///
16/// # Arguments
17///
18/// * `provider` - Token provider for GitHub credentials
19/// * `owner` - Repository owner
20/// * `repo` - Repository name
21/// * `title` - PR title
22/// * `base_branch` - Base branch (the branch to merge into)
23/// * `head_branch` - Head branch (the branch with changes)
24/// * `body` - Optional PR body text
25///
26/// # Returns
27///
28/// `PrCreateResult` with PR metadata.
29///
30/// # Errors
31///
32/// Returns an error if:
33/// - GitHub token is not available from the provider
34/// - GitHub API call fails
35/// - User lacks write access to the repository
36#[cfg(not(target_arch = "wasm32"))]
37#[instrument(skip(provider), fields(owner = %owner, repo = %repo, head = %head_branch, base = %base_branch))]
38#[allow(clippy::too_many_arguments)]
39pub async fn create_pr(
40    provider: &dyn TokenProvider,
41    owner: &str,
42    repo: &str,
43    title: &str,
44    base_branch: &str,
45    head_branch: &str,
46    body: Option<&str>,
47    draft: bool,
48) -> crate::Result<crate::github::pulls::PrCreateResult> {
49    // Create GitHub client from provider
50    let client = create_client_from_provider(provider)?;
51
52    // Create the pull request
53    crate::github::pulls::create_pull_request(
54        &client,
55        owner,
56        repo,
57        title,
58        head_branch,
59        base_branch,
60        body,
61        draft,
62    )
63    .await
64    .map_err(|e| AptuError::GitHub {
65        message: e.to_string(),
66    })
67}
68
69#[cfg(target_arch = "wasm32")]
70pub async fn create_pr(
71    _provider: &dyn crate::auth::TokenProvider,
72    _owner: &str,
73    _repo: &str,
74    _title: &str,
75    _base_branch: &str,
76    _head_branch: &str,
77    _body: Option<&str>,
78    _draft: bool,
79) -> crate::Result<crate::github::pulls::PrCreateResult> {
80    crate::facade::wasm_unsupported!("create_pr");
81}