jinxapi_github/v1_1_4/request/
pulls_get.rs

1//! Get a pull request
2//! 
3//! Draft pull requests are available in public repositories with GitHub Free and GitHub Free for organizations, GitHub Pro, and legacy per-repository billing plans, and in public and private repositories with GitHub Team and GitHub Enterprise Cloud. For more information, see [GitHub's products](https://docs.github.com/github/getting-started-with-github/githubs-products) in the GitHub Help documentation.
4//! 
5//! Lists details of a pull request by providing its number.
6//! 
7//! When you get, [create](https://docs.github.com/rest/reference/pulls/#create-a-pull-request), or [edit](https://docs.github.com/rest/reference/pulls#update-a-pull-request) a pull request, GitHub creates a merge commit to test whether the pull request can be automatically merged into the base branch. This test commit is not added to the base branch or the head branch. You can review the status of the test commit using the `mergeable` key. For more information, see "[Checking mergeability of pull requests](https://docs.github.com/rest/guides/getting-started-with-the-git-database-api#checking-mergeability-of-pull-requests)".
8//! 
9//! The value of the `mergeable` attribute can be `true`, `false`, or `null`. If the value is `null`, then GitHub has started a background job to compute the mergeability. After giving the job time to complete, resubmit the request. When the job finishes, you will see a non-`null` value for the `mergeable` attribute in the response. If `mergeable` is `true`, then `merge_commit_sha` will be the SHA of the _test_ merge commit.
10//! 
11//! The value of the `merge_commit_sha` attribute changes depending on the state of the pull request. Before merging a pull request, the `merge_commit_sha` attribute holds the SHA of the _test_ merge commit. After merging a pull request, the `merge_commit_sha` attribute changes depending on how you merged the pull request:
12//! 
13//! *   If merged as a [merge commit](https://docs.github.com/articles/about-merge-methods-on-github/), `merge_commit_sha` represents the SHA of the merge commit.
14//! *   If merged via a [squash](https://docs.github.com/articles/about-merge-methods-on-github/#squashing-your-merge-commits), `merge_commit_sha` represents the SHA of the squashed commit on the base branch.
15//! *   If [rebased](https://docs.github.com/articles/about-merge-methods-on-github/#rebasing-and-merging-your-commits), `merge_commit_sha` represents the commit that the base branch was updated to.
16//! 
17//! Pass the appropriate [media type](https://docs.github.com/rest/overview/media-types/#commits-commit-comparison-and-pull-requests) to fetch diff and patch formats.
18//! 
19//! [API method documentation](https://docs.github.com/rest/reference/pulls#get-a-pull-request)
20
21
22fn url_string(
23    base_url: &str,
24    p_owner: &str,
25    p_repo: &str,
26    p_pull_number: i64,
27) -> Result<String, crate::v1_1_4::ApiError> {
28    let trimmed = if base_url.is_empty() {
29        "https://api.github.com"
30    } else {
31        base_url.trim_end_matches('/')
32    };
33    let mut url = String::with_capacity(trimmed.len() + 34);
34    url.push_str(trimmed);
35    url.push_str("/repos/");
36    ::querylizer::Simple::extend(&mut url, &p_owner, false, &::querylizer::encode_path)?;
37    url.push('/');
38    ::querylizer::Simple::extend(&mut url, &p_repo, false, &::querylizer::encode_path)?;
39    url.push_str("/pulls/");
40    ::querylizer::Simple::extend(&mut url, &p_pull_number, false, &::querylizer::encode_path)?;
41    Ok(url)
42}
43
44#[cfg(feature = "hyper")]
45pub fn http_builder(
46    base_url: &str,
47    p_owner: &str,
48    p_repo: &str,
49    p_pull_number: i64,
50    h_user_agent: &str,
51    h_accept: ::std::option::Option<&str>,
52) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
53    let url = url_string(
54        base_url,
55        p_owner,
56        p_repo,
57        p_pull_number,
58    )?;
59    let mut builder = ::http::request::Request::get(url);
60    builder = builder.header(
61        "User-Agent",
62        &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
63    );
64    if let Some(value) = &h_accept {
65        builder = builder.header(
66            "Accept",
67            &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
68        );
69    }
70    Ok(builder)
71}
72
73#[cfg(feature = "hyper")]
74#[inline]
75pub fn hyper_request(
76    builder: ::http::request::Builder,
77) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError> {
78    Ok(builder.body(::hyper::Body::empty())?)
79}
80
81#[cfg(feature = "reqwest")]
82pub fn reqwest_builder(
83    base_url: &str,
84    p_owner: &str,
85    p_repo: &str,
86    p_pull_number: i64,
87    h_user_agent: &str,
88    h_accept: ::std::option::Option<&str>,
89) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
90    let url = url_string(
91        base_url,
92        p_owner,
93        p_repo,
94        p_pull_number,
95    )?;
96    let reqwest_url = ::reqwest::Url::parse(&url)?;
97    let mut request = ::reqwest::Request::new(::reqwest::Method::GET, reqwest_url);
98    let headers = request.headers_mut();
99    headers.append(
100        "User-Agent",
101        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
102    );
103    if let Some(value) = &h_accept {
104        headers.append(
105            "Accept",
106            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
107        );
108    }
109    Ok(request)
110}
111
112#[cfg(feature = "reqwest")]
113#[inline(always)]
114pub fn reqwest_request(
115    builder: ::reqwest::Request,
116) -> Result<::reqwest::Request, crate::v1_1_4::ApiError>
117{
118    Ok(builder)
119}
120
121#[cfg(feature = "reqwest-blocking")]
122pub fn reqwest_blocking_builder(
123    base_url: &str,
124    p_owner: &str,
125    p_repo: &str,
126    p_pull_number: i64,
127    h_user_agent: &str,
128    h_accept: ::std::option::Option<&str>,
129) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
130    let url = url_string(
131        base_url,
132        p_owner,
133        p_repo,
134        p_pull_number,
135    )?;
136    let reqwest_url = ::reqwest::Url::parse(&url)?;
137    let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::GET, reqwest_url);
138    let headers = request.headers_mut();
139    headers.append(
140        "User-Agent",
141        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
142    );
143    if let Some(value) = &h_accept {
144        headers.append(
145            "Accept",
146            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
147        );
148    }
149    Ok(request)
150}
151
152#[cfg(feature = "reqwest-blocking")]
153#[inline(always)]
154pub fn reqwest_blocking_request(
155    builder: ::reqwest::blocking::Request,
156) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError>
157{
158    Ok(builder)
159}