Commit 7146e11a authored by Ben Boeckel's avatar Ben Boeckel
Browse files

rustfmt: apply style changes

parent 7c4c42a2
......@@ -176,14 +176,17 @@ impl Gitlab {
}
/// Get comments on a commit.
pub fn commit_comments(&self, project: ProjectId, commit: &str) -> GitlabResult<Vec<CommitNote>> {
pub fn commit_comments(&self, project: ProjectId, commit: &str)
-> GitlabResult<Vec<CommitNote>> {
self._get_paged(&format!("projects/{}/repository/commit/{}/comments", project, commit))
}
/// Get comments on a commit.
pub fn create_commit_comment(&self, project: ProjectId, commit: &str, body: &str)
-> GitlabResult<CommitNote> {
let mut req = try!(self._mkrequest(&format!("projects/{}/repository/commit/{}/comment", project, commit)));
let mut req = try!(self._mkrequest(&format!("projects/{}/repository/commit/{}/comment",
project,
commit)));
req.param("note", body);
......@@ -197,7 +200,9 @@ impl Gitlab {
let line_str = format!("{}", line);
let line_type = LineType::New;
let mut req = try!(self._mkrequest(&format!("projects/{}/repository/commit/{}/comment", project, commit)));
let mut req = try!(self._mkrequest(&format!("projects/{}/repository/commit/{}/comment",
project,
commit)));
req.param("note", body)
.param("path", path)
......@@ -248,26 +253,19 @@ impl Gitlab {
}
/// Get issues.
pub fn issue(&self, project: ProjectId, issue: IssueId)
-> GitlabResult<Issue> {
pub fn issue(&self, project: ProjectId, issue: IssueId) -> GitlabResult<Issue> {
self._get(&format!("projects/{}/issues/{}", project, issue))
}
/// Get the notes from a issue.
pub fn issue_notes(&self, project: ProjectId, issue: IssueId)
-> GitlabResult<Vec<Note>> {
self._get_paged(&format!("projects/{}/issues/{}/notes",
project,
issue))
pub fn issue_notes(&self, project: ProjectId, issue: IssueId) -> GitlabResult<Vec<Note>> {
self._get_paged(&format!("projects/{}/issues/{}/notes", project, issue))
}
/// Create a note on a issue.
pub fn create_issue_note(&self, project: ProjectId, issue: IssueId,
content: &str)
pub fn create_issue_note(&self, project: ProjectId, issue: IssueId, content: &str)
-> GitlabResult<Note> {
let path = &format!("projects/{}/issues/{}/notes",
project,
issue);
let path = &format!("projects/{}/issues/{}/notes", project, issue);
let mut req = try!(self._mkrequest(path));
......
......@@ -29,17 +29,13 @@ impl Deserialize for GitlabHook {
// Look for `object_kind` first because some web hooks also have `event_name` which would
// cause a false match here.
let hook_res = if let Some(_) = val.pointer("/object_kind") {
from_value(val)
.map(GitlabHook::Web)
from_value(val).map(GitlabHook::Web)
} else if let Some(_) = val.pointer("/event_name") {
from_value(val)
.map(GitlabHook::System)
from_value(val).map(GitlabHook::System)
} else {
return Err(D::Error::missing_field("either object_kind or event_name"));
};
hook_res.map_err(|err| {
D::Error::invalid_value(&format!("{:?}", err))
})
hook_res.map_err(|err| D::Error::invalid_value(&format!("{:?}", err)))
}
}
......@@ -280,53 +280,45 @@ impl Deserialize for SystemHook {
"project_destroy" |
"project_rename" |
"project_transfer" => {
from_value(val)
.map(SystemHook::Project)
from_value(val).map(SystemHook::Project)
},
"user_add_to_team" |
"user_remove_from_team" => {
from_value(val)
.map(SystemHook::ProjectMember)
from_value(val).map(SystemHook::ProjectMember)
},
"user_create" |
"user_destroy" => {
from_value(val)
.map(SystemHook::User)
from_value(val).map(SystemHook::User)
},
"key_create" |
"key_destroy" => {
from_value(val)
.map(SystemHook::Key)
from_value(val).map(SystemHook::Key)
},
"group_create" |
"group_destroy" => {
from_value(val)
.map(SystemHook::Group)
from_value(val).map(SystemHook::Group)
},
"user_add_to_group" |
"user_remove_from_group" => {
from_value(val)
.map(SystemHook::GroupMember)
from_value(val).map(SystemHook::GroupMember)
},
"push" |
"tag_push" => {
from_value(val)
.map(SystemHook::Push)
from_value(val).map(SystemHook::Push)
},
_ => {
return Err(D::Error::invalid_value(&format!("unrecognized system event name: {}", event_name)));
return Err(D::Error::invalid_value(&format!("unrecognized system event name: {}",
event_name)));
},
};
hook_res.map_err(|err| {
D::Error::invalid_value(&format!("{:?}", err))
})
hook_res.map_err(|err| D::Error::invalid_value(&format!("{:?}", err)))
}
}
......@@ -63,8 +63,8 @@ pub struct UserBasic {
pub web_url: String,
}
pub trait UserResult : Serialize + Deserialize { }
impl<T: Serialize + Deserialize + Into<UserBasic>> UserResult for T { }
pub trait UserResult: Serialize + Deserialize {}
impl<T: Serialize + Deserialize + Into<UserBasic>> UserResult for T {}
#[derive(Serialize, Deserialize, Debug)]
/// More detailed information only accessible to administrators.
......@@ -832,13 +832,8 @@ impl Deserialize for IssueReference {
from_value::<Issue>(val.clone())
.map(IssueReference::Internal)
.or_else(|_| {
from_value::<ExternalIssue>(val)
.map(IssueReference::External)
})
.map_err(|err| {
D::Error::invalid_value(&format!("{:?}", err))
})
.or_else(|_| from_value::<ExternalIssue>(val).map(IssueReference::External))
.map_err(|err| D::Error::invalid_value(&format!("{:?}", err)))
}
}
......@@ -1033,28 +1028,24 @@ impl Note {
pub fn noteable_id(&self) -> Option<NoteableId> {
match self.noteable_type {
NoteType::Commit => {
self.noteable_id.as_string()
.map(|id| {
NoteableId::Commit(ObjectId::new(id))
})
self.noteable_id
.as_string()
.map(|id| NoteableId::Commit(ObjectId::new(id)))
},
NoteType::Issue => {
self.noteable_id.as_u64()
.map(|id| {
NoteableId::Issue(IssueId::new(id))
})
self.noteable_id
.as_u64()
.map(|id| NoteableId::Issue(IssueId::new(id)))
},
NoteType::MergeRequest => {
self.noteable_id.as_u64()
.map(|id| {
NoteableId::MergeRequest(MergeRequestId::new(id))
})
self.noteable_id
.as_u64()
.map(|id| NoteableId::MergeRequest(MergeRequestId::new(id)))
},
NoteType::Snippet => {
self.noteable_id.as_u64()
.map(|id| {
NoteableId::Snippet(SnippetId::new(id))
})
self.noteable_id
.as_u64()
.map(|id| NoteableId::Snippet(SnippetId::new(id)))
},
}
}
......@@ -1176,34 +1167,29 @@ impl Event {
pub fn event_target_id(&self) -> Option<EventTargetId> {
match self.target_type {
EventTargetType::Commit => {
self.target_id.as_string()
.map(|id| {
EventTargetId::Commit(ObjectId(id.to_string()))
})
self.target_id
.as_string()
.map(|id| EventTargetId::Commit(ObjectId(id.to_string())))
},
EventTargetType::Issue => {
self.target_id.as_u64()
.map(|id| {
EventTargetId::Issue(IssueId(id))
})
self.target_id
.as_u64()
.map(|id| EventTargetId::Issue(IssueId(id)))
},
EventTargetType::MergeRequest => {
self.target_id.as_u64()
.map(|id| {
EventTargetId::MergeRequest(MergeRequestId(id))
})
self.target_id
.as_u64()
.map(|id| EventTargetId::MergeRequest(MergeRequestId(id)))
},
EventTargetType::Snippet => {
self.target_id.as_u64()
.map(|id| {
EventTargetId::Snippet(SnippetId(id))
})
self.target_id
.as_u64()
.map(|id| EventTargetId::Snippet(SnippetId(id)))
},
EventTargetType::ProjectSnippet => {
self.target_id.as_u64()
.map(|id| {
EventTargetId::Snippet(SnippetId(id))
})
self.target_id
.as_u64()
.map(|id| EventTargetId::Snippet(SnippetId(id)))
},
}
}
......
......@@ -16,7 +16,8 @@ use self::serde::de::{Error, Type};
extern crate serde_json;
use self::serde_json::{from_value, Value};
use super::types::{BuildId, IssueId, IssueState, MergeRequestId, MergeRequestState, MergeStatus, MilestoneId, NoteableId, NoteId, ObjectId, ProjectId, SnippetId, UserId};
use super::types::{BuildId, IssueId, IssueState, MergeRequestId, MergeRequestState, MergeStatus,
MilestoneId, NoteableId, NoteId, ObjectId, ProjectId, SnippetId, UserId};
#[derive(Debug)]
pub struct HookDate(DateTime<UTC>);
......@@ -34,12 +35,8 @@ impl Deserialize for HookDate {
UTC.datetime_from_str(&val, "%Y-%m-%d %H:%M:%S UTC")
.or_else(|_| {
DateTime::parse_from_str(&val, "%Y-%m-%d %H:%M:%S %z")
.map_err(|err| {
D::Error::invalid_value(&format!("{:?}", err))
})
.map(|dt| {
dt.with_timezone(&UTC)
})
.map_err(|err| D::Error::invalid_value(&format!("{:?}", err)))
.map(|dt| dt.with_timezone(&UTC))
})
.map(HookDate)
}
......@@ -153,7 +150,8 @@ pub enum IssueAction {
Open,
Close,
Reopen,
}enum_serialize!(IssueAction -> "issue action",
}
enum_serialize!(IssueAction -> "issue action",
Update => "update",
Open => "open",
Close => "close",
......@@ -219,7 +217,9 @@ pub struct MergeRequestParams {
impl MergeRequestParams {
// https://gitlab.com/gitlab-org/gitlab-ce/issues/20880
pub fn force_remove_source_branch(&self) -> bool {
self.force_remove_source_branch.as_ref().map(|val| {
self.force_remove_source_branch
.as_ref()
.map(|val| {
if let Some(as_str) = val.as_string() {
as_str == "1"
} else if let Some(as_bool) = val.as_boolean() {
......@@ -365,7 +365,7 @@ pub enum NoteHookType {
Commit,
Issue,
MergeRequest,
Snippet
Snippet,
}
enum_serialize!(NoteHookType -> "note hook type",
Commit => "Commit",
......@@ -407,28 +407,24 @@ impl NoteHookAttrs {
pub fn noteable_id(&self) -> Option<NoteableId> {
match self.noteable_type {
NoteHookType::Commit => {
self.noteable_id.as_string()
.map(|id| {
NoteableId::Commit(ObjectId::new(id))
})
self.noteable_id
.as_string()
.map(|id| NoteableId::Commit(ObjectId::new(id)))
},
NoteHookType::Issue => {
self.noteable_id.as_u64()
.map(|id| {
NoteableId::Issue(IssueId::new(id))
})
self.noteable_id
.as_u64()
.map(|id| NoteableId::Issue(IssueId::new(id)))
},
NoteHookType::MergeRequest => {
self.noteable_id.as_u64()
.map(|id| {
NoteableId::MergeRequest(MergeRequestId::new(id))
})
self.noteable_id
.as_u64()
.map(|id| NoteableId::MergeRequest(MergeRequestId::new(id)))
},
NoteHookType::Snippet => {
self.noteable_id.as_u64()
.map(|id| {
NoteableId::Snippet(SnippetId::new(id))
})
self.noteable_id
.as_u64()
.map(|id| NoteableId::Snippet(SnippetId::new(id)))
},
}
}
......@@ -552,37 +548,31 @@ impl Deserialize for WebHook {
let hook_res = match object_kind.as_str() {
"push" |
"tag_push" => {
from_value(val)
.map(WebHook::Push)
from_value(val).map(WebHook::Push)
},
"issue" => {
from_value(val)
.map(WebHook::Issue)
from_value(val).map(WebHook::Issue)
},
"merge_request" => {
from_value(val)
.map(WebHook::MergeRequest)
from_value(val).map(WebHook::MergeRequest)
},
"note" => {
from_value(val)
.map(WebHook::Note)
from_value(val).map(WebHook::Note)
},
"build" => {
from_value(val)
.map(WebHook::Build)
from_value(val).map(WebHook::Build)
},
_ => {
return Err(D::Error::invalid_value(&format!("unrecognized webhook object kind: {}", object_kind)));
return Err(D::Error::invalid_value(&format!("unrecognized webhook object kind: {}",
object_kind)));
},
};
hook_res.map_err(|err| {
D::Error::invalid_value(&format!("{:?}", err))
})
hook_res.map_err(|err| D::Error::invalid_value(&format!("{:?}", err)))
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment