MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / github_create_pr

Function github_create_pr

crates/opencode-cli/src/main.rs:5008–5045  ·  view source on GitHub ↗
(
    owner: &str,
    repo: &str,
    base: &str,
    head: &str,
    title: &str,
    body: &str,
    token: Option<&str>,
)

Source from the content-addressed store, hash-verified

5006}
5007
5008fn github_create_pr(
5009 owner: &str,
5010 repo: &str,
5011 base: &str,
5012 head: &str,
5013 title: &str,
5014 body: &str,
5015 token: Option<&str>,
5016) -> anyhow::Result<u64> {
5017 let endpoint =
5018 format!("repos/{owner}/{repo}/pulls?state=open&head={owner}:{head}&base={base}&per_page=1");
5019 let existing = gh_api_json("GET", &endpoint, None, token)?;
5020 if let Some(number) = existing
5021 .as_array()
5022 .and_then(|items| items.first())
5023 .and_then(|pr| pr.get("number"))
5024 .and_then(|v| v.as_u64())
5025 {
5026 return Ok(number);
5027 }
5028
5029 let endpoint = format!("repos/{owner}/{repo}/pulls");
5030 let created = gh_api_json(
5031 "POST",
5032 &endpoint,
5033 Some(&serde_json::json!({
5034 "title": title,
5035 "head": head,
5036 "base": base,
5037 "body": body,
5038 })),
5039 token,
5040 )?;
5041 created
5042 .get("number")
5043 .and_then(|v| v.as_u64())
5044 .ok_or_else(|| anyhow::anyhow!("Failed to parse created PR number from GitHub response."))
5045}
5046
5047async fn generate_agent_response(
5048 prompt: &str,

Callers 1

handle_github_commandFunction · 0.85

Calls 2

gh_api_jsonFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected