Skip to content

Commit 4c7e4dc

Browse files
committed
Merge branch 'master' into self-signed
2 parents 5d009bf + 7618620 commit 4c7e4dc

File tree

5 files changed

+216
-2
lines changed

5 files changed

+216
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Additions
44

5+
* Add `api::projects:repository::commits::CompareCommits` endpoint
56
* Add `gitlab::Gitlab::new_self_signed` method
67

78
# v0.1701.0

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ url = "^2.1"
6161
void = { version = "^1.0.1", optional = true }
6262
# Required to avoid https://rustsec.org/advisories/RUSTSEC-2023-0044
6363
# Required to avoid https://rustsec.org/advisories/RUSTSEC-2023-0072
64-
openssl = { version = "~0.10.60", optional = true }
64+
# Required to avoid https://rustsec.org/advisories/RUSTSEC-2024-0357
65+
openssl = { version = "~0.10.66", optional = true }
6566
# Required to avoid `remove_dir_all` dependency.
6667
tempfile = { version = "^3.4.0", optional = true }
6768
# Required to avoid https://rustsec.org/advisories/RUSTSEC-2024-0019

src/api/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ These API endpoints have been implemented.
218218
* `GET /projects/:project/repository/commits/:sha/merge_requests` `projects/repository/commits/merge_requests.rs`
219219
* `GET /projects/:project/repository/commits/:sha/statuses` `projects/repository/commits/statuses.rs`
220220
* `GET /projects/:project/repository/commits/:sha/signature` `projects/repository/commits/signature.rs`
221+
* `GET /projects/:project/repository/compare` `projects/repository/commits/compare.rs`
221222
* `GET /projects/:project/repository/files/*file_path` `projects/repository/files/file.rs`
222223
* `POST /projects/:project/repository/files/*file_path` `projects/repository/files/create.rs`
223224
* `PUT /projects/:project/repository/files/*file_path` `projects/repository/files/update.rs`
@@ -472,7 +473,6 @@ instead of having to search the page for missing endpoints.
472473
* `GET /projects/:project/repository/commits/:sha/diff` https://gitlab.kitware.com/help/api/commits.md#get-the-diff-of-a-commit
473474
* `GET /projects/:project/repository/commits/:sha/discussions` https://gitlab.kitware.com/help/api/commits.md#get-the-discussions-of-a-commit
474475
* `POST /projects/:project/repository/commits/:sha/revert` https://gitlab.kitware.com/help/api/commits.md#revert-a-commit
475-
* `GET /projects/:project/repository/compare` https://gitlab.kitware.com/help/api/repositories.md#compare-branches-tags-or-commits
476476
* `GET /projects/:project/repository/contributors` https://gitlab.kitware.com/help/api/repositories.md#contributors
477477
* `HEAD /projects/:project/repository/files/*file_path` https://gitlab.kitware.com/help/api/repository_files.md#get-file-from-repository
478478
* `GET /projects/:project/repository/files/*file_path/blame` https://gitlab.kitware.com/help/api/repository_files.md#get-file-blame-from-repository

src/api/projects/repository/commits.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ mod comment;
1212
mod comments;
1313
mod commit;
1414
mod commits;
15+
mod compare;
1516
mod create;
1617
mod create_status;
1718
mod merge_requests;
@@ -55,6 +56,10 @@ pub use self::refs::CommitReferencesBuilder;
5556
pub use self::refs::CommitReferencesBuilderError;
5657
pub use self::refs::CommitRefsType;
5758

59+
pub use self::compare::CompareCommits;
60+
pub use self::compare::CompareCommitsBuilder;
61+
pub use self::compare::CompareCommitsBuilderError;
62+
5863
pub use self::statuses::CommitStatuses;
5964
pub use self::statuses::CommitStatusesBuilder;
6065
pub use self::statuses::CommitStatusesBuilderError;
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
2+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
3+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
4+
// option. This file may not be copied, modified, or distributed
5+
// except according to those terms.
6+
7+
use derive_builder::Builder;
8+
9+
use crate::api::common::NameOrId;
10+
use crate::api::endpoint_prelude::*;
11+
12+
/// Get the diffs between two commits.
13+
#[derive(Debug, Builder, Clone)]
14+
#[builder(setter(strip_option))]
15+
pub struct CompareCommits<'a> {
16+
/// The project to get a commit from.
17+
#[builder(setter(into))]
18+
project: NameOrId<'a>,
19+
/// The from commit sha or branch name.
20+
#[builder(setter(into))]
21+
from: Cow<'a, str>,
22+
/// The to commit sha or branch name.
23+
#[builder(setter(into))]
24+
to: Cow<'a, str>,
25+
/// The project ID to compare from.
26+
#[builder(default)]
27+
from_project_id: Option<u64>,
28+
/// Comparison method.
29+
///
30+
/// When `true`, the commits are compared directly. When `false` (the default), commits are
31+
/// compared taking their merge base into account.
32+
#[builder(default)]
33+
straight: Option<bool>,
34+
/// Present diffs in the unified diff format.
35+
///
36+
/// Default is false.
37+
#[builder(default)]
38+
unidiff: Option<bool>,
39+
}
40+
41+
impl<'a> CompareCommits<'a> {
42+
/// Create a builder for the endpoint.
43+
pub fn builder() -> CompareCommitsBuilder<'a> {
44+
CompareCommitsBuilder::default()
45+
}
46+
}
47+
48+
impl<'a> Endpoint for CompareCommits<'a> {
49+
fn method(&self) -> Method {
50+
Method::GET
51+
}
52+
53+
fn endpoint(&self) -> Cow<'static, str> {
54+
format!("projects/{}/repository/compare", self.project).into()
55+
}
56+
57+
fn parameters(&self) -> QueryParams {
58+
let mut params = QueryParams::default();
59+
params
60+
.push("from", self.from.as_ref())
61+
.push("to", self.to.as_ref())
62+
.push_opt("from_project_id", self.from_project_id)
63+
.push_opt("straight", self.straight)
64+
.push_opt("unidiff", self.unidiff);
65+
66+
params
67+
}
68+
}
69+
70+
#[cfg(test)]
71+
mod tests {
72+
73+
use crate::api::projects::repository::commits::{CompareCommits, CompareCommitsBuilderError};
74+
use crate::api::{self, Query};
75+
use crate::test::client::{ExpectedUrl, SingleTestClient};
76+
use http::Method;
77+
78+
#[test]
79+
fn project_is_necessary() {
80+
let err = CompareCommits::builder()
81+
.from("0000000000000000000000000000000000000000")
82+
.to("0000000000000000000000000000000000000000")
83+
.build()
84+
.unwrap_err();
85+
crate::test::assert_missing_field!(err, CompareCommitsBuilderError, "project");
86+
}
87+
88+
#[test]
89+
fn to_is_necessary() {
90+
let err = CompareCommits::builder()
91+
.project(1)
92+
.from("0000000000000000000000000000000000000000")
93+
.build()
94+
.unwrap_err();
95+
crate::test::assert_missing_field!(err, CompareCommitsBuilderError, "to");
96+
}
97+
98+
#[test]
99+
fn from_is_necessary() {
100+
let err = CompareCommits::builder()
101+
.project(1)
102+
.to("0000000000000000000000000000000000000000")
103+
.build()
104+
.unwrap_err();
105+
crate::test::assert_missing_field!(err, CompareCommitsBuilderError, "from");
106+
}
107+
108+
#[test]
109+
fn project_from_and_to_are_sufficient() {
110+
CompareCommits::builder()
111+
.project(1)
112+
.to("0000000000000000000000000000000000000000")
113+
.from("0000000000000000000000000000000000000000")
114+
.build()
115+
.unwrap();
116+
}
117+
118+
#[test]
119+
fn endpoint() {
120+
let endpoint = ExpectedUrl::builder()
121+
.method(Method::GET)
122+
.endpoint("projects/simple%2Fproject/repository/compare")
123+
.add_query_params(&[
124+
("from", "0000000000000000000000000000000000000000"),
125+
("to", "0000000000000000000000000000000000000000"),
126+
])
127+
.build()
128+
.unwrap();
129+
let client = SingleTestClient::new_raw(endpoint, "");
130+
let endpoint = CompareCommits::builder()
131+
.project("simple/project")
132+
.from("0000000000000000000000000000000000000000")
133+
.to("0000000000000000000000000000000000000000")
134+
.build()
135+
.unwrap();
136+
api::ignore(endpoint).query(&client).unwrap();
137+
}
138+
139+
#[test]
140+
fn endpoint_from_project_id() {
141+
let endpoint = ExpectedUrl::builder()
142+
.method(Method::GET)
143+
.endpoint("projects/simple%2Fproject/repository/compare")
144+
.add_query_params(&[
145+
("from", "0000000000000000000000000000000000000000"),
146+
("to", "0000000000000000000000000000000000000000"),
147+
("from_project_id", "234876"),
148+
])
149+
.build()
150+
.unwrap();
151+
let client = SingleTestClient::new_raw(endpoint, "");
152+
let endpoint = CompareCommits::builder()
153+
.project("simple/project")
154+
.from("0000000000000000000000000000000000000000")
155+
.to("0000000000000000000000000000000000000000")
156+
.from_project_id(234876)
157+
.build()
158+
.unwrap();
159+
api::ignore(endpoint).query(&client).unwrap();
160+
}
161+
162+
#[test]
163+
fn endpoint_straight() {
164+
let endpoint = ExpectedUrl::builder()
165+
.method(Method::GET)
166+
.endpoint("projects/simple%2Fproject/repository/compare")
167+
.add_query_params(&[
168+
("from", "0000000000000000000000000000000000000000"),
169+
("to", "0000000000000000000000000000000000000000"),
170+
("straight", "true"),
171+
])
172+
.build()
173+
.unwrap();
174+
let client = SingleTestClient::new_raw(endpoint, "");
175+
let endpoint = CompareCommits::builder()
176+
.project("simple/project")
177+
.from("0000000000000000000000000000000000000000")
178+
.to("0000000000000000000000000000000000000000")
179+
.straight(true)
180+
.build()
181+
.unwrap();
182+
api::ignore(endpoint).query(&client).unwrap();
183+
}
184+
185+
#[test]
186+
fn endpoint_unidiff() {
187+
let endpoint = ExpectedUrl::builder()
188+
.method(Method::GET)
189+
.endpoint("projects/simple%2Fproject/repository/compare")
190+
.add_query_params(&[
191+
("from", "0000000000000000000000000000000000000000"),
192+
("to", "0000000000000000000000000000000000000000"),
193+
("unidiff", "true"),
194+
])
195+
.build()
196+
.unwrap();
197+
let client = SingleTestClient::new_raw(endpoint, "");
198+
let endpoint = CompareCommits::builder()
199+
.project("simple/project")
200+
.from("0000000000000000000000000000000000000000")
201+
.to("0000000000000000000000000000000000000000")
202+
.unidiff(true)
203+
.build()
204+
.unwrap();
205+
api::ignore(endpoint).query(&client).unwrap();
206+
}
207+
}

0 commit comments

Comments
 (0)