Unverified Commit 224f4c5b authored by 06luki06's avatar 06luki06 Committed by GitHub
Browse files

Add the possibility of adding noteEvents with ProjectApi.addHook(..) (#1123)



---------

Co-authored-by: default avatarJeremie Bresson <jeremie.bresson@unblu.com>
parent 61e64115
...@@ -1074,7 +1074,7 @@ public class ProjectApi extends AbstractApi implements Constants { ...@@ -1074,7 +1074,7 @@ public class ProjectApi extends AbstractApi implements Constants {
* Only working with GitLab 16.9 and above. * Only working with GitLab 16.9 and above.
* *
* <pre><code>GitLab Endpoint: GET /projects/:id/avatar</code></pre> * <pre><code>GitLab Endpoint: GET /projects/:id/avatar</code></pre>
* *
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance * @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @return an InputStream to read the raw file from * @return an InputStream to read the raw file from
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
...@@ -2211,7 +2211,7 @@ public class ProjectApi extends AbstractApi implements Constants { ...@@ -2211,7 +2211,7 @@ public class ProjectApi extends AbstractApi implements Constants {
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public ProjectHook addHook(Object projectIdOrPath, String url, ProjectHook enabledHooks, public ProjectHook addHook(Object projectIdOrPath, String url, ProjectHook enabledHooks,
boolean enableSslVerification, String secretToken) throws GitLabApiException { Boolean enableSslVerification, String secretToken) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm() GitLabApiForm formData = new GitLabApiForm()
.withParam("url", url, true) .withParam("url", url, true)
...@@ -2238,6 +2238,7 @@ public class ProjectApi extends AbstractApi implements Constants { ...@@ -2238,6 +2238,7 @@ public class ProjectApi extends AbstractApi implements Constants {
/** /**
* Adds a hook to project. * Adds a hook to project.
* Convenience method for {@link #addHook(Object, String, ProjectHook, Boolean, String)}
* *
* <pre><code>GitLab Endpoint: POST /projects/:id/hooks</code></pre> * <pre><code>GitLab Endpoint: POST /projects/:id/hooks</code></pre>
* *
...@@ -2251,15 +2252,32 @@ public class ProjectApi extends AbstractApi implements Constants { ...@@ -2251,15 +2252,32 @@ public class ProjectApi extends AbstractApi implements Constants {
*/ */
public ProjectHook addHook(Object projectIdOrPath, String url, boolean doPushEvents, public ProjectHook addHook(Object projectIdOrPath, String url, boolean doPushEvents,
boolean doIssuesEvents, boolean doMergeRequestsEvents) throws GitLabApiException { boolean doIssuesEvents, boolean doMergeRequestsEvents) throws GitLabApiException {
return addHook(projectIdOrPath, url, doPushEvents, doIssuesEvents, doMergeRequestsEvents, null);
GitLabApiForm formData = new GitLabApiForm() }
.withParam("url", url)
.withParam("push_events", doPushEvents) /**
.withParam("issues_events", doIssuesEvents) * Adds a hook to project.
.withParam("merge_requests_events", doMergeRequestsEvents); * Convenience method for {@link #addHook(Object, String, ProjectHook, Boolean, String)}
*
Response response = post(Response.Status.CREATED, formData, "projects", getProjectIdOrPath(projectIdOrPath), "hooks"); * <pre><code>GitLab Endpoint: POST /projects/:id/hooks</code></pre>
return (response.readEntity(ProjectHook.class)); *
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance, required
* @param url the callback URL for the hook
* @param doPushEvents flag specifying whether to do push events
* @param doIssuesEvents flag specifying whether to do issues events
* @param doMergeRequestsEvents flag specifying whether to do merge requests events
* @param doNoteEvents flag specifying whether to do note events
* @return the added ProjectHook instance
* @throws GitLabApiException if any exception occurs
*/
public ProjectHook addHook(Object projectIdOrPath, String url, Boolean doPushEvents,
Boolean doIssuesEvents, Boolean doMergeRequestsEvents, Boolean doNoteEvents) throws GitLabApiException {
ProjectHook enabledHooks = new ProjectHook()
.withPushEvents(doPushEvents)
.withIssuesEvents(doIssuesEvents)
.withMergeRequestsEvents(doMergeRequestsEvents)
.withNoteEvents(doNoteEvents);
return addHook(projectIdOrPath, url, enabledHooks , null, null);
} }
/** /**
......
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