jinxapi_github/v1_1_4/request/
repos_compare_commits.rs

1//! Compare two commits
2//! 
3//! The `basehead` param is comprised of two parts: `base` and `head`. Both must be branch names in `repo`. To compare branches across other repositories in the same network as `repo`, use the format `<USERNAME>:branch`.
4//! 
5//! The response from the API is equivalent to running the `git log base..head` command; however, commits are returned in chronological order. 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.
6//! 
7//! The response also includes details on the files that were changed between the two commits. This includes the status of the change (for example, if a file was added, removed, modified, or renamed), and details of the change itself. For example, files with a `renamed` status have a `previous_filename` field showing the previous filename of the file, and files with a `modified` status have a `patch` field showing the changes made to the file.
8//! 
9//! **Working with large comparisons**
10//! 
11//! To process a response with a large number of commits, you can use (`per_page` or `page`) to paginate the results. When using paging, the list of changed files is only returned with page 1, but includes all changed files for the entire comparison. For more information on working with pagination, see "[Traversing with pagination](/rest/guides/traversing-with-pagination)."
12//! 
13//! When calling this API without any paging parameters (`per_page` or `page`), the returned list is limited to 250 commits and the last commit in the list is the most recent of the entire comparison. When a paging parameter is specified, the first commit in the returned list of each page is the earliest.
14//! 
15//! **Signature verification object**
16//! 
17//! 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:
18//! 
19//! | Name | Type | Description |
20//! | ---- | ---- | ----------- |
21//! | `verified` | `boolean` | Indicates whether GitHub considers the signature in this commit to be verified. |
22//! | `reason` | `string` | The reason for verified value. Possible values and their meanings are enumerated in table below. |
23//! | `signature` | `string` | The signature that was extracted from the commit. |
24//! | `payload` | `string` | The value that was signed. |
25//! 
26//! These are the possible values for `reason` in the `verification` object:
27//! 
28//! | Value | Description |
29//! | ----- | ----------- |
30//! | `expired_key` | The key that made the signature is expired. |
31//! | `not_signing_key` | The "signing" flag is not among the usage flags in the GPG key that made the signature. |
32//! | `gpgverify_error` | There was an error communicating with the signature verification service. |
33//! | `gpgverify_unavailable` | The signature verification service is currently unavailable. |
34//! | `unsigned` | The object does not include a signature. |
35//! | `unknown_signature_type` | A non-PGP signature was found in the commit. |
36//! | `no_user` | No user was associated with the `committer` email address in the commit. |
37//! | `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. |
38//! | `bad_email` | The `committer` email address in the commit is not included in the identities of the PGP key that made the signature. |
39//! | `unknown_key` | The key that made the signature has not been registered with any user's account. |
40//! | `malformed_signature` | There was an error parsing the signature. |
41//! | `invalid` | The signature could not be cryptographically verified using the key whose key-id was found in the signature. |
42//! | `valid` | None of the above errors applied, so the signature is considered to be verified. |
43//! 
44//! [API method documentation](https://docs.github.com/rest/reference/repos#compare-two-commits)
45
46
47fn url_string(
48    base_url: &str,
49    p_owner: &str,
50    p_repo: &str,
51    p_basehead: &str,
52    q_page: ::std::option::Option<i64>,
53    q_per_page: ::std::option::Option<i64>,
54) -> Result<String, crate::v1_1_4::ApiError> {
55    let trimmed = if base_url.is_empty() {
56        "https://api.github.com"
57    } else {
58        base_url.trim_end_matches('/')
59    };
60    let mut url = String::with_capacity(trimmed.len() + 36);
61    url.push_str(trimmed);
62    url.push_str("/repos/");
63    ::querylizer::Simple::extend(&mut url, &p_owner, false, &::querylizer::encode_path)?;
64    url.push('/');
65    ::querylizer::Simple::extend(&mut url, &p_repo, false, &::querylizer::encode_path)?;
66    url.push_str("/compare/");
67    ::querylizer::Simple::extend(&mut url, &p_basehead, false, &::querylizer::encode_path)?;
68    let mut prefix = '?';
69    if let Some(value) = &q_page {
70        url.push(::std::mem::replace(&mut prefix, '&'));
71        ::querylizer::Form::extend(&mut url, "page", value, false, &::querylizer::encode_query)?;
72    }
73    if let Some(value) = &q_per_page {
74        url.push(::std::mem::replace(&mut prefix, '&'));
75        ::querylizer::Form::extend(&mut url, "per_page", value, false, &::querylizer::encode_query)?;
76    }
77    Ok(url)
78}
79
80#[cfg(feature = "hyper")]
81#[allow(clippy::too_many_arguments)]
82pub fn http_builder(
83    base_url: &str,
84    p_owner: &str,
85    p_repo: &str,
86    p_basehead: &str,
87    q_page: ::std::option::Option<i64>,
88    q_per_page: ::std::option::Option<i64>,
89    h_user_agent: &str,
90    h_accept: ::std::option::Option<&str>,
91) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
92    let url = url_string(
93        base_url,
94        p_owner,
95        p_repo,
96        p_basehead,
97        q_page,
98        q_per_page,
99    )?;
100    let mut builder = ::http::request::Request::get(url);
101    builder = builder.header(
102        "User-Agent",
103        &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
104    );
105    if let Some(value) = &h_accept {
106        builder = builder.header(
107            "Accept",
108            &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
109        );
110    }
111    Ok(builder)
112}
113
114#[cfg(feature = "hyper")]
115#[inline]
116pub fn hyper_request(
117    builder: ::http::request::Builder,
118) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError> {
119    Ok(builder.body(::hyper::Body::empty())?)
120}
121
122#[cfg(feature = "reqwest")]
123#[allow(clippy::too_many_arguments)]
124pub fn reqwest_builder(
125    base_url: &str,
126    p_owner: &str,
127    p_repo: &str,
128    p_basehead: &str,
129    q_page: ::std::option::Option<i64>,
130    q_per_page: ::std::option::Option<i64>,
131    h_user_agent: &str,
132    h_accept: ::std::option::Option<&str>,
133) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
134    let url = url_string(
135        base_url,
136        p_owner,
137        p_repo,
138        p_basehead,
139        q_page,
140        q_per_page,
141    )?;
142    let reqwest_url = ::reqwest::Url::parse(&url)?;
143    let mut request = ::reqwest::Request::new(::reqwest::Method::GET, reqwest_url);
144    let headers = request.headers_mut();
145    headers.append(
146        "User-Agent",
147        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
148    );
149    if let Some(value) = &h_accept {
150        headers.append(
151            "Accept",
152            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
153        );
154    }
155    Ok(request)
156}
157
158#[cfg(feature = "reqwest")]
159#[inline(always)]
160pub fn reqwest_request(
161    builder: ::reqwest::Request,
162) -> Result<::reqwest::Request, crate::v1_1_4::ApiError>
163{
164    Ok(builder)
165}
166
167#[cfg(feature = "reqwest-blocking")]
168#[allow(clippy::too_many_arguments)]
169pub fn reqwest_blocking_builder(
170    base_url: &str,
171    p_owner: &str,
172    p_repo: &str,
173    p_basehead: &str,
174    q_page: ::std::option::Option<i64>,
175    q_per_page: ::std::option::Option<i64>,
176    h_user_agent: &str,
177    h_accept: ::std::option::Option<&str>,
178) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
179    let url = url_string(
180        base_url,
181        p_owner,
182        p_repo,
183        p_basehead,
184        q_page,
185        q_per_page,
186    )?;
187    let reqwest_url = ::reqwest::Url::parse(&url)?;
188    let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::GET, reqwest_url);
189    let headers = request.headers_mut();
190    headers.append(
191        "User-Agent",
192        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
193    );
194    if let Some(value) = &h_accept {
195        headers.append(
196            "Accept",
197            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
198        );
199    }
200    Ok(request)
201}
202
203#[cfg(feature = "reqwest-blocking")]
204#[inline(always)]
205pub fn reqwest_blocking_request(
206    builder: ::reqwest::blocking::Request,
207) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError>
208{
209    Ok(builder)
210}