Commit f95da6d0 authored by Greg Messner's avatar Greg Messner
Browse files

Re-worked hook methods to be consistient with rest of API.

parent 2fd7ff41
...@@ -19,7 +19,7 @@ import java.util.List; ...@@ -19,7 +19,7 @@ import java.util.List;
*/ */
public class ProjectApi extends AbstractApi { public class ProjectApi extends AbstractApi {
ProjectApi(GitLabApi gitLabApi) { public ProjectApi(GitLabApi gitLabApi) {
super(gitLabApi); super(gitLabApi);
} }
...@@ -29,7 +29,7 @@ public class ProjectApi extends AbstractApi { ...@@ -29,7 +29,7 @@ public class ProjectApi extends AbstractApi {
* GET /projects * GET /projects
* *
* @return a list of projects accessible by the authenticated user * @return a list of projects accessible by the authenticated user
* @throws GitLabApiException * @throws GitLabApiException if any exception occurs
*/ */
public List<Project> getProjects() throws GitLabApiException { public List<Project> getProjects() throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects"); Response response = get(Response.Status.OK, null, "projects");
...@@ -43,7 +43,7 @@ public class ProjectApi extends AbstractApi { ...@@ -43,7 +43,7 @@ public class ProjectApi extends AbstractApi {
* GET /projects/all * GET /projects/all
* *
* @return a list of all GitLab projects * @return a list of all GitLab projects
* @throws GitLabApiException * @throws GitLabApiException if any exception occurs
*/ */
public List<Project> getAllProjects() throws GitLabApiException { public List<Project> getAllProjects() throws GitLabApiException {
Response response = get(Response.Status.OK, UriComponent.decodeQuery("per_page=9999", true), "projects", "all"); Response response = get(Response.Status.OK, UriComponent.decodeQuery("per_page=9999", true), "projects", "all");
...@@ -57,10 +57,11 @@ public class ProjectApi extends AbstractApi { ...@@ -57,10 +57,11 @@ public class ProjectApi extends AbstractApi {
* GET /projects/owned * GET /projects/owned
* *
* @return a list of projects owned by the authenticated user * @return a list of projects owned by the authenticated user
* @throws GitLabApiException * @throws GitLabApiException if any exception occurs
*/ */
public List<Project> getOwnedProjects() throws GitLabApiException { public List<Project> getOwnedProjects() throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", "owned"); Form formData = new GitLabApiForm().withParam("owned", true);
Response response = get(Response.Status.OK, formData.asMap(), "projects");
return (response.readEntity(new GenericType<List<Project>>() { return (response.readEntity(new GenericType<List<Project>>() {
})); }));
} }
...@@ -70,9 +71,9 @@ public class ProjectApi extends AbstractApi { ...@@ -70,9 +71,9 @@ public class ProjectApi extends AbstractApi {
* *
* GET /projects/:id * GET /projects/:id
* *
* @param projectId * @param projectId the ID of the project to get
* @return the specified project * @return the specified project
* @throws GitLabApiException * @throws GitLabApiException if any exception occurs
*/ */
public Project getProject(Integer projectId) throws GitLabApiException { public Project getProject(Integer projectId) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", projectId); Response response = get(Response.Status.OK, null, "projects", projectId);
...@@ -85,9 +86,9 @@ public class ProjectApi extends AbstractApi { ...@@ -85,9 +86,9 @@ public class ProjectApi extends AbstractApi {
* GET /projects/:id * GET /projects/:id
* *
* @param namespace the name of the project namespace or group * @param namespace the name of the project namespace or group
* @param project * @param project the name of the project to get
* @return the specified project * @return the specified project
* @throws GitLabApiException * @throws GitLabApiException if any exception occurs
*/ */
public Project getProject(String namespace, String project) throws GitLabApiException { public Project getProject(String namespace, String project) throws GitLabApiException {
...@@ -113,16 +114,16 @@ public class ProjectApi extends AbstractApi { ...@@ -113,16 +114,16 @@ public class ProjectApi extends AbstractApi {
/** /**
* Create a new project in the specified group. * Create a new project in the specified group.
* *
* @param groupId * @param groupId the group ID to create the project under
* @param projectName * @param projectName the name of the project top create
* @return the created project * @return the created project
* @throws GitLabApiException * @throws GitLabApiException if any exception occurs
*/ */
public Project createProject(Integer groupId, String projectName) throws GitLabApiException { public Project createProject(Integer groupId, String projectName) throws GitLabApiException {
Form formData = new Form(); GitLabApiForm formData = new GitLabApiForm()
addFormParam(formData, "namespace_id", groupId); .withParam("namespace_id", groupId)
addFormParam(formData, "name", projectName, true); .withParam("name", projectName, true);
Response response = post(Response.Status.CREATED, formData, "projects"); Response response = post(Response.Status.CREATED, formData, "projects");
return (response.readEntity(Project.class)); return (response.readEntity(Project.class));
...@@ -133,7 +134,7 @@ public class ProjectApi extends AbstractApi { ...@@ -133,7 +134,7 @@ public class ProjectApi extends AbstractApi {
* *
* @param project the Project instance with the configuration for the new project * @param project the Project instance with the configuration for the new project
* @return a Project instance with the newly created project info * @return a Project instance with the newly created project info
* @throws GitLabApiException * @throws GitLabApiException if any exception occurs
*/ */
public Project createProject(Project project) throws GitLabApiException { public Project createProject(Project project) throws GitLabApiException {
return (createProject(project, null)); return (createProject(project, null));
...@@ -154,9 +155,9 @@ public class ProjectApi extends AbstractApi { ...@@ -154,9 +155,9 @@ public class ProjectApi extends AbstractApi {
* visibilityLevel (optional) * visibilityLevel (optional)
* *
* @param project the Project instance with the configuration for the new project * @param project the Project instance with the configuration for the new project
* @param importUrl * @param importUrl the URL to import the repository from
* @return a Project instance with the newly created project info * @return a Project instance with the newly created project info
* @throws GitLabApiException * @throws GitLabApiException if any exception occurs
*/ */
public Project createProject(Project project, String importUrl) throws GitLabApiException { public Project createProject(Project project, String importUrl) throws GitLabApiException {
...@@ -169,22 +170,22 @@ public class ProjectApi extends AbstractApi { ...@@ -169,22 +170,22 @@ public class ProjectApi extends AbstractApi {
return (null); return (null);
} }
Form formData = new Form(); GitLabApiForm formData = new GitLabApiForm()
.withParam("name", name, true)
.withParam("description", project.getDescription())
.withParam("issues_enabled", project.getIssuesEnabled())
.withParam("wall_enabled", project.getWallEnabled())
.withParam("merge_requests_enabled", project.getMergeRequestsEnabled())
.withParam("wiki_enabled", project.getWikiEnabled())
.withParam("snippets_enabled", project.getSnippetsEnabled())
.withParam("public", project.getPublic())
.withParam("visibility_level", project.getVisibilityLevel())
.withParam("import_url", importUrl);
if (project.getNamespace() != null) { if (project.getNamespace() != null) {
addFormParam(formData, "namespace_id", project.getNamespace().getId()); formData.withParam("namespace_id", project.getNamespace().getId());
} }
addFormParam(formData, "name", name, true);
addFormParam(formData, "description", project.getDescription());
addFormParam(formData, "issues_enabled", project.getIssuesEnabled());
addFormParam(formData, "wall_enabled", project.getWallEnabled());
addFormParam(formData, "merge_requests_enabled", project.getMergeRequestsEnabled());
addFormParam(formData, "wiki_enabled", project.getWikiEnabled());
addFormParam(formData, "snippets_enabled", project.getSnippetsEnabled());
addFormParam(formData, "public", project.getPublic());
addFormParam(formData, "visibility_level", project.getVisibilityLevel());
addFormParam(formData, "import_url", importUrl);
Response response = post(Response.Status.CREATED, formData, "projects"); Response response = post(Response.Status.CREATED, formData, "projects");
return (response.readEntity(Project.class)); return (response.readEntity(Project.class));
} }
...@@ -200,31 +201,31 @@ public class ProjectApi extends AbstractApi { ...@@ -200,31 +201,31 @@ public class ProjectApi extends AbstractApi {
* @param mergeRequestsEnabled Whether Merge Requests should be enabled, otherwise null indicates to use GitLab default * @param mergeRequestsEnabled Whether Merge Requests should be enabled, otherwise null indicates to use GitLab default
* @param wikiEnabled Whether a Wiki should be enabled, otherwise null indicates to use GitLab default * @param wikiEnabled Whether a Wiki should be enabled, otherwise null indicates to use GitLab default
* @param snippetsEnabled Whether Snippets should be enabled, otherwise null indicates to use GitLab default * @param snippetsEnabled Whether Snippets should be enabled, otherwise null indicates to use GitLab default
* @param publik Whether the project is public or private, if true same as setting visibilityLevel = 20, otherwise null indicates to use GitLab default * @param isPublic Whether the project is public or private, if true same as setting visibilityLevel = 20, otherwise null indicates to use GitLab default
* @param visibilityLevel The visibility level of the project, otherwise null indicates to use GitLab default * @param visibilityLevel The visibility level of the project, otherwise null indicates to use GitLab default
* @param importUrl The Import URL for the project, otherwise null * @param importUrl The Import URL for the project, otherwise null
* @return the Gitlab Project * @return the GitLab Project
* @throws GitLabApiException * @throws GitLabApiException if any exception occurs
*/ */
public Project createProject(String name, Integer namespaceId, String description, Boolean issuesEnabled, Boolean wallEnabled, Boolean mergeRequestsEnabled, public Project createProject(String name, Integer namespaceId, String description, Boolean issuesEnabled, Boolean wallEnabled, Boolean mergeRequestsEnabled,
Boolean wikiEnabled, Boolean snippetsEnabled, Boolean publik, Integer visibilityLevel, String importUrl) throws GitLabApiException { Boolean wikiEnabled, Boolean snippetsEnabled, Boolean isPublic, Integer visibilityLevel, String importUrl) throws GitLabApiException {
if (name == null || name.trim().length() == 0) { if (name == null || name.trim().length() == 0) {
return (null); return (null);
} }
Form formData = new Form(); GitLabApiForm formData = new GitLabApiForm()
addFormParam(formData, "name", name, true); .withParam("name", name, true)
addFormParam(formData, "namespace_id", namespaceId); .withParam("namespace_id", namespaceId)
addFormParam(formData, "description", description); .withParam("description", description)
addFormParam(formData, "issues_enabled", issuesEnabled); .withParam("issues_enabled", issuesEnabled)
addFormParam(formData, "wall_enabled", wallEnabled); .withParam("wall_enabled", wallEnabled)
addFormParam(formData, "merge_requests_enabled", mergeRequestsEnabled); .withParam("merge_requests_enabled", mergeRequestsEnabled)
addFormParam(formData, "wiki_enabled", wikiEnabled); .withParam("wiki_enabled", wikiEnabled)
addFormParam(formData, "snippets_enabled", snippetsEnabled); .withParam("snippets_enabled", snippetsEnabled)
addFormParam(formData, "public", publik); .withParam("public", isPublic)
addFormParam(formData, "visibility_level", visibilityLevel); .withParam("visibility_level", visibilityLevel)
addFormParam(formData, "import_url", importUrl); .withParam("import_url", importUrl);
Response response = post(Response.Status.CREATED, formData, "projects"); Response response = post(Response.Status.CREATED, formData, "projects");
return (response.readEntity(Project.class)); return (response.readEntity(Project.class));
...@@ -235,8 +236,8 @@ public class ProjectApi extends AbstractApi { ...@@ -235,8 +236,8 @@ public class ProjectApi extends AbstractApi {
* *
* DELETE /projects/:id * DELETE /projects/:id
* *
* @param projectId * @param projectId the project ID to remove
* @throws GitLabApiException * @throws GitLabApiException if any exception occurs
*/ */
public void deleteProject(Integer projectId) throws GitLabApiException { public void deleteProject(Integer projectId) throws GitLabApiException {
...@@ -252,8 +253,8 @@ public class ProjectApi extends AbstractApi { ...@@ -252,8 +253,8 @@ public class ProjectApi extends AbstractApi {
* *
* DELETE /projects/:id * DELETE /projects/:id
* *
* @param project * @param project the Project instance to remove
* @throws GitLabApiException * @throws GitLabApiException if any exception occurs
*/ */
public void deleteProject(Project project) throws GitLabApiException { public void deleteProject(Project project) throws GitLabApiException {
deleteProject(project.getId()); deleteProject(project.getId());
...@@ -264,9 +265,9 @@ public class ProjectApi extends AbstractApi { ...@@ -264,9 +265,9 @@ public class ProjectApi extends AbstractApi {
* *
* GET /projects/:id/members * GET /projects/:id/members
* *
* @param projectId * @param projectId the project ID to get team members for
* @return the members belonging to the specified project * @return the members belonging to the specified project
* @throws GitLabApiException * @throws GitLabApiException if any exception occurs
*/ */
public List<Member> getMembers(Integer projectId) throws GitLabApiException { public List<Member> getMembers(Integer projectId) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", projectId, "members"); Response response = get(Response.Status.OK, null, "projects", projectId, "members");
...@@ -279,10 +280,10 @@ public class ProjectApi extends AbstractApi { ...@@ -279,10 +280,10 @@ public class ProjectApi extends AbstractApi {
* *
* GET /projects/:id/members/:user_id * GET /projects/:id/members/:user_id
* *
* @param projectId * @param projectId the project ID to get team member for
* @param userId * @param userId the user ID of the member
* @return the member specified by the project ID/user ID pair * @return the member specified by the project ID/user ID pair
* @throws GitLabApiException * @throws GitLabApiException if any exception occurs
*/ */
public Member getMember(Integer projectId, Integer userId) throws GitLabApiException { public Member getMember(Integer projectId, Integer userId) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", projectId, "members", userId); Response response = get(Response.Status.OK, null, "projects", projectId, "members", userId);
...@@ -296,17 +297,17 @@ public class ProjectApi extends AbstractApi { ...@@ -296,17 +297,17 @@ public class ProjectApi extends AbstractApi {
* *
* POST /projects/:id/members * POST /projects/:id/members
* *
* @param projectId * @param projectId the project ID to add the team member to
* @param userId * @param userId the user ID of the member to add
* @param accessLevel * @param accessLevel
* @return the added member * @return the added member
* @throws GitLabApiException * @throws GitLabApiException if any exception occurs
*/ */
public Member addMember(Integer projectId, Integer userId, Integer accessLevel) throws GitLabApiException { public Member addMember(Integer projectId, Integer userId, Integer accessLevel) throws GitLabApiException {
Form formData = new Form(); GitLabApiForm formData = new GitLabApiForm()
formData.param("user_id", userId.toString()); .withParam("user_id", userId, true)
formData.param("access_level", accessLevel.toString()); .withParam("access_level", accessLevel, true);
Response response = post(Response.Status.CREATED, formData, "projects", projectId, "members"); Response response = post(Response.Status.CREATED, formData, "projects", projectId, "members");
return (response.readEntity(Member.class)); return (response.readEntity(Member.class));
} }
...@@ -316,9 +317,9 @@ public class ProjectApi extends AbstractApi { ...@@ -316,9 +317,9 @@ public class ProjectApi extends AbstractApi {
* *
* DELETE /projects/:id/members/:user_id * DELETE /projects/:id/members/:user_id
* *
* @param projectId * @param projectId the project ID to remove the team member from
* @param userId * @param userId the user ID of the member to remove
* @throws GitLabApiException * @throws GitLabApiException if any exception occurs
*/ */
public void removeMember(Integer projectId, Integer userId) throws GitLabApiException { public void removeMember(Integer projectId, Integer userId) throws GitLabApiException {
delete(Response.Status.OK, null, "projects", projectId, "members", userId); delete(Response.Status.OK, null, "projects", projectId, "members", userId);
...@@ -329,9 +330,9 @@ public class ProjectApi extends AbstractApi { ...@@ -329,9 +330,9 @@ public class ProjectApi extends AbstractApi {
* *
* GET /projects/:id/events * GET /projects/:id/events
* *
* @param projectId * @param projectId the project ID to get events for
* @return the project events for the specified project * @return the project events for the specified project
* @throws GitLabApiException * @throws GitLabApiException if any exception occurs
*/ */
public List<Event> getProjectEvents(Integer projectId) throws GitLabApiException { public List<Event> getProjectEvents(Integer projectId) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", projectId, "events"); Response response = get(Response.Status.OK, null, "projects", projectId, "events");
...@@ -344,9 +345,9 @@ public class ProjectApi extends AbstractApi { ...@@ -344,9 +345,9 @@ public class ProjectApi extends AbstractApi {
* *
* GET /projects/:id/hooks * GET /projects/:id/hooks
* *
* @param projectId * @param projectId the project ID to get project hooks for
* @return a list of project hooks for the specified project * @return a list of project hooks for the specified project
* @throws GitLabApiException * @throws GitLabApiException if any exception occurs
*/ */
public List<ProjectHook> getHooks(Integer projectId) throws GitLabApiException { public List<ProjectHook> getHooks(Integer projectId) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", projectId, "hooks"); Response response = get(Response.Status.OK, null, "projects", projectId, "hooks");
...@@ -359,28 +360,120 @@ public class ProjectApi extends AbstractApi { ...@@ -359,28 +360,120 @@ public class ProjectApi extends AbstractApi {
* *
* GET /projects/:id/hooks/:hook_id * GET /projects/:id/hooks/:hook_id
* *
* @param projectId * @param projectId the project ID to get the hook for
* @param hookId * @param hookId the ID of the hook to get
* @return the project hook for the specified project ID/hook ID pair * @return the project hook for the specified project ID/hook ID pair
* @throws GitLabApiException * @throws GitLabApiException if any exception occurs
*/ */
public ProjectHook getHook(Integer projectId, Integer hookId) throws GitLabApiException { public ProjectHook getHook(Integer projectId, Integer hookId) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", projectId, "hooks", hookId); Response response = get(Response.Status.OK, null, "projects", projectId, "hooks", hookId);
return (response.readEntity(ProjectHook.class)); return (response.readEntity(ProjectHook.class));
} }
/**
* Adds a hook to project.
*
* POST /projects/:id/hooks
*
* @param projectName the name of the project
* @param url the callback URL for the hook
* @param enabledHooks a ProjectHook instance specifying which hooks to enable
* @param enableSslVerification enable SSL verification
* @param secretToken the secret token to pass back to the hook
* @return the added ProjectHook instance
* @throws GitLabApiException if any exception occurs
*/
public ProjectHook addHook(String projectName, String url, ProjectHook enabledHooks, boolean enableSslVerification, String secretToken) throws GitLabApiException {
if (projectName == null) {
return (null);
}
GitLabApiForm formData = new GitLabApiForm()
.withParam("url", url, true)
.withParam("push_events", enabledHooks.getPushEvents(), false)
.withParam("issues_events", enabledHooks.getIssuesEvents(), false)
.withParam("merge_requests_events", enabledHooks.getMergeRequestsEvents(), false)
.withParam("tag_push_events", enabledHooks.getTagPushEvents(), false)
.withParam("note_events", enabledHooks.getNoteEvents(), false)
.withParam("job_events", enabledHooks.getJobEvents(), false)
.withParam("pipeline_events", enabledHooks.getPipelineEvents(), false)
.withParam("wiki_events", enabledHooks.getWikiPageEvents(), false)
.withParam("enable_ssl_verification", enabledHooks.getEnableSslVerification())
.withParam("token", secretToken, false);
Response response = post(Response.Status.CREATED, formData, "projects", projectName, "hooks");
return (response.readEntity(ProjectHook.class));
}
/**
* Adds a hook to project.
*
* POST /projects/:id/hooks
*
* @param projectId the project ID to add the project hook to
* @param url the callback URL for the hook
* @param enabledHooks a ProjectHook instance specifying which hooks to enable
* @param enableSslVerification enable SSL verification
* @param secretToken the secret token to pass back to the hook
* @return the added ProjectHook instance
* @throws GitLabApiException if any exception occurs
*/
public ProjectHook addHook(Integer projectId, String url, ProjectHook enabledHooks, boolean enableSslVerification, String secretToken) throws GitLabApiException {
if (projectId == null) {
return (null);
}
GitLabApiForm formData = new GitLabApiForm()
.withParam("url", url, true)
.withParam("push_events", enabledHooks.getPushEvents(), false)
.withParam("issues_events", enabledHooks.getIssuesEvents(), false)
.withParam("merge_requests_events", enabledHooks.getMergeRequestsEvents(), false)
.withParam("tag_push_events", enabledHooks.getTagPushEvents(), false)
.withParam("note_events", enabledHooks.getNoteEvents(), false)
.withParam("job_events", enabledHooks.getJobEvents(), false)
.withParam("pipeline_events", enabledHooks.getPipelineEvents(), false)
.withParam("wiki_events", enabledHooks.getWikiPageEvents(), false)
.withParam("enable_ssl_verification", enabledHooks.getEnableSslVerification())
.withParam("token", secretToken, false);
Response response = post(Response.Status.CREATED, formData, "projects", projectId, "hooks");
return (response.readEntity(ProjectHook.class));
}
/**
* Adds a hook to project.
*
* POST /projects/:id/hooks
*
* @param project the Project instance to add the project hook to
* @param url the callback URL for the hook
* @param enabledHooks a ProjectHook instance specifying which hooks to enable
* @param enableSslVerification enable SSL verification
* @param secretToken the secret token to pass back to the hook
* @return the added ProjectHook instance
* @throws GitLabApiException if any exception occurs
*/
public ProjectHook addHook(Project project, String url, ProjectHook enabledHooks, boolean enableSslVerification, String secretToken) throws GitLabApiException {
if (project == null) {
return (null);
}
return (addHook(project.getId(), url, enabledHooks, enableSslVerification, secretToken));
}
/** /**
* Adds a hook to project. * Adds a hook to project.
* *
* POST /projects/:id/hooks * POST /projects/:id/hooks
* *
* @param project * @param project the Project instance to add the project hook to
* @param url * @param url the callback URL for the hook
* @param doPushEvents * @param doPushEvents flag specifying whether to do push events
* @param doIssuesEvents * @param doIssuesEvents flag specifying whether to do issues events
* @param doMergeRequestsEvents * @param doMergeRequestsEvents flag specifying whether to do merge requests events
* @return the added project hook * @return the added ProjectHook instance
* @throws GitLabApiException * @throws GitLabApiException if any exception occurs
*/ */
public ProjectHook addHook(Project project, String url, boolean doPushEvents, boolean doIssuesEvents, boolean doMergeRequestsEvents) throws GitLabApiException { public ProjectHook addHook(Project project, String url, boolean doPushEvents, boolean doIssuesEvents, boolean doMergeRequestsEvents) throws GitLabApiException {
...@@ -396,21 +489,21 @@ public class ProjectApi extends AbstractApi { ...@@ -396,21 +489,21 @@ public class ProjectApi extends AbstractApi {
* *
* POST /projects/:id/hooks * POST /projects/:id/hooks
* *
* @param projectId * @param projectId the project ID to add the project hook to
* @param url * @param url the callback URL for the hook
* @param doPushEvents * @param doPushEvents flag specifying whether to do push events
* @param doIssuesEvents * @param doIssuesEvents flag specifying whether to do issues events
* @param doMergeRequestsEvents * @param doMergeRequestsEvents flag specifying whether to do merge requests events
* @return the added project hook * @return the added ProjectHook instance
* @throws GitLabApiException * @throws GitLabApiException if any exception occurs
*/ */
public ProjectHook addHook(Integer projectId, String url, boolean doPushEvents, boolean doIssuesEvents, boolean doMergeRequestsEvents) throws GitLabApiException { public ProjectHook addHook(Integer projectId, String url, boolean doPushEvents, boolean doIssuesEvents, boolean doMergeRequestsEvents) throws GitLabApiException {
Form formData = new Form(); GitLabApiForm formData = new GitLabApiForm()
formData.param("url", url); .withParam("url", url)
formData.param("push_events", Boolean.toString(doPushEvents)); .withParam("push_events", doPushEvents)
formData.param("issues_enabled", Boolean.toString(doIssuesEvents)); .withParam("issues_enabled", doIssuesEvents)
formData.param("merge_requests_events", Boolean.toString(doMergeRequestsEvents)); .withParam("merge_requests_events", doMergeRequestsEvents);
Response response = post(Response.Status.CREATED, formData, "projects", projectId, "hooks"); Response response = post(Response.Status.CREATED, formData, "projects", projectId, "hooks");
return (response.readEntity(ProjectHook.class)); return (response.readEntity(ProjectHook.class));
...@@ -421,9 +514,9 @@ public class ProjectApi extends AbstractApi { ...@@ -421,9 +514,9 @@ public class ProjectApi extends AbstractApi {
* *
* DELETE /projects/:id/hooks/:hook_id * DELETE /projects/:id/hooks/:hook_id
* *
* @param projectId * @param projectId the project ID to delete the project hook from
* @param hookId * @param hookId the project hook ID to delete
* @throws GitLabApiException * @throws GitLabApiException if any exception occurs
*/ */
public void deleteHook(Integer projectId, Integer hookId) throws GitLabApiException { public void deleteHook(Integer projectId, Integer hookId) throws GitLabApiException {
delete(Response.Status.OK, null, "projects", projectId, "hooks", hookId); delete(Response.Status.OK, null, "projects", projectId, "hooks", hookId);
...@@ -434,8 +527,8 @@ public class ProjectApi extends AbstractApi { ...@@ -434,8 +527,8 @@ public class ProjectApi extends AbstractApi {
* *
* DELETE /projects/:id/hooks/:hook_id * DELETE /projects/:id/hooks/:hook_id
* *
* @param hook * @param hook the ProjectHook instance to remove
* @throws GitLabApiException * @throws GitLabApiException if any exception occurs
*/ */
public void deleteHook(ProjectHook hook) throws GitLabApiException { public void deleteHook(ProjectHook hook) throws GitLabApiException {
deleteHook(hook.getProjectId(), hook.getId()); deleteHook(hook.getProjectId(), hook.getId());
...@@ -446,17 +539,24 @@ public class ProjectApi extends AbstractApi { ...@@ -446,17 +539,24 @@ public class ProjectApi extends AbstractApi {
* *
* PUT /projects/:id/hooks/:hook_id * PUT /projects/:id/hooks/:hook_id
* *
* @param hook * @param hook the ProjectHook instance that contains the project hook info to modify
* @return the modified project hook * @return the modified project hook
* @throws GitLabApiException * @throws GitLabApiException if any exception occurs
*/ */
public ProjectHook modifyHook(ProjectHook hook) throws GitLabApiException { public ProjectHook modifyHook(ProjectHook hook) throws GitLabApiException {
Form formData = new Form(); GitLabApiForm formData = new GitLabApiForm()
formData.param("url", hook.getUrl()); .withParam("url", hook.getUrl(), true)
formData.param("push_events", hook.getPushEvents().toString()); .withParam("push_events", hook.getPushEvents(), false)
formData.param("issues_enabled", hook.getIssuesEvents().toString()); .withParam("issues_events", hook.getIssuesEvents(), false)
formData.param("merge_requests_events", hook.getMergeRequestsEvents().toString()); .withParam("merge_requests_events", hook.getMergeRequestsEvents(), false)
.withParam("tag_push_events", hook.getTagPushEvents(), false)
.withParam("note_events", hook.getNoteEvents(), false)
.withParam("job_events", hook.getJobEvents(), false)
.withParam("pipeline_events", hook.getPipelineEvents(), false)
.withParam("wiki_events", hook.getWikiPageEvents(), false)
.withParam("enable_ssl_verification", hook.getEnableSslVerification(), false)
.withParam("token", hook.getToken(), false);
Response response = put(Response.Status.OK, formData.asMap(), "projects", hook.getProjectId(), "hooks", hook.getId()); Response response = put(Response.Status.OK, formData.asMap(), "projects", hook.getProjectId(), "hooks", hook.getId());
return (response.readEntity(ProjectHook.class)); return (response.readEntity(ProjectHook.class));
...@@ -467,9 +567,9 @@ public class ProjectApi extends AbstractApi { ...@@ -467,9 +567,9 @@ public class ProjectApi extends AbstractApi {
* *
* GET /projects/:id/issues * GET /projects/:id/issues
* *
* @param projectId * @param projectId the project ID to get the issues for
* @return a list of project's issues * @return a list of project's issues
* @throws GitLabApiException * @throws GitLabApiException if any exception occurs
*/ */
public List<Issue> getIssues(Integer projectId) throws GitLabApiException { public List<Issue> getIssues(Integer projectId) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", projectId, "issues"); Response response = get(Response.Status.OK, null, "projects", projectId, "issues");
......
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