gitea_sdk/api/pulls/
get.rs

1use crate::{error::Result, model::pulls::PullRequest, Client};
2
3#[derive(Debug, Clone)]
4pub struct GetPullRequestByIdBuilder {
5    owner: String,
6    repo: String,
7    id: i64,
8}
9
10impl GetPullRequestByIdBuilder {
11    pub fn new(owner: impl ToString, repo: impl ToString, id: i64) -> Self {
12        Self {
13            owner: owner.to_string(),
14            repo: repo.to_string(),
15            id,
16        }
17    }
18    /// Sends the request to get a pull request by its ID.
19    pub async fn send(&self, client: &Client) -> Result<PullRequest> {
20        let Self { owner, repo, id } = self;
21        let req = client
22            .get(format!("/repos/{owner}/{repo}/pulls/{id}"))
23            .build()?;
24        let res = client.make_request(req).await?;
25        client.parse_response(res).await
26    }
27}
28
29#[derive(Debug, Clone)]
30pub struct GetPullRequestByBranchesBuilder {
31    owner: String,
32    repo: String,
33    head: String,
34    base: String,
35}
36
37impl GetPullRequestByBranchesBuilder {
38    pub fn new(
39        owner: impl ToString,
40        repo: impl ToString,
41        head: impl ToString,
42        base: impl ToString,
43    ) -> Self {
44        Self {
45            owner: owner.to_string(),
46            repo: repo.to_string(),
47            head: head.to_string(),
48            base: base.to_string(),
49        }
50    }
51    /// Sends the request to get a pull request by its head and base branches.
52    pub async fn send(&self, client: &Client) -> Result<PullRequest> {
53        let Self {
54            owner,
55            repo,
56            head,
57            base,
58        } = self;
59        let req = client
60            .get(format!("/repos/{owner}/{repo}/pulls/{base}/{head}"))
61            .build()?;
62        let res = client.make_request(req).await?;
63        client.parse_response(res).await
64    }
65}