| 1 | //! Pull requests. Served by the MCP tools; see [`crate::mcp`] for why. |
| 2 | |
| 3 | use { |
| 4 | crate::{ |
| 5 | client::Client, |
| 6 | error::Result, |
| 7 | issues::State, |
| 8 | models::{CreatedRef, PullRequest, PullRequestSummary}, |
| 9 | }, |
| 10 | serde_json::json, |
| 11 | }; |
| 12 | |
| 13 | impl Client { |
| 14 | /// Pull requests in `owner/repo`. |
| 15 | pub async fn pulls(&self, repo: &str, state: State) -> Result<Vec<PullRequestSummary>> { |
| 16 | let args = json!({ "repo": repo, "state": state.as_str() }); |
| 17 | self.call_tool_as("list_pull_requests", args).await |
| 18 | } |
| 19 | |
| 20 | /// One pull request with its comments and unified diff. The server |
| 21 | /// truncates diffs past 100 kB and flags it on the result. |
| 22 | pub async fn pull(&self, repo: &str, number: i64) -> Result<PullRequest> { |
| 23 | self.call_tool_as( |
| 24 | "get_pull_request", |
| 25 | json!({ "repo": repo, "number": number }), |
| 26 | ) |
| 27 | .await |
| 28 | } |
| 29 | |
| 30 | /// Open a pull request from `head` into `base`. |
| 31 | pub async fn create_pull( |
| 32 | &self, |
| 33 | repo: &str, |
| 34 | title: &str, |
| 35 | head: &str, |
| 36 | base: &str, |
| 37 | body: Option<&str>, |
| 38 | ) -> Result<CreatedRef> { |
| 39 | let mut args = json!({ |
| 40 | "repo": repo, |
| 41 | "title": title, |
| 42 | "head": head, |
| 43 | "base": base, |
| 44 | }); |
| 45 | if let Some(body) = body { |
| 46 | args["body"] = body.into(); |
| 47 | } |
| 48 | self.call_tool_as("create_pull_request", args).await |
| 49 | } |
| 50 | } |