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
3a55a767
Commit
3a55a767
authored
Oct 10, 2019
by
Ben Boeckel
⛰
Browse files
rust: remove internal uses of ToString
parent
bd875060
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/error.rs
View file @
3a55a767
...
...
@@ -46,6 +46,6 @@ impl Error {
.and_then
(|
s
|
s
.as_str
())
.unwrap_or_else
(||
"unknown error"
);
Error
::
from_kind
(
ErrorKind
::
Gitlab
(
msg
.to
_string
()))
Error
::
from_kind
(
ErrorKind
::
Gitlab
(
msg
.
in
to
()))
}
}
src/gitlab.rs
View file @
3a55a767
...
...
@@ -218,7 +218,7 @@ impl Gitlab {
let
mut
users
=
self
.get_paged_with_param
(
"users"
,
&
[(
"username"
,
name
.as_ref
())])
?
;
users
.pop
()
.ok_or_else
(||
Error
::
from_kind
(
ErrorKind
::
Gitlab
(
"no such user"
.to
_string
())))
.ok_or_else
(||
Error
::
from_kind
(
ErrorKind
::
Gitlab
(
"no such user"
.
in
to
())))
}
/// Get all accessible projects.
...
...
src/systemhooks.rs
View file @
3a55a767
...
...
@@ -387,7 +387,8 @@ impl<'de> Deserialize<'de> for SystemHook {
let
val
=
<
Value
as
Deserialize
>
::
deserialize
(
deserializer
)
?
;
let
event_name
=
match
val
.pointer
(
"/event_name"
)
{
Some
(
&
Value
::
String
(
ref
name
))
=>
name
.to_string
(),
// XXX(1.36.0): NLL makes this clone unnecessary.
Some
(
&
Value
::
String
(
ref
name
))
=>
name
.clone
(),
Some
(
_
)
=>
{
return
Err
(
D
::
Error
::
invalid_type
(
Unexpected
::
Other
(
"JSON value"
),
...
...
@@ -399,7 +400,7 @@ impl<'de> Deserialize<'de> for SystemHook {
},
};
let
hook_res
=
match
event_name
.as_
str
()
{
let
hook_res
=
match
event_name
.as_
ref
()
{
"project_create"
|
"project_destroy"
|
"project_rename"
|
"project_transfer"
=>
{
serde_json
::
from_value
(
val
)
.map
(
SystemHook
::
Project
)
},
...
...
src/test/types.rs
View file @
3a55a767
...
...
@@ -39,7 +39,7 @@ fn test_read_award_emoji() {
award_emoji
.user.avatar_url
,
Some
(
"https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon"
.to
_string
()
.
in
to
()
),
);
assert_eq!
(
award_emoji
.user.id
,
UserId
::
new
(
13
));
...
...
@@ -77,7 +77,7 @@ fn test_read_commit_note() {
commit_note
.author.avatar_url
,
Some
(
"https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon"
.to
_string
()
.
in
to
()
),
);
assert_eq!
(
commit_note
.author.id
,
UserId
::
new
(
13
));
...
...
@@ -94,19 +94,18 @@ fn test_read_commit_status() {
assert_eq!
(
commit_status
.id
,
CommitStatusId
::
new
(
931434
));
assert_eq!
(
commit_status
.sha
,
ObjectId
::
new
(
"de4ac3cf96cb8a0893be22b03f5171d934f9d392"
.to_string
()
),
ObjectId
::
new
(
"de4ac3cf96cb8a0893be22b03f5171d934f9d392"
),
);
assert_eq!
(
commit_status
.ref_
,
Some
(
"master"
.to
_string
()));
assert_eq!
(
commit_status
.ref_
,
Some
(
"master"
.
in
to
()));
assert_eq!
(
commit_status
.status
,
StatusState
::
Success
);
assert_eq!
(
commit_status
.name
,
"rust-gitlab-megas-linux-debug"
);
assert_eq!
(
commit_status
.target_url
,
Some
(
"https://buildbot.kitware.com/builders/rust-gitlab-megas-linux-debug/builds/41"
.to_string
()
"https://buildbot.kitware.com/builders/rust-gitlab-megas-linux-debug/builds/41"
.into
()
),
);
assert_eq!
(
commit_status
.description
,
Some
(
"expected"
.to
_string
()));
assert_eq!
(
commit_status
.description
,
Some
(
"expected"
.
in
to
()));
assert_eq!
(
commit_status
.created_at
,
Utc
.ymd
(
2016
,
11
,
8
)
.and_hms_milli
(
14
,
35
,
32
,
627
),
...
...
@@ -126,10 +125,7 @@ fn test_read_commit_status() {
assert_eq!
(
commit_status
.author.state
,
UserState
::
Active
);
assert_eq!
(
commit_status
.author.avatar_url
,
Some
(
"https://gitlab.kitware.com/uploads/-/system/user/avatar/35/buildbot-logo.png"
.to_string
()
),
Some
(
"https://gitlab.kitware.com/uploads/-/system/user/avatar/35/buildbot-logo.png"
.into
()),
);
assert_eq!
(
commit_status
.author.id
,
UserId
::
new
(
35
));
assert_eq!
(
commit_status
.coverage
,
None
);
...
...
@@ -143,7 +139,7 @@ fn test_read_issue() {
assert_eq!
(
issue
.iid
,
IssueInternalId
::
new
(
6
));
assert_eq!
(
issue
.project_id
,
ProjectId
::
new
(
855
));
assert_eq!
(
issue
.title
,
"fix documentation warnings"
);
assert_eq!
(
issue
.description
,
Some
(
""
.to
_string
()));
assert_eq!
(
issue
.description
,
Some
(
""
.
in
to
()));
assert_eq!
(
issue
.state
,
IssueState
::
Closed
);
assert_eq!
(
issue
.created_at
,
...
...
@@ -169,7 +165,7 @@ fn test_read_issue() {
issue
.author.avatar_url
,
Some
(
"https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon"
.to
_string
()
.
in
to
()
),
);
assert_eq!
(
issue
.author.id
,
UserId
::
new
(
13
));
...
...
@@ -179,7 +175,7 @@ fn test_read_issue() {
assert_eq!
(
assignee
.name
,
"Ben Boeckel"
);
assert_eq!
(
assignee
.state
,
UserState
::
Active
);
assert_eq!
(
assignee
.avatar_url
,
Some
(
"https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon"
.to
_string
()));
Some
(
"https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon"
.
in
to
()));
assert_eq!
(
assignee
.id
,
UserId
::
new
(
13
));
}
else
{
panic!
(
"expected to have an assignee for the issue"
);
...
...
@@ -192,7 +188,7 @@ fn test_read_issue() {
assert_eq!
(
assignee
.name
,
"Ben Boeckel"
);
assert_eq!
(
assignee
.state
,
UserState
::
Active
);
assert_eq!
(
assignee
.avatar_url
,
Some
(
"https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon"
.to
_string
()));
Some
(
"https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon"
.
in
to
()));
assert_eq!
(
assignee
.id
,
UserId
::
new
(
13
));
}
else
{
panic!
(
"expected to have assignees for the issue"
);
...
...
@@ -227,7 +223,7 @@ fn test_read_issue_reference() {
Some
(
"The workflow currently requires that the robot be able to register itself as a
\
webhook for new projects. An API needs added for this.
\n\n
Cc: @brad.king"
.to
_string
()
.
in
to
()
),
);
assert_eq!
(
issue
.state
,
IssueState
::
Closed
);
...
...
@@ -251,7 +247,7 @@ fn test_read_issue_reference() {
assert_eq!
(
issue
.author.name
,
"Ben Boeckel"
);
assert_eq!
(
issue
.author.state
,
UserState
::
Active
);
assert_eq!
(
issue
.author.avatar_url
,
Some
(
"https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon"
.to
_string
()));
Some
(
"https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon"
.
in
to
()));
assert_eq!
(
issue
.author.id
,
UserId
::
new
(
13
));
if
let
Some
(
ref
assignee
)
=
issue
.assignee
{
assert_eq!
(
assignee
.username
,
"ben.boeckel"
);
...
...
@@ -259,7 +255,7 @@ fn test_read_issue_reference() {
assert_eq!
(
assignee
.name
,
"Ben Boeckel"
);
assert_eq!
(
assignee
.state
,
UserState
::
Active
);
assert_eq!
(
assignee
.avatar_url
,
Some
(
"https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon"
.to
_string
()));
Some
(
"https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon"
.
in
to
()));
assert_eq!
(
assignee
.id
,
UserId
::
new
(
13
));
}
else
{
panic!
(
"expected to have an assignee for the issue"
);
...
...
@@ -297,7 +293,7 @@ fn test_read_member() {
member
.avatar_url
,
Some
(
"https://secure.gravatar.com/avatar/9ddcd45fcb89d966aab95b1f1002f84c?s=80&d=identicon"
.to
_string
()
.
in
to
()
),
);
assert_eq!
(
member
.web_url
,
"https://gitlab.kitware.com/kwrobot"
);
...
...
@@ -313,7 +309,7 @@ fn test_read_merge_request() {
assert_eq!
(
merge_request
.iid
,
MergeRequestInternalId
::
new
(
35
));
assert_eq!
(
merge_request
.project_id
,
ProjectId
::
new
(
855
));
assert_eq!
(
merge_request
.title
,
"gitlab: expose hook addition API"
);
assert_eq!
(
merge_request
.description
,
Some
(
"Fixes #5."
.to
_string
()));
assert_eq!
(
merge_request
.description
,
Some
(
"Fixes #5."
.
in
to
()));
assert_eq!
(
merge_request
.state
,
MergeRequestState
::
Merged
);
assert_eq!
(
merge_request
.created_at
,
...
...
@@ -344,7 +340,7 @@ fn test_read_merge_request() {
merge_request
.author.avatar_url
,
Some
(
"https://secure.gravatar.com/avatar/2f5f7e99190174edb5a2f66b8653b0b2?s=80&d=identicon"
.to
_string
()
.
in
to
()
),
);
assert_eq!
(
merge_request
.author.id
,
UserId
::
new
(
13
));
...
...
@@ -354,7 +350,7 @@ fn test_read_merge_request() {
assert_eq!
(
assignee
.name
,
"Brad King"
);
assert_eq!
(
assignee
.state
,
UserState
::
Active
);
assert_eq!
(
assignee
.avatar_url
,
Some
(
"https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon"
.to
_string
()));
Some
(
"https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon"
.
in
to
()));
assert_eq!
(
assignee
.id
,
UserId
::
new
(
10
));
}
else
{
panic!
(
"expected to have an assignee for the merge request"
);
...
...
@@ -367,7 +363,7 @@ fn test_read_merge_request() {
assert_eq!
(
assignee
.name
,
"Brad King"
);
assert_eq!
(
assignee
.state
,
UserState
::
Active
);
assert_eq!
(
assignee
.avatar_url
,
Some
(
"https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon"
.to
_string
()));
Some
(
"https://secure.gravatar.com/avatar/0617392a2f9fd505720d0c42cefc1a10?s=80&d=identicon"
.
in
to
()));
assert_eq!
(
assignee
.id
,
UserId
::
new
(
10
));
}
else
{
panic!
(
"expected to have assignees for the merge request"
);
...
...
@@ -406,7 +402,7 @@ fn test_read_merge_request() {
assert_eq!
(
merge_request
.time_stats.total_time_spent
,
0
);
assert_eq!
(
merge_request
.time_stats.human_time_estimate
,
None
);
assert_eq!
(
merge_request
.time_stats.human_total_time_spent
,
None
);
assert_eq!
(
merge_request
.changes_count
,
Some
(
"3"
.to
_string
()));
assert_eq!
(
merge_request
.changes_count
,
Some
(
"3"
.
in
to
()));
assert_eq!
(
merge_request
.user_notes_count
,
3
);
assert_eq!
(
merge_request
.discussion_locked
,
None
);
assert_eq!
(
merge_request
.should_remove_source_branch
,
None
);
...
...
@@ -433,7 +429,7 @@ fn test_read_note() {
note
.author.avatar_url
,
Some
(
"https://secure.gravatar.com/avatar/9ddcd45fcb89d966aab95b1f1002f84c?s=80&d=identicon"
.to
_string
()
.
in
to
()
),
);
assert_eq!
(
note
.author.id
,
UserId
::
new
(
11
));
...
...
@@ -538,9 +534,9 @@ fn test_read_project() {
assert_eq!
(
project
.id
,
ProjectId
::
new
(
855
));
assert_eq!
(
project
.description
,
Some
(
"Rust library for communicating with a Gitlab instance."
.to
_string
()),
Some
(
"Rust library for communicating with a Gitlab instance."
.
in
to
()),
);
assert_eq!
(
project
.default_branch
,
Some
(
"master"
.to
_string
()));
assert_eq!
(
project
.default_branch
,
Some
(
"master"
.
in
to
()));
assert!
(
project
.tag_list
.is_empty
());
assert_eq!
(
project
.archived
,
false
);
assert_eq!
(
project
.empty_repo
,
false
);
...
...
@@ -559,7 +555,7 @@ fn test_read_project() {
);
assert_eq!
(
project
.readme_url
,
Some
(
"https://gitlab.kitware.com/utils/rust-gitlab/blob/master/README.md"
.to
_string
()),
Some
(
"https://gitlab.kitware.com/utils/rust-gitlab/blob/master/README.md"
.
in
to
()),
);
assert!
(
project
.owner
.is_none
());
assert_eq!
(
project
.name
,
"rust-gitlab"
);
...
...
@@ -635,7 +631,7 @@ fn test_read_project() {
);
assert_eq!
(
project
.wiki_access_level
,
FeatureVisibilityLevel
::
Enabled
);
assert_eq!
(
project
.merge_method
,
Some
(
"merge"
.to
_string
()));
assert_eq!
(
project
.merge_method
,
Some
(
"merge"
.
in
to
()));
if
let
Some
(
ref
permissions
)
=
project
.permissions
{
if
let
Some
(
ref
group_access
)
=
permissions
.group_access
{
assert_eq!
(
group_access
.access_level
,
50
);
...
...
@@ -767,7 +763,7 @@ fn test_read_repo_commit_detail() {
}
if
let
Some
(
ref
last_pipeline
)
=
repo_commit_detail
.last_pipeline
{
assert_eq!
(
last_pipeline
.id
,
PipelineId
::
new
(
34289
));
assert_eq!
(
last_pipeline
.ref_
,
Some
(
"master"
.to
_string
()));
assert_eq!
(
last_pipeline
.ref_
,
Some
(
"master"
.
in
to
()));
assert_eq!
(
last_pipeline
.sha
,
ObjectId
::
new
(
"de4ac3cf96cb8a0893be22b03f5171d934f9d392"
),
...
...
@@ -775,7 +771,7 @@ fn test_read_repo_commit_detail() {
assert_eq!
(
last_pipeline
.status
,
StatusState
::
Success
);
assert_eq!
(
last_pipeline
.web_url
,
"https://gitlab.kitware.com/utils/rust-gitlab/pipelines/34289"
.to_string
()
,
"https://gitlab.kitware.com/utils/rust-gitlab/pipelines/34289"
,
);
}
else
{
panic!
(
"expected to have a last_pipeline for this commit"
);
...
...
@@ -795,7 +791,7 @@ fn test_read_user() {
user
.avatar_url
,
Some
(
"https://secure.gravatar.com/avatar/9ddcd45fcb89d966aab95b1f1002f84c?s=80&d=identicon"
.to
_string
()
.
in
to
()
),
);
assert_eq!
(
user
.web_url
,
"https://gitlab.kitware.com/kwrobot"
);
...
...
@@ -805,10 +801,10 @@ fn test_read_user() {
);
assert_eq!
(
user
.is_admin
,
None
);
assert_eq!
(
user
.highest_role
,
Some
(
AccessLevel
::
Owner
));
assert_eq!
(
user
.bio
,
Some
(
""
.to
_string
()));
assert_eq!
(
user
.bio
,
Some
(
""
.
in
to
()));
assert_eq!
(
user
.private_profile
,
Some
(
false
));
assert_eq!
(
user
.location
,
None
);
assert_eq!
(
user
.public_email
,
Some
(
""
.to
_string
()));
assert_eq!
(
user
.public_email
,
Some
(
""
.
in
to
()));
assert_eq!
(
user
.skype
,
""
);
assert_eq!
(
user
.linkedin
,
""
);
assert_eq!
(
user
.twitter
,
""
);
...
...
@@ -828,7 +824,7 @@ fn test_read_user_public() {
user_public
.avatar_url
,
Some
(
"https://secure.gravatar.com/avatar/9ddcd45fcb89d966aab95b1f1002f84c?s=80&d=identicon"
.to
_string
()
.
in
to
()
),
);
assert_eq!
(
user_public
.web_url
,
"https://gitlab.kitware.com/kwrobot"
);
...
...
@@ -837,10 +833,10 @@ fn test_read_user_public() {
Some
(
Utc
.ymd
(
2015
,
2
,
26
)
.and_hms_milli
(
15
,
58
,
34
,
670
)),
);
assert_eq!
(
user_public
.is_admin
,
Some
(
true
));
assert_eq!
(
user_public
.bio
,
Some
(
""
.to
_string
()));
assert_eq!
(
user_public
.bio
,
Some
(
""
.
in
to
()));
assert_eq!
(
user_public
.private_profile
,
Some
(
false
));
assert_eq!
(
user_public
.location
,
None
);
assert_eq!
(
user_public
.public_email
,
Some
(
""
.to
_string
()));
assert_eq!
(
user_public
.public_email
,
Some
(
""
.
in
to
()));
assert_eq!
(
user_public
.skype
,
""
);
assert_eq!
(
user_public
.linkedin
,
""
);
assert_eq!
(
user_public
.twitter
,
""
);
...
...
@@ -892,7 +888,7 @@ fn test_read_resoruce_label_events() {
assert_eq!
(
label
.id
,
LabelId
::
new
(
1720
));
assert_eq!
(
label
.name
,
"area:doc"
);
assert_eq!
(
label
.color
,
LabelColor
::
from_rgb
(
0x58
,
0x43
,
0xAD
));
assert_eq!
(
label
.description
,
Some
(
"Documentation issues"
.to
_string
()));
assert_eq!
(
label
.description
,
Some
(
"Documentation issues"
.
in
to
()));
}
#[test]
...
...
@@ -901,10 +897,10 @@ fn test_read_pipelines() {
assert_eq!
(
pipeline_basic
.id
,
PipelineId
::
new
(
145400
));
assert_eq!
(
pipeline_basic
.status
,
StatusState
::
Success
);
assert_eq!
(
pipeline_basic
.ref_
,
Some
(
"master"
.to
_string
()));
assert_eq!
(
pipeline_basic
.ref_
,
Some
(
"master"
.
in
to
()));
assert_eq!
(
pipeline_basic
.sha
,
ObjectId
::
new
(
"7134adce4522c399cdab16e128b0a1af15b93f14"
.to_string
()
),
ObjectId
::
new
(
"7134adce4522c399cdab16e128b0a1af15b93f14"
),
);
assert_eq!
(
pipeline_basic
.web_url
,
...
...
@@ -918,10 +914,10 @@ 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
.ref_
,
Some
(
"master"
.
in
to
()));
assert_eq!
(
pipeline
.sha
,
ObjectId
::
new
(
"7134adce4522c399cdab16e128b0a1af15b93f14"
.to_string
()
),
ObjectId
::
new
(
"7134adce4522c399cdab16e128b0a1af15b93f14"
),
);
assert_eq!
(
pipeline
.before_sha
,
None
);
assert_eq!
(
pipeline
.tag
,
false
);
...
...
src/types.rs
View file @
3a55a767
...
...
@@ -1493,7 +1493,7 @@ impl Issue {
has_tasks
:
None
,
confidential
:
false
,
discussion_locked
:
None
,
web_url
:
""
.to
_string
(),
web_url
:
""
.
in
to
(),
_links
:
None
,
}
}
...
...
@@ -2388,7 +2388,7 @@ impl Event {
EventTargetType
::
Commit
=>
{
self
.target_id
.as_str
()
.map
(|
id
|
EventTargetId
::
Commit
(
ObjectId
(
id
.to
_string
())))
.map
(|
id
|
EventTargetId
::
Commit
(
ObjectId
(
id
.
in
to
())))
},
EventTargetType
::
Issue
=>
{
self
.target_id
...
...
src/webhooks.rs
View file @
3a55a767
...
...
@@ -760,7 +760,8 @@ impl<'de> Deserialize<'de> for WebHook {
let
val
=
<
Value
as
Deserialize
>
::
deserialize
(
deserializer
)
?
;
let
object_kind
=
match
val
.pointer
(
"/object_kind"
)
{
Some
(
&
Value
::
String
(
ref
kind
))
=>
kind
.to_string
(),
// XXX(1.36.0): NLL makes this clone unnecessary.
Some
(
&
Value
::
String
(
ref
kind
))
=>
kind
.clone
(),
Some
(
_
)
=>
{
return
Err
(
D
::
Error
::
invalid_type
(
Unexpected
::
Other
(
"JSON value"
),
...
...
@@ -772,7 +773,7 @@ impl<'de> Deserialize<'de> for WebHook {
},
};
let
hook_res
=
match
object_kind
.as_
str
()
{
let
hook_res
=
match
object_kind
.as_
ref
()
{
"push"
|
"tag_push"
=>
serde_json
::
from_value
(
val
)
.map
(
WebHook
::
Push
),
"issue"
=>
serde_json
::
from_value
(
val
)
.map
(
WebHook
::
Issue
),
...
...
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