Skip to content

Commit f0c8fa1

Browse files
committed
Merge branch 'cleanups'
2 parents b31b782 + dda100a commit f0c8fa1

File tree

21 files changed

+244
-284
lines changed

21 files changed

+244
-284
lines changed

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ log = "0.3"
1919
serde = "0.8"
2020
serde_derive = { version = "0.8", optional = true }
2121
serde_json = "0.8"
22+
serde_urlencoded = "0.3"
2223

2324

2425
hyper = "0.9"

build.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ fn main() {
1212

1313
let src = Path::new("src/serde_types.in.rs");
1414
let dst = Path::new(&out_dir).join("serde_types.rs");
15+
serde_codegen::expand(&src, &dst).unwrap();
1516

17+
let src = Path::new("src/merge_requests/serde_types.in.rs");
18+
let dst = Path::new(&out_dir).join("merge_requests");
19+
std::fs::create_dir_all(&dst).expect(&format!("Cannot create directory {:?}!", dst));
20+
let dst = dst.join("serde_types.rs");
1621
serde_codegen::expand(&src, &dst).unwrap();
1722
}
1823

examples/list_groups.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn main() {
2929
hostname);
3030
}
3131
};
32-
let mut gl = gitlab::GitLab::new_https(&hostname, &token);
32+
let mut gl = gitlab::GitLab::new(&hostname, &token);
3333
gl.set_pagination(gitlab::Pagination {
3434
page: 1,
3535
per_page: 100,

examples/list_issues.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn main() {
3434
}
3535
};
3636

37-
let gl = GitLab::new_https(&hostname, &token);
37+
let gl = GitLab::new(&hostname, &token);
3838

3939
let issues = gl.issues(issues::Listing::new()).unwrap();
4040
println!("issues: {:?}", issues);

examples/list_merge_requests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn main() {
3333
}
3434
};
3535

36-
let gl = GitLab::new_https(&hostname, &token);
36+
let gl = GitLab::new(&hostname, &token);
3737

3838
let merge_request = gl.merge_request(merge_requests::single::Listing::new(142, 418)).unwrap();
3939
println!("merge_request: {:?}", merge_request);

examples/list_projects.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn main() {
3434
}
3535
};
3636

37-
let gl = GitLab::new_https(&hostname, &token);
37+
let gl = GitLab::new(&hostname, &token);
3838
// for i in 1..82 {
3939
// gl.set_pagination(Pagination{page: i, per_page: 1});
4040
// println!("projects: {:?}", gl.projects().unwrap());

src/gitlab.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl fmt::Debug for GitLab {
4949

5050

5151
impl GitLab {
52-
pub fn new(scheme: &str, domain: &str, port: u16, private_token: &str) -> GitLab {
52+
pub fn _new(scheme: &str, domain: &str, port: u16, private_token: &str) -> GitLab {
5353
GitLab {
5454
scheme: scheme.to_string(),
5555
domain: domain.to_string(),
@@ -69,12 +69,13 @@ impl GitLab {
6969
}
7070
}
7171

72-
pub fn new_http(domain: &str, private_token: &str) -> GitLab {
73-
GitLab::new("http", domain, 80, private_token)
72+
pub fn new_insecure(domain: &str, private_token: &str) -> GitLab {
73+
warn!("Using insecure http:// protocol: Token will be sent in clear!");
74+
GitLab::_new("http", domain, 80, private_token)
7475
}
7576

76-
pub fn new_https(domain: &str, private_token: &str) -> GitLab {
77-
GitLab::new("https", domain, 443, private_token)
77+
pub fn new(domain: &str, private_token: &str) -> GitLab {
78+
GitLab::_new("https", domain, 443, private_token)
7879
}
7980

8081
/// Build a URL used to access GitLab instance, including some parameters.
@@ -89,7 +90,7 @@ impl GitLab {
8990
/// let expected_url = "https://gitlab.example.com:\
9091
/// 443/api/v3/groups?order_by=path&private_token=XXXXXXXXXXXXX";
9192
///
92-
/// let gl = GitLab::new_https("gitlab.example.com", "XXXXXXXXXXXXX");
93+
/// let gl = GitLab::new("gitlab.example.com", "XXXXXXXXXXXXX");
9394
///
9495
/// assert_eq!(gl.build_url("groups?order_by=path"), expected_url);
9596
/// ```

src/groups/mod.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,6 @@ pub enum ListingOrderBy {
4848
}
4949

5050

51-
#[derive(Debug, Copy, Clone)]
52-
pub enum ListingSort {
53-
Asc,
54-
Desc,
55-
}
56-
57-
5851
fn append_group_lister_options_order_by(order_by: ListingOrderBy, s: &mut String) {
5952
s.push_str(match order_by {
6053
ListingOrderBy::Name => "name",
@@ -63,10 +56,10 @@ fn append_group_lister_options_order_by(order_by: ListingOrderBy, s: &mut String
6356
}
6457

6558

66-
fn append_group_lister_options_sort(order_by: ListingSort, s: &mut String) {
59+
fn append_group_lister_options_sort(order_by: ::ListingSort, s: &mut String) {
6760
s.push_str(match order_by {
68-
ListingSort::Asc => "asc",
69-
ListingSort::Desc => "desc",
61+
::ListingSort::Asc => "asc",
62+
::ListingSort::Desc => "desc",
7063
});
7164
}
7265

@@ -83,7 +76,7 @@ pub struct Listing {
8376
/// Order groups by `name` or `path`. Default is `name`
8477
order_by: Option<ListingOrderBy>,
8578
/// Order groups in `asc` or `desc` order. Default is `asc`
86-
sort: Option<ListingSort>,
79+
sort: Option<::ListingSort>,
8780
}
8881

8982

@@ -108,7 +101,7 @@ impl Listing {
108101
self.order_by = Some(order_by);
109102
self
110103
}
111-
fn sort(&mut self, sort: ListingSort) -> &mut Listing {
104+
fn sort(&mut self, sort: ::ListingSort) -> &mut Listing {
112105
self.sort = Some(sort);
113106
self
114107
}
@@ -254,11 +247,11 @@ mod tests {
254247
#[test]
255248
fn groups_build_query_sort() {
256249
let expected_string = "groups?sort=asc";
257-
let query = Listing::new().sort(ListingSort::Asc).build_query();
250+
let query = Listing::new().sort(::ListingSort::Asc).build_query();
258251
assert_eq!(query, expected_string);
259252

260253
let expected_string = "groups?sort=desc";
261-
let query = Listing::new().sort(ListingSort::Desc).build_query();
254+
let query = Listing::new().sort(::ListingSort::Desc).build_query();
262255
assert_eq!(query, expected_string);
263256
}
264257

src/groups/projects.rs

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ use BuildQuery;
2929

3030
// FIXME: Use a type for the project id.
3131

32-
#[derive(Debug, Copy, Clone)]
33-
pub enum ListingVisibility {
34-
Public,
35-
Internal,
36-
Private,
37-
}
38-
3932

4033
#[derive(Debug, Copy, Clone)]
4134
pub enum ListingOrderBy {
@@ -48,25 +41,18 @@ pub enum ListingOrderBy {
4841
}
4942

5043

51-
#[derive(Debug, Copy, Clone)]
52-
pub enum ListingSort {
53-
Asc,
54-
Desc,
55-
}
56-
57-
5844
#[derive(Default, Debug, Clone)]
5945
pub struct Listing {
6046
/// Group Id.
6147
id: i64,
6248
/// Limit by archived status.
6349
archived: Option<bool>,
6450
/// Limit by visibility
65-
visibility: Option<ListingVisibility>,
51+
visibility: Option<::ListingVisibility>,
6652
/// Return requests ordered by. Default is `ListingOrderBy::CreatedAt`.
6753
order_by: Option<ListingOrderBy>,
68-
/// Return requests sorted. Default is `ListingSort::Desc`.
69-
sort: Option<ListingSort>,
54+
/// Return requests sorted. Default is `::ListingSort::Desc`.
55+
sort: Option<::ListingSort>,
7056
/// Return list of authorized projects according to a search criteria.
7157
search: String,
7258
/// Return projects ordered by `ci_enabled` flag. Projects with enabled GitLab CI go first.
@@ -82,15 +68,15 @@ impl Listing {
8268
self.archived = Some(archived);
8369
self
8470
}
85-
pub fn visibility(&mut self, visibility: ListingVisibility) -> &mut Listing {
71+
pub fn visibility(&mut self, visibility: ::ListingVisibility) -> &mut Listing {
8672
self.visibility = Some(visibility);
8773
self
8874
}
8975
pub fn order_by(&mut self, order_by: ListingOrderBy) -> &mut Listing {
9076
self.order_by = Some(order_by);
9177
self
9278
}
93-
pub fn sort(&mut self, sort: ListingSort) -> &mut Listing {
79+
pub fn sort(&mut self, sort: ::ListingSort) -> &mut Listing {
9480
self.sort = Some(sort);
9581
self
9682
}
@@ -141,9 +127,9 @@ impl BuildQuery for Listing {
141127

142128
query.push_str("visibility=");
143129
query.push_str(match visibility {
144-
ListingVisibility::Public => "public",
145-
ListingVisibility::Internal => "internal",
146-
ListingVisibility::Private => "private",
130+
::ListingVisibility::Public => "public",
131+
::ListingVisibility::Internal => "internal",
132+
::ListingVisibility::Private => "private",
147133
});
148134
});
149135

@@ -168,8 +154,8 @@ impl BuildQuery for Listing {
168154

169155
query.push_str("sort=");
170156
query.push_str(match sort {
171-
ListingSort::Asc => "asc",
172-
ListingSort::Desc => "desc",
157+
::ListingSort::Asc => "asc",
158+
::ListingSort::Desc => "desc",
173159
});
174160
});
175161

@@ -232,19 +218,19 @@ mod tests {
232218
fn groups_build_query_visibility() {
233219
let expected_string = format!("groups/{}/projects?visibility=public", TEST_PROJECT_ID);
234220
let query = Listing::new(TEST_PROJECT_ID.clone())
235-
.visibility(ListingVisibility::Public)
221+
.visibility(::ListingVisibility::Public)
236222
.build_query();
237223
assert_eq!(query, expected_string);
238224

239225
let expected_string = format!("groups/{}/projects?visibility=internal", TEST_PROJECT_ID);
240226
let query = Listing::new(TEST_PROJECT_ID.clone())
241-
.visibility(ListingVisibility::Internal)
227+
.visibility(::ListingVisibility::Internal)
242228
.build_query();
243229
assert_eq!(query, expected_string);
244230

245231
let expected_string = format!("groups/{}/projects?visibility=private", TEST_PROJECT_ID);
246232
let query = Listing::new(TEST_PROJECT_ID.clone())
247-
.visibility(ListingVisibility::Private)
233+
.visibility(::ListingVisibility::Private)
248234
.build_query();
249235
assert_eq!(query, expected_string);
250236
}
@@ -289,11 +275,11 @@ mod tests {
289275
#[test]
290276
fn groups_build_query_sort() {
291277
let expected_string = format!("groups/{}/projects?sort=asc", TEST_PROJECT_ID);
292-
let query = Listing::new(TEST_PROJECT_ID.clone()).sort(ListingSort::Asc).build_query();
278+
let query = Listing::new(TEST_PROJECT_ID.clone()).sort(::ListingSort::Asc).build_query();
293279
assert_eq!(query, expected_string);
294280

295281
let expected_string = format!("groups/{}/projects?sort=desc", TEST_PROJECT_ID);
296-
let query = Listing::new(TEST_PROJECT_ID.clone()).sort(ListingSort::Desc).build_query();
282+
let query = Listing::new(TEST_PROJECT_ID.clone()).sort(::ListingSort::Desc).build_query();
297283
assert_eq!(query, expected_string);
298284
}
299285

0 commit comments

Comments
 (0)