Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
b442f13a
Unverified
Commit
b442f13a
authored
Jun 14, 2021
by
Gautier de Saint Martin Lacaze
Committed by
GitHub
Jun 14, 2021
Browse files
Merge pull request #719 from gitlab4j/issue-649
Fix #649 : Add missing properties to SystemHook
parents
02864229
69413145
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/SystemHooksApi.java
View file @
b442f13a
...
...
@@ -80,12 +80,32 @@ public class SystemHooksApi extends AbstractApi {
* @param token secret token to validate received payloads, optional
* @param pushEvents when true, the hook will fire on push events, optional
* @param tagPushEvents when true, the hook will fire on new tags being pushed, optional
* @param enablS
s
slVerification do SSL verification when triggering the hook, optional
* @param enabl
e
SslVerification do SSL verification when triggering the hook, optional
* @return an SystemHookEvent instance with info on the added system hook
* @throws GitLabApiException if any exception occurs
*/
public
SystemHook
addSystemHook
(
String
url
,
String
token
,
Boolean
pushEvents
,
Boolean
tagPushEvents
,
Boolean
enablSsslVerification
)
throws
GitLabApiException
{
Boolean
tagPushEvents
,
Boolean
enableSslVerification
)
throws
GitLabApiException
{
SystemHook
systemHook
=
new
SystemHook
().
withPushEvents
(
pushEvents
)
.
withTagPushEvents
(
tagPushEvents
)
.
withEnableSslVerification
(
enableSslVerification
);
return
addSystemHook
(
url
,
token
,
systemHook
);
}
/**
* Add a new system hook. This method requires admin access.
*
* <pre><code>GitLab Endpoint: POST /hooks</code></pre>
*
* @param url the hook URL, required
* @param token secret token to validate received payloads, optional
* @param systemHook the systemHook to create
* @return an SystemHookEvent instance with info on the added system hook
* @throws GitLabApiException if any exception occurs
*/
public
SystemHook
addSystemHook
(
String
url
,
String
token
,
SystemHook
systemHook
)
throws
GitLabApiException
{
if
(
url
==
null
)
{
throw
new
RuntimeException
(
"url cannot be null"
);
...
...
@@ -94,9 +114,11 @@ public class SystemHooksApi extends AbstractApi {
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"url"
,
url
,
true
)
.
withParam
(
"token"
,
token
)
.
withParam
(
"push_events"
,
pushEvents
)
.
withParam
(
"tag_push_events"
,
tagPushEvents
)
.
withParam
(
"enable_ssl_verification"
,
enablSsslVerification
);
.
withParam
(
"push_events"
,
systemHook
.
getPushEvents
())
.
withParam
(
"tag_push_events"
,
systemHook
.
getTagPushEvents
())
.
withParam
(
"merge_requests_events"
,
systemHook
.
getMergeRequestsEvents
())
.
withParam
(
"repository_update_events"
,
systemHook
.
getRepositoryUpdateEvents
())
.
withParam
(
"enable_ssl_verification"
,
systemHook
.
getEnableSslVerification
());
Response
response
=
post
(
Response
.
Status
.
CREATED
,
formData
,
"hooks"
);
return
(
response
.
readEntity
(
SystemHook
.
class
));
}
...
...
src/main/java/org/gitlab4j/api/models/SystemHook.java
View file @
b442f13a
...
...
@@ -13,6 +13,7 @@ public class SystemHook {
private
Boolean
tagPushEvents
;
private
Boolean
enableSslVerification
;
private
Boolean
repositoryUpdateEvents
;
private
Boolean
mergeRequestsEvents
;
public
Integer
getId
()
{
return
id
;
...
...
@@ -70,6 +71,14 @@ public class SystemHook {
return
repositoryUpdateEvents
;
}
public
void
setMergeRequestsEvents
(
Boolean
mergeRequestsEvents
)
{
this
.
mergeRequestsEvents
=
mergeRequestsEvents
;
}
public
Boolean
getMergeRequestsEvents
()
{
return
mergeRequestsEvents
;
}
public
SystemHook
withId
(
Integer
id
)
{
this
.
id
=
id
;
return
(
this
);
...
...
@@ -105,6 +114,11 @@ public class SystemHook {
return
(
this
);
}
public
SystemHook
withMergeRequestsEvents
(
Boolean
mergeRequestsEvents
)
{
this
.
mergeRequestsEvents
=
mergeRequestsEvents
;
return
(
this
);
}
@Override
public
String
toString
()
{
return
(
JacksonJson
.
toJsonString
(
this
));
...
...
src/test/java/org/gitlab4j/api/TestSystemHooksApi.java
View file @
b442f13a
...
...
@@ -63,13 +63,33 @@ public class TestSystemHooksApi extends AbstractIntegrationTest {
assertEquals
(
TEST_HOOK_URL
,
hook
.
getUrl
());
assertTrue
(
hook
.
getPushEvents
());
assertFalse
(
hook
.
getTagPushEvents
());
assertFalse
(
hook
.
getMergeRequestsEvents
());
assertFalse
(
hook
.
getRepositoryUpdateEvents
());
assertTrue
(
hook
.
getEnableSslVerification
());
gitLabApi
.
getSystemHooksApi
().
deleteSystemHook
(
hook
);
hook
.
withPushEvents
(
false
)
.
withTagPushEvents
(
true
)
.
withMergeRequestsEvents
(
true
)
.
withRepositoryUpdateEvents
(
true
)
.
withEnableSslVerification
(
false
);
SystemHook
updatedHook
=
gitLabApi
.
getSystemHooksApi
().
addSystemHook
(
TEST_HOOK_URL
,
TEST_SECRET_TOKEN
,
hook
);
assertNotNull
(
updatedHook
);
assertEquals
(
TEST_HOOK_URL
,
updatedHook
.
getUrl
());
assertFalse
(
hook
.
getPushEvents
());
assertTrue
(
hook
.
getTagPushEvents
());
assertTrue
(
hook
.
getMergeRequestsEvents
());
assertTrue
(
hook
.
getRepositoryUpdateEvents
());
assertFalse
(
hook
.
getEnableSslVerification
());
gitLabApi
.
getSystemHooksApi
().
deleteSystemHook
(
hook
);
}
@Test
public
void
testGe
r
SystemHooks
()
throws
GitLabApiException
{
public
void
testGe
t
SystemHooks
()
throws
GitLabApiException
{
SystemHook
hook
=
gitLabApi
.
getSystemHooksApi
().
addSystemHook
(
TEST_HOOK_URL
,
TEST_SECRET_TOKEN
,
true
,
false
,
true
);
assertNotNull
(
hook
);
...
...
@@ -77,7 +97,7 @@ public class TestSystemHooksApi extends AbstractIntegrationTest {
List
<
SystemHook
>
hooks
=
gitLabApi
.
getSystemHooksApi
().
getSystemHooks
();
assertNotNull
(
hooks
);
assertFalse
(
hooks
.
isEmpty
());
gitLabApi
.
getSystemHooksApi
().
deleteSystemHook
(
hook
);
}
}
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