Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Nicholas Bailey
rust-gitlab
Commits
bd875060
Commit
bd875060
authored
Oct 10, 2019
by
Ben Boeckel
⛰
Browse files
rustfmt: apply suggestions
parent
d2a41c44
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/gitlab.rs
View file @
bd875060
...
...
@@ -729,7 +729,10 @@ impl Gitlab {
/// Get the labels with open/closed/merge requests count
pub
fn
labels_with_counts
(
&
self
,
project
:
ProjectId
)
->
Result
<
Vec
<
Label
>>
{
self
.get_paged_with_param
(
&
format!
(
"projects/{}/labels"
,
project
),
vec!
[(
"with_counts"
,
"true"
)])
self
.get_paged_with_param
(
&
format!
(
"projects/{}/labels"
,
project
),
vec!
[(
"with_counts"
,
"true"
)],
)
}
/// Get label by ID.
...
...
@@ -897,14 +900,11 @@ impl Gitlab {
&
self
,
project
:
ProjectId
,
issue
:
IssueInternalId
,
)
->
Result
<
Vec
<
ResourceLabelEvent
>>
{
self
.get_paged
(
&
format!
(
"projects/{}/issues/{}/resource_label_events"
,
project
,
issue
,
)
)
)
->
Result
<
Vec
<
ResourceLabelEvent
>>
{
self
.get_paged
(
&
format!
(
"projects/{}/issues/{}/resource_label_events"
,
project
,
issue
,
))
}
/// Create a note on a issue.
...
...
@@ -977,55 +977,40 @@ impl Gitlab {
K
:
AsRef
<
str
>
,
V
:
AsRef
<
str
>
,
{
self
.get_paged_with_param
(
&
format!
(
"projects/{}/pipelines"
,
project
,
),
params
,
)
self
.get_paged_with_param
(
&
format!
(
"projects/{}/pipelines"
,
project
),
params
)
}
/// Get a single pipeline.
pub
fn
pipeline
(
&
self
,
project
:
ProjectId
,
id
:
PipelineId
)
->
Result
<
Pipeline
>
{
self
.get
(
&
format!
(
"projects/{}/pipelines/{}"
,
project
,
id
,
),
)
pub
fn
pipeline
(
&
self
,
project
:
ProjectId
,
id
:
PipelineId
)
->
Result
<
Pipeline
>
{
self
.get
(
&
format!
(
"projects/{}/pipelines/{}"
,
project
,
id
))
}
/// Get variables of a pipeline.
pub
fn
pipeline_variables
(
&
self
,
project
:
ProjectId
,
id
:
PipelineId
)
->
Result
<
Vec
<
PipelineVariable
>>
{
self
.get
(
&
format!
(
"projects/{}/pipelines/{}/variables"
,
project
,
id
,
),
)
pub
fn
pipeline_variables
(
&
self
,
project
:
ProjectId
,
id
:
PipelineId
,
)
->
Result
<
Vec
<
PipelineVariable
>>
{
self
.get
(
&
format!
(
"projects/{}/pipelines/{}/variables"
,
project
,
id
))
}
/// Create a new pipeline.
pub
fn
create_pipeline
(
&
self
,
project
:
ProjectId
,
ref_
:
ObjectId
,
variables
:
&
[
PipelineVariable
])
->
Result
<
Pipeline
>
{
pub
fn
create_pipeline
(
&
self
,
project
:
ProjectId
,
ref_
:
ObjectId
,
variables
:
&
[
PipelineVariable
],
)
->
Result
<
Pipeline
>
{
use
crates
::
serde
::
Serialize
;
#[derive(Debug,
Serialize)]
struct
CreatePipelineParams
<
'a
>
{
ref_
:
ObjectId
,
variables
:
&
'a
[
PipelineVariable
],
variables
:
&
'a
[
PipelineVariable
],
}
self
.post_with_param
(
&
format!
(
"projects/{}/pipeline"
,
project
,
),
CreatePipelineParams
{
&
format!
(
"projects/{}/pipeline"
,
project
),
CreatePipelineParams
{
ref_
:
ref_
,
variables
:
variables
,
},
...
...
@@ -1033,35 +1018,20 @@ impl Gitlab {
}
/// Retry jobs in a pipeline.
pub
fn
retry_pipeline
(
&
self
,
project
:
ProjectId
,
id
:
PipelineId
)
->
Result
<
Pipeline
>
{
self
.post
(
&
format!
(
"projects/{}/pipelines/{}/retry"
,
project
,
id
,
),
)
pub
fn
retry_pipeline
(
&
self
,
project
:
ProjectId
,
id
:
PipelineId
)
->
Result
<
Pipeline
>
{
self
.post
(
&
format!
(
"projects/{}/pipelines/{}/retry"
,
project
,
id
))
}
/// Cancel a pipeline.
pub
fn
cancel_pipeline
(
&
self
,
project
:
ProjectId
,
id
:
PipelineId
)
->
Result
<
Pipeline
>
{
self
.post
(
&
format!
(
"projects/{}/pipelines/{}/cancel"
,
project
,
id
,
),
)
pub
fn
cancel_pipeline
(
&
self
,
project
:
ProjectId
,
id
:
PipelineId
)
->
Result
<
Pipeline
>
{
self
.post
(
&
format!
(
"projects/{}/pipelines/{}/cancel"
,
project
,
id
))
}
#[allow(unused)]
/// Delete a pipeline.
///
/// NOTE Not implemented.
fn
delete_pipeline
(
&
self
,
project
:
ProjectId
,
id
:
PipelineId
)
->
Result
<
Pipeline
>
{
fn
delete_pipeline
(
&
self
,
project
:
ProjectId
,
id
:
PipelineId
)
->
Result
<
Pipeline
>
{
unimplemented!
();
}
...
...
@@ -1309,14 +1279,11 @@ impl Gitlab {
&
self
,
project
:
ProjectId
,
merge_request
:
MergeRequestInternalId
,
)
->
Result
<
Vec
<
ResourceLabelEvent
>>
{
self
.get_paged
(
&
format!
(
"projects/{}/merge_requests/{}/resource_label_events"
,
project
,
merge_request
,
)
)
)
->
Result
<
Vec
<
ResourceLabelEvent
>>
{
self
.get_paged
(
&
format!
(
"projects/{}/merge_requests/{}/resource_label_events"
,
project
,
merge_request
,
))
}
pub
fn
create_merge_request_discussion
(
...
...
@@ -1483,7 +1450,9 @@ impl Gitlab {
where
T
:
DeserializeOwned
,
{
let
rsp
=
self
.token
.set_header
(
req
)
?
let
rsp
=
self
.token
.set_header
(
req
)
?
.send
()
.chain_err
(||
ErrorKind
::
Communication
)
?
;
let
status
=
rsp
.status
();
...
...
@@ -1531,13 +1500,13 @@ impl Gitlab {
/// Create a `POST` request to an API endpoint.
fn
post
<
T
>
(
&
self
,
url
:
&
str
)
->
Result
<
T
>
where
T
:
DeserializeOwned
where
T
:
DeserializeOwned
,
{
let
param
:
&
[(
&
str
,
&
str
)]
=
&
[];
self
.post_with_param
(
url
,
param
)
}
/// Create a `POST` request to an API endpoint with query parameters.
fn
post_with_param
<
T
,
U
>
(
&
self
,
url
:
&
str
,
param
:
U
)
->
Result
<
T
>
where
...
...
src/test/types.rs
View file @
bd875060
...
...
@@ -465,7 +465,10 @@ fn test_read_note() {
#[test]
fn
test_read_singlenote_discussion
()
{
let
discussions
:
Vec
<
Discussion
>
=
read_test_file
(
"discussion"
);
let
discussion
=
discussions
.iter
()
.find
(|
x
|
x
.id
.value
()
==
"18ea341cb10e952889e277836ba638c6b17ff26c"
)
.unwrap
();
let
discussion
=
discussions
.iter
()
.find
(|
x
|
x
.id
.value
()
==
"18ea341cb10e952889e277836ba638c6b17ff26c"
)
.unwrap
();
assert!
(
discussion
.individual_note
);
assert_eq!
(
discussion
.notes
.len
(),
1
);
let
note
=
discussion
.notes
.get
(
0
)
.unwrap
();
...
...
@@ -477,7 +480,10 @@ fn test_read_singlenote_discussion() {
#[test]
fn
test_read_nocode_discussion
()
{
let
discussions
:
Vec
<
Discussion
>
=
read_test_file
(
"discussion"
);
let
discussion
=
discussions
.iter
()
.find
(|
x
|
x
.id
.value
()
==
"a4d5505b3556eaa45edbe567af7aebc1760dedd7"
)
.unwrap
();
let
discussion
=
discussions
.iter
()
.find
(|
x
|
x
.id
.value
()
==
"a4d5505b3556eaa45edbe567af7aebc1760dedd7"
)
.unwrap
();
assert!
(
!
(
discussion
.individual_note
));
assert_eq!
(
discussion
.notes
.len
(),
3
);
let
question
=
discussion
.notes
.get
(
0
)
.unwrap
();
...
...
@@ -500,7 +506,10 @@ fn test_read_nocode_discussion() {
#[test]
fn
test_read_code_discussion
()
{
let
discussions
:
Vec
<
Discussion
>
=
read_test_file
(
"discussion"
);
let
discussion
=
discussions
.into_iter
()
.find
(|
x
|
x
.id
.value
()
==
"9f4998b2308728b95cff52af97019479e1269183"
)
.unwrap
();
let
discussion
=
discussions
.into_iter
()
.find
(|
x
|
x
.id
.value
()
==
"9f4998b2308728b95cff52af97019479e1269183"
)
.unwrap
();
assert!
(
!
(
discussion
.individual_note
));
let
note
=
discussion
.notes
.get
(
0
)
.unwrap
();
assert!
(
note
.resolvable
);
...
...
@@ -511,7 +520,10 @@ fn test_read_code_discussion() {
assert!
(
note
.position
.is_some
());
if
let
Some
(
position
)
=
&
note
.position
{
assert_eq!
(
position
.position_type
,
NotePositionType
::
Text
);
assert_eq!
(
position
.head_sha
.value
(),
"04e94ae667024a62a90179f395bfdc2b35f3efd2"
);
assert_eq!
(
position
.head_sha
.value
(),
"04e94ae667024a62a90179f395bfdc2b35f3efd2"
,
);
assert_eq!
(
position
.new_line
,
Some
(
156
));
assert_eq!
(
position
.new_path
,
"src/gitlab.rs"
);
}
else
{
...
...
@@ -576,7 +588,10 @@ fn test_read_project() {
assert_eq!
(
project
.namespace.kind
,
NamespaceKind
::
Group
);
assert_eq!
(
project
.namespace.full_path
,
"utils"
);
assert_eq!
(
project
.namespace.avatar_url
,
None
);
assert_eq!
(
project
.namespace.web_url
,
"https://gitlab.kitware.com/groups/utils"
);
assert_eq!
(
project
.namespace.web_url
,
"https://gitlab.kitware.com/groups/utils"
,
);
assert!
(
project
.namespace.members_count_with_descendants
.is_none
());
assert!
(
project
.forked_from_project
.is_none
());
assert_eq!
(
project
.avatar_url
,
None
);
...
...
@@ -601,11 +616,23 @@ fn test_read_project() {
assert_eq!
(
project
.snippets_enabled
,
false
);
assert_eq!
(
project
.wiki_enabled
,
true
);
assert_eq!
(
project
.builds_access_level
,
FeatureVisibilityLevel
::
Disabled
);
assert_eq!
(
project
.builds_access_level
,
FeatureVisibilityLevel
::
Disabled
,
);
assert_eq!
(
project
.issues_access_level
,
FeatureVisibilityLevel
::
Enabled
);
assert_eq!
(
project
.merge_requests_access_level
,
FeatureVisibilityLevel
::
Enabled
);
assert_eq!
(
project
.repository_access_level
,
FeatureVisibilityLevel
::
Enabled
);
assert_eq!
(
project
.snippets_access_level
,
FeatureVisibilityLevel
::
Disabled
);
assert_eq!
(
project
.merge_requests_access_level
,
FeatureVisibilityLevel
::
Enabled
,
);
assert_eq!
(
project
.repository_access_level
,
FeatureVisibilityLevel
::
Enabled
,
);
assert_eq!
(
project
.snippets_access_level
,
FeatureVisibilityLevel
::
Disabled
,
);
assert_eq!
(
project
.wiki_access_level
,
FeatureVisibilityLevel
::
Enabled
);
assert_eq!
(
project
.merge_method
,
Some
(
"merge"
.to_string
()));
...
...
@@ -858,7 +885,7 @@ fn test_read_resoruce_label_events() {
Some
(
ResourceLabelEventTarget
::
Issue
(
id
))
if
id
.value
()
==
69328
=>
{
// this is the expected value
},
x
=>
panic!
(
"Unexpected resource_target: {:?}"
,
x
)
x
=>
panic!
(
"Unexpected resource_target: {:?}"
,
x
)
,
}
let
label
=
event
.label
.unwrap
();
...
...
@@ -873,10 +900,16 @@ fn test_read_pipelines() {
let
pipeline_basic
:
PipelineBasic
=
read_test_file
(
"pipeline_basic"
);
assert_eq!
(
pipeline_basic
.id
,
PipelineId
::
new
(
145400
));
assert_eq!
(
pipeline_basic
.status
,
StatusState
::
Success
);
assert_eq!
(
pipeline_basic
.status
,
StatusState
::
Success
);
assert_eq!
(
pipeline_basic
.ref_
,
Some
(
"master"
.to_string
()));
assert_eq!
(
pipeline_basic
.sha
,
ObjectId
::
new
(
"7134adce4522c399cdab16e128b0a1af15b93f14"
.to_string
()));
assert_eq!
(
pipeline_basic
.web_url
,
"https://gitlab.kitware.com/utils/rust-gitlab/pipelines/145400"
);
assert_eq!
(
pipeline_basic
.sha
,
ObjectId
::
new
(
"7134adce4522c399cdab16e128b0a1af15b93f14"
.to_string
()),
);
assert_eq!
(
pipeline_basic
.web_url
,
"https://gitlab.kitware.com/utils/rust-gitlab/pipelines/145400"
,
);
}
#[test]
...
...
@@ -886,21 +919,45 @@ fn test_read_pipeline() {
assert_eq!
(
pipeline
.id
,
PipelineId
::
new
(
145400
));
assert_eq!
(
pipeline
.status
,
StatusState
::
Success
);
assert_eq!
(
pipeline
.ref_
,
Some
(
"master"
.to_string
()));
assert_eq!
(
pipeline
.sha
,
ObjectId
::
new
(
"7134adce4522c399cdab16e128b0a1af15b93f14"
.to_string
()));
assert_eq!
(
pipeline
.sha
,
ObjectId
::
new
(
"7134adce4522c399cdab16e128b0a1af15b93f14"
.to_string
()),
);
assert_eq!
(
pipeline
.before_sha
,
None
);
assert_eq!
(
pipeline
.tag
,
false
);
assert_eq!
(
pipeline
.yaml_errors
,
None
);
assert_eq!
(
pipeline
.created_at
,
Some
(
Utc
.ymd
(
2019
,
9
,
3
)
.and_hms_milli
(
18
,
09
,
47
,
178
)));
assert_eq!
(
pipeline
.updated_at
,
Some
(
Utc
.ymd
(
2019
,
9
,
3
)
.and_hms_milli
(
18
,
15
,
47
,
18
)));
assert_eq!
(
pipeline
.started_at
,
Some
(
Utc
.ymd
(
2019
,
9
,
3
)
.and_hms_milli
(
18
,
09
,
51
,
465
)));
assert_eq!
(
pipeline
.finished_at
,
Some
(
Utc
.ymd
(
2019
,
9
,
3
)
.and_hms_milli
(
18
,
15
,
47
,
13
)));
assert_eq!
(
pipeline
.created_at
,
Some
(
Utc
.ymd
(
2019
,
9
,
3
)
.and_hms_milli
(
18
,
09
,
47
,
178
)),
);
assert_eq!
(
pipeline
.updated_at
,
Some
(
Utc
.ymd
(
2019
,
9
,
3
)
.and_hms_milli
(
18
,
15
,
47
,
18
)),
);
assert_eq!
(
pipeline
.started_at
,
Some
(
Utc
.ymd
(
2019
,
9
,
3
)
.and_hms_milli
(
18
,
09
,
51
,
465
)),
);
assert_eq!
(
pipeline
.finished_at
,
Some
(
Utc
.ymd
(
2019
,
9
,
3
)
.and_hms_milli
(
18
,
15
,
47
,
13
)),
);
assert_eq!
(
pipeline
.committed_at
,
None
);
assert_eq!
(
pipeline
.duration
,
Some
(
0
));
assert_eq!
(
pipeline
.coverage
,
None
);
assert_eq!
(
pipeline
.web_url
,
"https://gitlab.kitware.com/utils/rust-gitlab/pipelines/145400"
);
assert_eq!
(
pipeline
.web_url
,
"https://gitlab.kitware.com/utils/rust-gitlab/pipelines/145400"
,
);
// nested user
assert_eq!
(
pipeline
.user.avatar_url
,
Some
(
"https://gitlab.kitware.com/uploads/-/system/user/avatar/35/buildbot-logo.png"
.to_owned
()));
assert_eq!
(
pipeline
.user.avatar_url
,
Some
(
"https://gitlab.kitware.com/uploads/-/system/user/avatar/35/buildbot-logo.png"
.to_owned
(),
),
);
assert_eq!
(
pipeline
.user.id
,
UserId
::
new
(
35
));
assert_eq!
(
pipeline
.user.name
,
"buildbot"
);
assert_eq!
(
pipeline
.user.username
,
"buildbot"
);
...
...
src/types.rs
View file @
bd875060
...
...
@@ -2658,22 +2658,28 @@ pub struct ResourceLabelEvent {
resource_type
:
String
,
/// The label may be None if the label has been deleted.
pub
label
:
Option
<
EventLabel
>
,
pub
action
:
String
pub
action
:
String
,
}
impl
ResourceLabelEvent
{
/// Returns the id of the merge request or issue that this event is from
pub
fn
event_target
(
&
self
)
->
Option
<
ResourceLabelEventTarget
>
{
match
self
.resource_type
.as_ref
()
{
"MergeRequest"
=>
Some
(
ResourceLabelEventTarget
::
MergeRequest
(
MergeRequestId
::
new
(
self
.resource_id
))),
"Issue"
=>
Some
(
ResourceLabelEventTarget
::
Issue
(
IssueId
::
new
(
self
.resource_id
))),
_
=>
None
"MergeRequest"
=>
{
Some
(
ResourceLabelEventTarget
::
MergeRequest
(
MergeRequestId
::
new
(
self
.resource_id
,
)))
},
"Issue"
=>
{
Some
(
ResourceLabelEventTarget
::
Issue
(
IssueId
::
new
(
self
.resource_id
,
)))
},
_
=>
None
,
}
}
}
#[derive(Debug,
Clone,
PartialEq,
Eq)]
/// The type of object that on which the resource label event was created
pub
enum
ResourceLabelEventTarget
{
...
...
@@ -2683,7 +2689,6 @@ pub enum ResourceLabelEventTarget {
MergeRequest
(
MergeRequestId
),
}
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// An label on a project.
...
...
src/webhooks.rs
View file @
bd875060
...
...
@@ -43,17 +43,16 @@ impl<'de> Deserialize<'de> for HookDate {
let
val
=
String
::
deserialize
(
deserializer
)
?
;
Utc
.datetime_from_str
(
&
val
,
"%Y-%m-%d %H:%M:%S UTC"
)
.or_else
(|
_
|
DateTime
::
parse_from_rfc3339
(
&
val
)
.map
(|
dt
|
dt
.with_timezone
(
&
Utc
)))
.or_else
(|
_
|
{
DateTime
::
parse_from_rfc3339
(
&
val
)
.map
(|
dt
|
dt
.with_timezone
(
&
Utc
))
})
.or_else
(|
_
|
{
DateTime
::
parse_from_str
(
&
val
,
"%Y-%m-%d %H:%M:%S %z"
)
.map
(|
dt
|
dt
.with_timezone
(
&
Utc
))
DateTime
::
parse_from_str
(
&
val
,
"%Y-%m-%d %H:%M:%S %z"
)
.map
(|
dt
|
dt
.with_timezone
(
&
Utc
))
})
.map_err
(|
err
|
{
D
::
Error
::
invalid_value
(
Unexpected
::
Other
(
"hook date"
),
&
format!
(
"Unsupported format: {} {:?}"
,
val
,
err
)
.as_str
(),
)
)
})
.map
(
HookDate
)
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment