Skip to content
GitLab
Menu
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
04e94ae6
Commit
04e94ae6
authored
Oct 04, 2016
by
Ben Boeckel
⛰
Browse files
gitlab: expose hook addition API
Fixes #5.
parent
981262b0
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/gitlab.rs
View file @
04e94ae6
...
...
@@ -147,6 +147,33 @@ impl Gitlab {
self
._get
(
&
format!
(
"projects/{}/hooks/{}"
,
project
,
hook
))
}
fn
bool_param_value
(
value
:
bool
)
->
&
'static
str
{
if
value
{
"true"
}
else
{
"false"
}
}
fn
set_event_flags
(
request
:
&
mut
Request
,
events
:
WebhookEvents
)
{
request
.param
(
"build_events"
,
Self
::
bool_param_value
(
events
.build
()))
.param
(
"issues_events"
,
Self
::
bool_param_value
(
events
.issues
()))
.param
(
"merge_requests_events"
,
Self
::
bool_param_value
(
events
.merge_requests
()))
.param
(
"note_events"
,
Self
::
bool_param_value
(
events
.note
()))
.param
(
"pipeline_events"
,
Self
::
bool_param_value
(
events
.pipeline
()))
.param
(
"push_events"
,
Self
::
bool_param_value
(
events
.push
()))
.param
(
"wiki_page_events"
,
Self
::
bool_param_value
(
events
.wiki_page
()));
}
/// Add a project hook.
pub
fn
add_hook
(
&
self
,
project
:
ProjectId
,
url
:
&
str
,
events
:
WebhookEvents
)
->
GitlabResult
<
Hook
>
{
let
mut
req
=
try
!
(
self
._mkrequest
(
&
format!
(
"projects/{}/hooks"
,
project
)));
Self
::
set_event_flags
(
&
mut
req
,
events
);
self
._post
(
&
format!
(
"projects/{}/hooks"
,
project
))
}
/// Get the team members of a group.
pub
fn
group_members
(
&
self
,
group
:
GroupId
)
->
GitlabResult
<
Vec
<
Member
>>
{
self
._get_paged
(
&
format!
(
"groups/{}/members"
,
group
))
...
...
src/macros.rs
View file @
04e94ae6
...
...
@@ -66,3 +66,20 @@ macro_rules! enum_serialize {
}
};
}
macro_rules!
with_event
{
{
$method
:
ident
,
$name
:
ident
}
=>
{
pub
fn
$method
(
mut
self
)
->
Self
{
self
.
$name
=
true
;
self
}
};
}
macro_rules!
get_event
{
{
$name
:
ident
}
=>
{
pub
fn
$name
(
&
self
)
->
bool
{
self
.
$name
}
};
}
src/types.rs.in
View file @
04e94ae6
...
...
@@ -297,6 +297,47 @@ impl From<ProjectHook> for Hook {
}
}
#[derive(Default)]
pub struct WebhookEvents {
build: bool,
issues: bool,
merge_requests: bool,
note: bool,
pipeline: bool,
push: bool,
wiki_page: bool,
}
impl WebhookEvents {
fn new() -> Self {
WebhookEvents {
build: false,
issues: false,
merge_requests: false,
note: false,
pipeline: false,
push: false,
wiki_page: false,
}
}
with_event!{with_build, build}
with_event!{with_issues, issues}
with_event!{with_merge_requests, merge_requests}
with_event!{with_note, note}
with_event!{with_pipeline, pipeline}
with_event!{with_push, push}
with_event!{with_wiki_page, wiki_page}
get_event!{build}
get_event!{issues}
get_event!{merge_requests}
get_event!{note}
get_event!{pipeline}
get_event!{push}
get_event!{wiki_page}
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
/// Type-safe project ID.
pub struct ProjectId(u64);
...
...
Write
Preview
Supports
Markdown
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