jinxapi_github/v1_1_4/request/
repos_get_commit.rs

1//! Get a commit
2//! 
3//! Returns the contents of a single commit reference. You must have `read` access for the repository to use this endpoint.
4//! 
5//! **Note:** If there are more than 300 files in the commit diff, the response will include pagination link headers for the remaining files, up to a limit of 3000 files. Each page contains the static commit information, and the only changes are to the file listing.
6//! 
7//! You can 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. Diffs with binary data will have no `patch` property.
8//! 
9//! To return only the SHA-1 hash of the commit reference, you can provide the `sha` custom [media type](https://docs.github.com/rest/overview/media-types/#commits-commit-comparison-and-pull-requests) in the `Accept` header. You can use this endpoint to check if a remote reference's SHA-1 hash is the same as your local reference's SHA-1 hash by providing the local SHA-1 reference as the ETag.
10//! 
11//! **Signature verification object**
12//! 
13//! The response will include a `verification` object that describes the result of verifying the commit's signature. The following fields are included in the `verification` object:
14//! 
15//! | Name | Type | Description |
16//! | ---- | ---- | ----------- |
17//! | `verified` | `boolean` | Indicates whether GitHub considers the signature in this commit to be verified. |
18//! | `reason` | `string` | The reason for verified value. Possible values and their meanings are enumerated in table below. |
19//! | `signature` | `string` | The signature that was extracted from the commit. |
20//! | `payload` | `string` | The value that was signed. |
21//! 
22//! These are the possible values for `reason` in the `verification` object:
23//! 
24//! | Value | Description |
25//! | ----- | ----------- |
26//! | `expired_key` | The key that made the signature is expired. |
27//! | `not_signing_key` | The "signing" flag is not among the usage flags in the GPG key that made the signature. |
28//! | `gpgverify_error` | There was an error communicating with the signature verification service. |
29//! | `gpgverify_unavailable` | The signature verification service is currently unavailable. |
30//! | `unsigned` | The object does not include a signature. |
31//! | `unknown_signature_type` | A non-PGP signature was found in the commit. |
32//! | `no_user` | No user was associated with the `committer` email address in the commit. |
33//! | `unverified_email` | The `committer` email address in the commit was associated with a user, but the email address is not verified on her/his account. |
34//! | `bad_email` | The `committer` email address in the commit is not included in the identities of the PGP key that made the signature. |
35//! | `unknown_key` | The key that made the signature has not been registered with any user's account. |
36//! | `malformed_signature` | There was an error parsing the signature. |
37//! | `invalid` | The signature could not be cryptographically verified using the key whose key-id was found in the signature. |
38//! | `valid` | None of the above errors applied, so the signature is considered to be verified. |
39//! 
40//! [API method documentation](https://docs.github.com/rest/reference/repos#get-a-commit)
41
42
43fn url_string(
44    base_url: &str,
45    p_owner: &str,
46    p_repo: &str,
47    p_ref: &str,
48    q_page: ::std::option::Option<i64>,
49    q_per_page: ::std::option::Option<i64>,
50) -> Result<String, crate::v1_1_4::ApiError> {
51    let trimmed = if base_url.is_empty() {
52        "https://api.github.com"
53    } else {
54        base_url.trim_end_matches('/')
55    };
56    let mut url = String::with_capacity(trimmed.len() + 36);
57    url.push_str(trimmed);
58    url.push_str("/repos/");
59    ::querylizer::Simple::extend(&mut url, &p_owner, false, &::querylizer::encode_path)?;
60    url.push('/');
61    ::querylizer::Simple::extend(&mut url, &p_repo, false, &::querylizer::encode_path)?;
62    url.push_str("/commits/");
63    ::querylizer::Simple::extend(&mut url, &p_ref, false, &::querylizer::encode_path)?;
64    let mut prefix = '?';
65    if let Some(value) = &q_page {
66        url.push(::std::mem::replace(&mut prefix, '&'));
67        ::querylizer::Form::extend(&mut url, "page", value, false, &::querylizer::encode_query)?;
68    }
69    if let Some(value) = &q_per_page {
70        url.push(::std::mem::replace(&mut prefix, '&'));
71        ::querylizer::Form::extend(&mut url, "per_page", value, false, &::querylizer::encode_query)?;
72    }
73    Ok(url)
74}
75
76#[cfg(feature = "hyper")]
77#[allow(clippy::too_many_arguments)]
78pub fn http_builder(
79    base_url: &str,
80    p_owner: &str,
81    p_repo: &str,
82    p_ref: &str,
83    q_page: ::std::option::Option<i64>,
84    q_per_page: ::std::option::Option<i64>,
85    h_user_agent: &str,
86    h_accept: ::std::option::Option<&str>,
87) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
88    let url = url_string(
89        base_url,
90        p_owner,
91        p_repo,
92        p_ref,
93        q_page,
94        q_per_page,
95    )?;
96    let mut builder = ::http::request::Request::get(url);
97    builder = builder.header(
98        "User-Agent",
99        &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
100    );
101    if let Some(value) = &h_accept {
102        builder = builder.header(
103            "Accept",
104            &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
105        );
106    }
107    Ok(builder)
108}
109
110#[cfg(feature = "hyper")]
111#[inline]
112pub fn hyper_request(
113    builder: ::http::request::Builder,
114) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError> {
115    Ok(builder.body(::hyper::Body::empty())?)
116}
117
118#[cfg(feature = "reqwest")]
119#[allow(clippy::too_many_arguments)]
120pub fn reqwest_builder(
121    base_url: &str,
122    p_owner: &str,
123    p_repo: &str,
124    p_ref: &str,
125    q_page: ::std::option::Option<i64>,
126    q_per_page: ::std::option::Option<i64>,
127    h_user_agent: &str,
128    h_accept: ::std::option::Option<&str>,
129) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
130    let url = url_string(
131        base_url,
132        p_owner,
133        p_repo,
134        p_ref,
135        q_page,
136        q_per_page,
137    )?;
138    let reqwest_url = ::reqwest::Url::parse(&url)?;
139    let mut request = ::reqwest::Request::new(::reqwest::Method::GET, reqwest_url);
140    let headers = request.headers_mut();
141    headers.append(
142        "User-Agent",
143        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
144    );
145    if let Some(value) = &h_accept {
146        headers.append(
147            "Accept",
148            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
149        );
150    }
151    Ok(request)
152}
153
154#[cfg(feature = "reqwest")]
155#[inline(always)]
156pub fn reqwest_request(
157    builder: ::reqwest::Request,
158) -> Result<::reqwest::Request, crate::v1_1_4::ApiError>
159{
160    Ok(builder)
161}
162
163#[cfg(feature = "reqwest-blocking")]
164#[allow(clippy::too_many_arguments)]
165pub fn reqwest_blocking_builder(
166    base_url: &str,
167    p_owner: &str,
168    p_repo: &str,
169    p_ref: &str,
170    q_page: ::std::option::Option<i64>,
171    q_per_page: ::std::option::Option<i64>,
172    h_user_agent: &str,
173    h_accept: ::std::option::Option<&str>,
174) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
175    let url = url_string(
176        base_url,
177        p_owner,
178        p_repo,
179        p_ref,
180        q_page,
181        q_per_page,
182    )?;
183    let reqwest_url = ::reqwest::Url::parse(&url)?;
184    let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::GET, reqwest_url);
185    let headers = request.headers_mut();
186    headers.append(
187        "User-Agent",
188        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
189    );
190    if let Some(value) = &h_accept {
191        headers.append(
192            "Accept",
193            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
194        );
195    }
196    Ok(request)
197}
198
199#[cfg(feature = "reqwest-blocking")]
200#[inline(always)]
201pub fn reqwest_blocking_request(
202    builder: ::reqwest::blocking::Request,
203) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError>
204{
205    Ok(builder)
206}