Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
rust-gitlab
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
15
Issues
15
List
Boards
Labels
Service Desk
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Utils
rust-gitlab
Commits
6c7c2ffe
Commit
6c7c2ffe
authored
Mar 26, 2019
by
Ben Boeckel
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rustfmt: apply suggestions
parent
eaaf5ad8
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
1040 additions
and
639 deletions
+1040
-639
src/error.rs
src/error.rs
+2
-1
src/gitlab.rs
src/gitlab.rs
+513
-283
src/hooks.rs
src/hooks.rs
+7
-4
src/lib.rs
src/lib.rs
+2
-2
src/systemhooks.rs
src/systemhooks.rs
+28
-21
src/test/types.rs
src/test/types.rs
+333
-180
src/types.rs
src/types.rs
+103
-106
src/webhooks.rs
src/webhooks.rs
+52
-42
No files found.
src/error.rs
View file @
6c7c2ffe
...
...
@@ -40,7 +40,8 @@ error_chain! {
impl
Error
{
/// Extract the message from a Gitlab JSON error.
pub
fn
from_gitlab
(
value
:
Value
)
->
Self
{
let
msg
=
value
.pointer
(
"/message"
)
let
msg
=
value
.pointer
(
"/message"
)
.and_then
(|
s
|
s
.as_str
())
.unwrap_or_else
(||
"unknown error"
);
...
...
src/gitlab.rs
View file @
6c7c2ffe
This diff is collapsed.
Click to expand it.
src/hooks.rs
View file @
6c7c2ffe
...
...
@@ -11,8 +11,8 @@
//! Gitlab does not have consistent structures for its hooks, so they often change from
//! version to version.
use
crates
::
serde
::{
Deserialize
,
Deserializer
};
use
crates
::
serde
::
de
::{
Error
,
Unexpected
};
use
crates
::
serde
::{
Deserialize
,
Deserializer
};
use
crates
::
serde_json
::{
self
,
Value
};
use
systemhooks
::
SystemHook
;
...
...
@@ -29,7 +29,8 @@ pub enum GitlabHook {
impl
<
'de
>
Deserialize
<
'de
>
for
GitlabHook
{
fn
deserialize
<
D
>
(
deserializer
:
D
)
->
Result
<
Self
,
D
::
Error
>
where
D
:
Deserializer
<
'de
>
,
where
D
:
Deserializer
<
'de
>
,
{
let
val
=
<
Value
as
Deserialize
>
::
deserialize
(
deserializer
)
?
;
...
...
@@ -44,8 +45,10 @@ impl<'de> Deserialize<'de> for GitlabHook {
};
hook_res
.map_err
(|
err
|
{
D
::
Error
::
invalid_value
(
Unexpected
::
Other
(
"gitlab hook"
),
&
format!
(
"{:?}"
,
err
)
.as_str
())
D
::
Error
::
invalid_value
(
Unexpected
::
Other
(
"gitlab hook"
),
&
format!
(
"{:?}"
,
err
)
.as_str
(),
)
})
}
}
src/lib.rs
View file @
6c7c2ffe
...
...
@@ -36,16 +36,16 @@ mod error;
mod
macros
;
mod
gitlab
;
pub
mod
hooks
;
pub
mod
systemhooks
;
pub
mod
types
;
pub
mod
webhooks
;
pub
mod
hooks
;
pub
use
error
::
*
;
pub
use
gitlab
::
CommitStatusInfo
;
pub
use
gitlab
::
MergeRequestStateFilter
;
pub
use
gitlab
::
Gitlab
;
pub
use
gitlab
::
GitlabBuilder
;
pub
use
gitlab
::
MergeRequestStateFilter
;
pub
use
types
::
*
;
#[cfg(test)]
...
...
src/systemhooks.rs
View file @
6c7c2ffe
...
...
@@ -13,8 +13,8 @@
//! version to version.
use
crates
::
chrono
::{
DateTime
,
Utc
};
use
crates
::
serde
::{
Deserialize
,
Deserializer
,
Serialize
,
Serializer
};
use
crates
::
serde
::
de
::{
Error
,
Unexpected
};
use
crates
::
serde
::{
Deserialize
,
Deserializer
,
Serialize
,
Serializer
};
use
crates
::
serde_json
::{
self
,
Value
};
use
types
::{
AccessLevel
,
GroupId
,
ObjectId
,
ProjectId
,
SshKeyId
,
UserId
};
...
...
@@ -55,7 +55,7 @@ enum_serialize!(ProjectVisibility -> "project visibility",
Public
=>
"public"
;
"visibilitylevel|public"
,
);
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// A hook for a project.
pub
struct
ProjectSystemHook
{
...
...
@@ -131,7 +131,7 @@ impl From<HumanAccessLevel> for AccessLevel {
}
}
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// A project membership hook.
pub
struct
ProjectMemberSystemHook
{
...
...
@@ -176,7 +176,7 @@ enum_serialize!(UserEvent -> "user event",
Destroy
=>
"user_destroy"
,
);
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// A user hook.
pub
struct
UserSystemHook
{
...
...
@@ -209,7 +209,7 @@ enum_serialize!(KeyEvent -> "key event",
Destroy
=>
"key_destroy"
,
);
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// An SSH key hook.
pub
struct
KeySystemHook
{
...
...
@@ -240,7 +240,7 @@ enum_serialize!(GroupEvent -> "group event",
Destroy
=>
"group_destroy"
,
);
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// A group hook.
pub
struct
GroupSystemHook
{
...
...
@@ -275,7 +275,7 @@ enum_serialize!(GroupMemberEvent -> "group member event",
Remove
=>
"user_remove_from_group"
,
);
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// A group membership hook.
pub
struct
GroupMemberSystemHook
{
...
...
@@ -316,7 +316,7 @@ enum_serialize!(PushEvent -> "push event",
TagPush
=>
"tag_push"
,
);
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// A push hook.
pub
struct
PushSystemHook
{
...
...
@@ -332,7 +332,7 @@ pub struct PushSystemHook {
pub
before
:
ObjectId
,
/// The new object ID of the ref that was pushed.
pub
after
:
ObjectId
,
#[serde(rename
=
"ref"
)]
#[serde(rename
=
"ref"
)]
/// The name of the reference that was pushed.
pub
ref_
:
String
,
/// The new object ID of the ref that was pushed.
...
...
@@ -381,14 +381,18 @@ pub enum SystemHook {
impl
<
'de
>
Deserialize
<
'de
>
for
SystemHook
{
fn
deserialize
<
D
>
(
deserializer
:
D
)
->
Result
<
Self
,
D
::
Error
>
where
D
:
Deserializer
<
'de
>
,
where
D
:
Deserializer
<
'de
>
,
{
let
val
=
<
Value
as
Deserialize
>
::
deserialize
(
deserializer
)
?
;
let
event_name
=
match
val
.pointer
(
"/event_name"
)
{
Some
(
&
Value
::
String
(
ref
name
))
=>
name
.to_string
(),
Some
(
_
)
=>
{
return
Err
(
D
::
Error
::
invalid_type
(
Unexpected
::
Other
(
"JSON value"
),
&
"a string"
));
return
Err
(
D
::
Error
::
invalid_type
(
Unexpected
::
Other
(
"JSON value"
),
&
"a string"
,
));
},
None
=>
{
return
Err
(
D
::
Error
::
missing_field
(
"event_name"
));
...
...
@@ -396,13 +400,13 @@ impl<'de> Deserialize<'de> for SystemHook {
};
let
hook_res
=
match
event_name
.as_str
()
{
"project_create"
|
"project_destroy"
|
"project_rename"
|
"project_transfer"
=>
serde_json
::
from_value
(
val
)
.map
(
SystemHook
::
Project
),
"project_create"
|
"project_destroy"
|
"project_rename"
|
"project_transfer"
=>
{
serde_json
::
from_value
(
val
)
.map
(
SystemHook
::
Project
)
},
"user_add_to_team"
|
"user_remove_from_team"
=>
serde_json
::
from_value
(
val
)
.map
(
SystemHook
::
ProjectMember
),
"user_add_to_team"
|
"user_remove_from_team"
=>
{
serde_json
::
from_value
(
val
)
.map
(
SystemHook
::
ProjectMember
)
},
"user_create"
|
"user_destroy"
=>
serde_json
::
from_value
(
val
)
.map
(
SystemHook
::
User
),
...
...
@@ -410,14 +414,17 @@ impl<'de> Deserialize<'de> for SystemHook {
"group_create"
|
"group_destroy"
=>
serde_json
::
from_value
(
val
)
.map
(
SystemHook
::
Group
),
"user_add_to_group"
|
"user_remove_from_group"
=>
serde_json
::
from_value
(
val
)
.map
(
SystemHook
::
GroupMember
),
"user_add_to_group"
|
"user_remove_from_group"
=>
{
serde_json
::
from_value
(
val
)
.map
(
SystemHook
::
GroupMember
)
},
"push"
|
"tag_push"
=>
serde_json
::
from_value
(
val
)
.map
(
SystemHook
::
Push
),
_
=>
{
return
Err
(
D
::
Error
::
custom
(
format!
(
"unrecognized system event name: {}"
,
event_name
)));
return
Err
(
D
::
Error
::
custom
(
format!
(
"unrecognized system event name: {}"
,
event_name
,
)));
},
};
...
...
src/test/types.rs
View file @
6c7c2ffe
This diff is collapsed.
Click to expand it.
src/types.rs
View file @
6c7c2ffe
This diff is collapsed.
Click to expand it.
src/webhooks.rs
View file @
6c7c2ffe
...
...
@@ -12,13 +12,15 @@
//! version to version.
use
crates
::
chrono
::{
DateTime
,
NaiveDate
,
TimeZone
,
Utc
};
use
crates
::
serde
::{
Deserialize
,
Deserializer
,
Serialize
,
Serializer
};
use
crates
::
serde
::
de
::{
Error
,
Unexpected
};
use
crates
::
serde
::{
Deserialize
,
Deserializer
,
Serialize
,
Serializer
};
use
crates
::
serde_json
::{
self
,
Value
};
use
types
::{
JobId
,
IssueId
,
IssueInternalId
,
IssueState
,
MergeRequestId
,
MergeRequestInternalId
,
MergeRequestState
,
MergeStatus
,
MilestoneId
,
NoteId
,
NoteType
,
NoteableId
,
ObjectId
,
ProjectId
,
SnippetId
,
UserId
};
use
types
::{
IssueId
,
IssueInternalId
,
IssueState
,
JobId
,
MergeRequestId
,
MergeRequestInternalId
,
MergeRequestState
,
MergeStatus
,
MilestoneId
,
NoteId
,
NoteType
,
NoteableId
,
ObjectId
,
ProjectId
,
SnippetId
,
UserId
,
};
#[derive(Debug,
Clone,
Copy)]
/// A wrapper struct for dates in web hooks.
...
...
@@ -35,7 +37,8 @@ impl Serialize for HookDate {
impl
<
'de
>
Deserialize
<
'de
>
for
HookDate
{
fn
deserialize
<
D
>
(
deserializer
:
D
)
->
Result
<
Self
,
D
::
Error
>
where
D
:
Deserializer
<
'de
>
,
where
D
:
Deserializer
<
'de
>
,
{
let
val
=
String
::
deserialize
(
deserializer
)
?
;
...
...
@@ -43,8 +46,10 @@ impl<'de> Deserialize<'de> for HookDate {
.or_else
(|
_
|
{
DateTime
::
parse_from_str
(
&
val
,
"%Y-%m-%d %H:%M:%S %z"
)
.map_err
(|
err
|
{
D
::
Error
::
invalid_value
(
Unexpected
::
Other
(
"hook date"
),
&
format!
(
"{:?}"
,
err
)
.as_str
())
D
::
Error
::
invalid_value
(
Unexpected
::
Other
(
"hook date"
),
&
format!
(
"{:?}"
,
err
)
.as_str
(),
)
})
.map
(|
dt
|
dt
.with_timezone
(
&
Utc
))
})
...
...
@@ -58,7 +63,7 @@ impl AsRef<DateTime<Utc>> for HookDate {
}
}
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// Project information exposed in hooks.
pub
struct
ProjectHookAttrs
{
...
...
@@ -88,7 +93,7 @@ pub struct ProjectHookAttrs {
url
:
String
,
}
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// Wiki project information exposed in hooks.
pub
struct
ProjectWikiHookAttrs
{
...
...
@@ -104,7 +109,7 @@ pub struct ProjectWikiHookAttrs {
pub
default_branch
:
String
,
}
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// User information exposed in hooks.
pub
struct
UserHookAttrs
{
...
...
@@ -116,7 +121,7 @@ pub struct UserHookAttrs {
pub
avatar_url
:
Option
<
String
>
,
}
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// The identity of a user exposed through a hook.
pub
struct
HookCommitIdentity
{
...
...
@@ -126,7 +131,7 @@ pub struct HookCommitIdentity {
pub
email
:
String
,
}
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// Commit information exposed in hooks.
pub
struct
CommitHookAttrs
{
...
...
@@ -144,7 +149,7 @@ pub struct CommitHookAttrs {
pub
removed
:
Option
<
Vec
<
String
>>
,
}
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// A push hook.
pub
struct
PushHook
{
...
...
@@ -156,7 +161,7 @@ pub struct PushHook {
pub
before
:
ObjectId
,
/// The new object ID of the ref after the push.
pub
after
:
ObjectId
,
#[serde(rename
=
"ref"
)]
#[serde(rename
=
"ref"
)]
/// The name of the reference which has been pushed.
pub
ref_
:
String
,
/// The new object ID of the ref after the push.
...
...
@@ -205,7 +210,7 @@ enum_serialize!(IssueAction -> "issue action",
Reopen
=>
"reopen"
,
);
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// Issue information exposed in hooks.
pub
struct
IssueHookAttrs
{
...
...
@@ -260,7 +265,7 @@ pub struct IssueHookAttrs {
pub
action
:
Option
<
IssueAction
>
,
}
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// An issue hook.
pub
struct
IssueHook
{
...
...
@@ -298,7 +303,7 @@ enum_serialize!(MergeRequestAction -> "merge request action",
Merge
=>
"merge"
,
);
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// Merge parameters for a merge request.
pub
struct
MergeRequestParams
{
...
...
@@ -326,7 +331,7 @@ impl MergeRequestParams {
}
}
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// Merge request information exposed in hooks.
pub
struct
MergeRequestHookAttrs
{
...
...
@@ -400,7 +405,7 @@ pub struct MergeRequestHookAttrs {
lock_version
:
Option
<
u64
>
,
}
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// A merge request hook.
pub
struct
MergeRequestHook
{
...
...
@@ -430,7 +435,7 @@ enum_serialize!(SnippetType -> "snippet type",
Personal
=>
"PersonalSnippet"
,
);
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// Snippet information exposed in hooks.
pub
struct
SnippetHookAttrs
{
...
...
@@ -448,7 +453,7 @@ pub struct SnippetHookAttrs {
pub
updated_at
:
HookDate
,
/// The name of the snippet.
pub
file_name
:
String
,
#[serde(rename
=
"type"
)]
#[serde(rename
=
"type"
)]
/// The type of the snippet.
pub
type_
:
SnippetType
,
/// The visibility of the snippet.
...
...
@@ -468,7 +473,7 @@ enum_serialize!(WikiPageAction -> "wiki page action",
Update
=>
"update"
,
);
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// Wiki information exposed in hooks.
pub
struct
WikiPageHookAttrs
{
...
...
@@ -487,7 +492,7 @@ pub struct WikiPageHookAttrs {
pub
action
:
WikiPageAction
,
}
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// Diff information exposed in hooks.
pub
struct
DiffHookAttrs
{
...
...
@@ -510,7 +515,7 @@ pub struct DiffHookAttrs {
pub
too_large
:
bool
,
}
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
// FIXME: This can apparently be a string sometimes.
// https://gitlab.com/gitlab-org/gitlab-ce/issues/21467
...
...
@@ -526,7 +531,7 @@ pub struct PositionHookAttrs {
pub
new_path
:
String
,
}
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// Note (comment) information exposed in hooks.
pub
struct
NoteHookAttrs
{
...
...
@@ -567,7 +572,7 @@ pub struct NoteHookAttrs {
/// The URL of the note.
pub
url
:
String
,
#[serde(rename
=
"type"
)]
#[serde(rename
=
"type"
)]
pub
type_
:
Option
<
String
>
,
// ???
//pub is_award: bool, // seems to have been removed?
}
...
...
@@ -600,7 +605,7 @@ impl NoteHookAttrs {
}
}
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// A note hook.
pub
struct
NoteHook
{
...
...
@@ -625,7 +630,7 @@ pub struct NoteHook {
repository
:
Value
,
}
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// Build user information exposed in hooks.
pub
struct
BuildUserHookAttrs
{
...
...
@@ -637,7 +642,7 @@ pub struct BuildUserHookAttrs {
pub
email
:
Option
<
String
>
,
}
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// Build commit information exposed in hooks.
pub
struct
BuildCommitHookAttrs
{
...
...
@@ -658,7 +663,7 @@ pub struct BuildCommitHookAttrs {
pub
finished_at
:
Option
<
HookDate
>
,
}
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// Project information exposed in build hooks.
pub
struct
BuildProjectHookAttrs
{
...
...
@@ -676,13 +681,13 @@ pub struct BuildProjectHookAttrs {
pub
visibility_level
:
u64
,
}
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// A build hook.
pub
struct
BuildHook
{
/// The event which occurred.
pub
object_kind
:
String
,
#[serde(rename
=
"ref"
)]
#[serde(rename
=
"ref"
)]
/// The name of the reference that was tested.
pub
ref_
:
String
,
pub
tag
:
String
,
...
...
@@ -711,7 +716,7 @@ pub struct BuildHook {
pub
repository
:
BuildProjectHookAttrs
,
}
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[cfg_attr(feature
=
"strict"
,
serde(deny_unknown_fields))]
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
/// A wiki page hook.
pub
struct
WikiPageHook
{
...
...
@@ -746,14 +751,18 @@ pub enum WebHook {
impl
<
'de
>
Deserialize
<
'de
>
for
WebHook
{
fn
deserialize
<
D
>
(
deserializer
:
D
)
->
Result
<
Self
,
D
::
Error
>
where
D
:
Deserializer
<
'de
>
,
where
D
:
Deserializer
<
'de
>
,
{
let
val
=
<
Value
as
Deserialize
>
::
deserialize
(
deserializer
)
?
;
let
object_kind
=
match
val
.pointer
(
"/object_kind"
)
{
Some
(
&
Value
::
String
(
ref
kind
))
=>
kind
.to_string
(),
Some
(
_
)
=>
{
return
Err
(
D
::
Error
::
invalid_type
(
Unexpected
::
Other
(
"JSON value"
),
&
"a string"
));
return
Err
(
D
::
Error
::
invalid_type
(
Unexpected
::
Other
(
"JSON value"
),
&
"a string"
,
));
},
None
=>
{
return
Err
(
D
::
Error
::
missing_field
(
"object_kind"
));
...
...
@@ -772,17 +781,18 @@ impl<'de> Deserialize<'de> for WebHook {
"build"
=>
serde_json
::
from_value
(
val
)
.map
(
WebHook
::
Build
),
_
=>
{
return
Err
(
D
::
Error
::
invalid_value
(
Unexpected
::
Other
(
"object kind"
),
&
format!
(
"unrecognized webhook object kind:
\
{}"
,
object_kind
)
.as_str
()));
return
Err
(
D
::
Error
::
invalid_value
(
Unexpected
::
Other
(
"object kind"
),
&
format!
(
"unrecognized webhook object kind: {}"
,
object_kind
)
.as_str
(),
));
},
};
hook_res
.map_err
(|
err
|
{
D
::
Error
::
invalid_value
(
Unexpected
::
Other
(
"web hook"
),
&
format!
(
"{:?}"
,
err
)
.as_str
())
D
::
Error
::
invalid_value
(
Unexpected
::
Other
(
"web hook"
),
&
format!
(
"{:?}"
,
err
)
.as_str
(),
)
})
}
}
Brad King
@brad.king
mentioned in commit
eb4fba97
·
Mar 26, 2019
mentioned in commit
eb4fba97
mentioned in commit eb4fba979eb145ca033c1ac24656409cb6a8137c
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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