jinxapi_github/v1_1_4/request/
git_get_commit.rs

1//! Get a commit
2//! 
3//! Gets a Git [commit object](https://git-scm.com/book/en/v1/Git-Internals-Git-Objects#Commit-Objects).
4//! 
5//! **Signature verification object**
6//! 
7//! 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:
8//! 
9//! | Name | Type | Description |
10//! | ---- | ---- | ----------- |
11//! | `verified` | `boolean` | Indicates whether GitHub considers the signature in this commit to be verified. |
12//! | `reason` | `string` | The reason for verified value. Possible values and their meanings are enumerated in the table below. |
13//! | `signature` | `string` | The signature that was extracted from the commit. |
14//! | `payload` | `string` | The value that was signed. |
15//! 
16//! These are the possible values for `reason` in the `verification` object:
17//! 
18//! | Value | Description |
19//! | ----- | ----------- |
20//! | `expired_key` | The key that made the signature is expired. |
21//! | `not_signing_key` | The "signing" flag is not among the usage flags in the GPG key that made the signature. |
22//! | `gpgverify_error` | There was an error communicating with the signature verification service. |
23//! | `gpgverify_unavailable` | The signature verification service is currently unavailable. |
24//! | `unsigned` | The object does not include a signature. |
25//! | `unknown_signature_type` | A non-PGP signature was found in the commit. |
26//! | `no_user` | No user was associated with the `committer` email address in the commit. |
27//! | `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. |
28//! | `bad_email` | The `committer` email address in the commit is not included in the identities of the PGP key that made the signature. |
29//! | `unknown_key` | The key that made the signature has not been registered with any user's account. |
30//! | `malformed_signature` | There was an error parsing the signature. |
31//! | `invalid` | The signature could not be cryptographically verified using the key whose key-id was found in the signature. |
32//! | `valid` | None of the above errors applied, so the signature is considered to be verified. |
33//! 
34//! [API method documentation](https://docs.github.com/rest/reference/git#get-a-commit)
35
36
37fn url_string(
38    base_url: &str,
39    p_owner: &str,
40    p_repo: &str,
41    p_commit_sha: &str,
42) -> Result<String, crate::v1_1_4::ApiError> {
43    let trimmed = if base_url.is_empty() {
44        "https://api.github.com"
45    } else {
46        base_url.trim_end_matches('/')
47    };
48    let mut url = String::with_capacity(trimmed.len() + 40);
49    url.push_str(trimmed);
50    url.push_str("/repos/");
51    ::querylizer::Simple::extend(&mut url, &p_owner, false, &::querylizer::encode_path)?;
52    url.push('/');
53    ::querylizer::Simple::extend(&mut url, &p_repo, false, &::querylizer::encode_path)?;
54    url.push_str("/git/commits/");
55    ::querylizer::Simple::extend(&mut url, &p_commit_sha, false, &::querylizer::encode_path)?;
56    Ok(url)
57}
58
59#[cfg(feature = "hyper")]
60pub fn http_builder(
61    base_url: &str,
62    p_owner: &str,
63    p_repo: &str,
64    p_commit_sha: &str,
65    h_user_agent: &str,
66    h_accept: ::std::option::Option<&str>,
67) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
68    let url = url_string(
69        base_url,
70        p_owner,
71        p_repo,
72        p_commit_sha,
73    )?;
74    let mut builder = ::http::request::Request::get(url);
75    builder = builder.header(
76        "User-Agent",
77        &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
78    );
79    if let Some(value) = &h_accept {
80        builder = builder.header(
81            "Accept",
82            &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
83        );
84    }
85    Ok(builder)
86}
87
88#[cfg(feature = "hyper")]
89#[inline]
90pub fn hyper_request(
91    builder: ::http::request::Builder,
92) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError> {
93    Ok(builder.body(::hyper::Body::empty())?)
94}
95
96#[cfg(feature = "reqwest")]
97pub fn reqwest_builder(
98    base_url: &str,
99    p_owner: &str,
100    p_repo: &str,
101    p_commit_sha: &str,
102    h_user_agent: &str,
103    h_accept: ::std::option::Option<&str>,
104) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
105    let url = url_string(
106        base_url,
107        p_owner,
108        p_repo,
109        p_commit_sha,
110    )?;
111    let reqwest_url = ::reqwest::Url::parse(&url)?;
112    let mut request = ::reqwest::Request::new(::reqwest::Method::GET, reqwest_url);
113    let headers = request.headers_mut();
114    headers.append(
115        "User-Agent",
116        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
117    );
118    if let Some(value) = &h_accept {
119        headers.append(
120            "Accept",
121            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
122        );
123    }
124    Ok(request)
125}
126
127#[cfg(feature = "reqwest")]
128#[inline(always)]
129pub fn reqwest_request(
130    builder: ::reqwest::Request,
131) -> Result<::reqwest::Request, crate::v1_1_4::ApiError>
132{
133    Ok(builder)
134}
135
136#[cfg(feature = "reqwest-blocking")]
137pub fn reqwest_blocking_builder(
138    base_url: &str,
139    p_owner: &str,
140    p_repo: &str,
141    p_commit_sha: &str,
142    h_user_agent: &str,
143    h_accept: ::std::option::Option<&str>,
144) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
145    let url = url_string(
146        base_url,
147        p_owner,
148        p_repo,
149        p_commit_sha,
150    )?;
151    let reqwest_url = ::reqwest::Url::parse(&url)?;
152    let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::GET, reqwest_url);
153    let headers = request.headers_mut();
154    headers.append(
155        "User-Agent",
156        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
157    );
158    if let Some(value) = &h_accept {
159        headers.append(
160            "Accept",
161            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
162        );
163    }
164    Ok(request)
165}
166
167#[cfg(feature = "reqwest-blocking")]
168#[inline(always)]
169pub fn reqwest_blocking_request(
170    builder: ::reqwest::blocking::Request,
171) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError>
172{
173    Ok(builder)
174}