Skip to content

Adding ExternalUncyclo Service #259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 93 additions & 37 deletions src/main/java/org/gitlab4j/api/ServicesApi.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.gitlab4j.api;

import javax.ws.rs.core.Form;
import javax.ws.rs.core.Response;

import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.services.ExternalUncycloService;
import org.gitlab4j.api.services.HipChatService;
import org.gitlab4j.api.services.JiraService;
import org.gitlab4j.api.services.SlackService;

import javax.ws.rs.core.Form;
import javax.ws.rs.core.Response;

/**
* Access for the services API. Currently only the gitlab-ci, HipChatService, Slack, and JIRA service are supported.
* See <a href="https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/services.md">GitLab documentation</a> for more info.
Expand All @@ -20,11 +21,12 @@ public ServicesApi(GitLabApi gitLabApi) {

/**
* Activates the gitlab-ci service for a project.
*
* <p>
* PUT /projects/:id/services/gitlab-ci
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param token for authentication
* @param projectCIUrl URL of the GitLab-CI project
* @param token for authentication
* @param projectCIUrl URL of the GitLab-CI project
* @throws GitLabApiException if any exception occurs
* @deprecated No longer supported
*/
Expand All @@ -37,7 +39,7 @@ public void setGitLabCI(Object projectIdOrPath, String token, String projectCIUr

/**
* Deletes the gitlab-ci service for a project.
*
* <p>
* DELETE /projects/:id/services/gitlab-ci
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
Expand All @@ -51,7 +53,7 @@ public void deleteGitLabCI(Object projectIdOrPath) throws GitLabApiException {

/**
* Get the HipChatService notification configuration for a project.
*
* <p>
* Get /projects/:id/services/hipchat
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
Expand All @@ -60,16 +62,16 @@ public void deleteGitLabCI(Object projectIdOrPath) throws GitLabApiException {
*/
public HipChatService getHipChatService(Object projectIdOrPath) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "hipchat");
return (response.readEntity(HipChatService.class));
return (response.readEntity(HipChatService.class));
}

/**
* Updates the HipChatService notification settings for a project.
*
* <p>
* PUT /projects/:id/services/hipchat
*
* <p>
* The following properties on the HipChatService instance are utilized in the update of the settings:
*
* <p>
* pushEvents (optional) - Enable notifications for push events
* issuesEvents (optional) - Enable notifications for issue events
* confidentialIssuesEvents (optional) - Enable notifications for confidential issue events
Expand All @@ -87,7 +89,7 @@ public HipChatService getHipChatService(Object projectIdOrPath) throws GitLabApi
* notifyOnlyBrokenPipelines (optional) - Send notifications for broken pipelines
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param hipChat the HipChatService instance holding the settings
* @param hipChat the HipChatService instance holding the settings
* @return a HipChatService instance holding the newly updated settings
* @throws GitLabApiException if any exception occurs
*/
Expand All @@ -114,13 +116,13 @@ public HipChatService updateHipChatService(Object projectIdOrPath, HipChatServic

/**
* Activates HipChatService notifications.
*
* <p>
* PUT /projects/:id/services/hipchat
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param token for authentication
* @param room HipChatService Room
* @param server HipChatService Server URL
* @param token for authentication
* @param room HipChatService Room
* @param server HipChatService Server URL
* @throws GitLabApiException if any exception occurs
* @deprecated replaced with {@link #updateHipChatService(Object, HipChatService) updateHipChat} method
*/
Expand All @@ -134,7 +136,7 @@ public void setHipChat(Object projectIdOrPath, String token, String room, String

/**
* Deletes the HipChatService service for a project.
*
* <p>
* DELETE /projects/:id/services/hipchat
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
Expand All @@ -147,7 +149,7 @@ public void deleteHipChat(Object projectIdOrPath) throws GitLabApiException {

/**
* Deletes the HipChatService service for a project.
*
* <p>
* DELETE /projects/:id/services/hipchat
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
Expand All @@ -160,7 +162,7 @@ public void deleteHipChatService(Object projectIdOrPath) throws GitLabApiExcepti

/**
* Get the Slack notification settings for a project.
*
* <p>
* Get /projects/:id/services/slack
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
Expand All @@ -169,16 +171,16 @@ public void deleteHipChatService(Object projectIdOrPath) throws GitLabApiExcepti
*/
public SlackService getSlackService(Object projectIdOrPath) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "slack");
return (response.readEntity(SlackService.class));
return (response.readEntity(SlackService.class));
}

/**
* Updates the Slack notification settings for a project.
*
* <p>
* PUT /projects/:id/services/slack
*
* <p>
* The following properties on the SlackService instance are utilized in the update of the settings:
*
* <p>
* webhook (required) - https://hooks.slack.com/services/...
* username (optional) - username
* defaultChannel (optional) - Default channel to use if others are not configured
Expand All @@ -203,7 +205,7 @@ public SlackService getSlackService(Object projectIdOrPath) throws GitLabApiExce
* pipelineChannel (optional) - The name of the channel to receive pipeline events notifications
* wikiPageChannel (optional) - The name of the channel to receive wiki page events notifications
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param slackNotifications the SlackService instance holding the settings
* @return a SlackService instance holding the newly updated settings
* @throws GitLabApiException if any exception occurs
Expand All @@ -212,7 +214,7 @@ public SlackService updateSlackService(Object projectIdOrPath, SlackService slac
GitLabApiForm formData = new GitLabApiForm()
.withParam("webhook", slackNotifications.getWebhook(), true)
.withParam("username", slackNotifications.getUsername())
.withParam("channel", slackNotifications.getDefaultChannel())
.withParam("channel", slackNotifications.getDefaultChannel())
.withParam("notify_only_broken_pipelines", slackNotifications.getNotifyOnlyBrokenPipelines())
.withParam("notify_only_default_branch", slackNotifications.getNotifyOnlyDefaultBranch())
.withParam("push_events", slackNotifications.getPushEvents())
Expand All @@ -239,7 +241,7 @@ public SlackService updateSlackService(Object projectIdOrPath, SlackService slac

/**
* Deletes the Slack notifications service for a project.
*
* <p>
* DELETE /projects/:id/services/slack
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
Expand All @@ -249,10 +251,10 @@ public void deleteSlackService(Object projectIdOrPath) throws GitLabApiException
Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
delete(expectedStatus, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "slack");
}

/**
* Get the JIRA service settings for a project.
*
* <p>
* Get /projects/:id/services/jira
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
Expand All @@ -261,16 +263,16 @@ public void deleteSlackService(Object projectIdOrPath) throws GitLabApiException
*/
public JiraService getJiraService(Object projectIdOrPath) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "jira");
return (response.readEntity(JiraService.class));
return (response.readEntity(JiraService.class));
}

/**
* Updates the JIRA service settings for a project.
*
* <p>
* PUT /projects/:id/services/jira
*
* <p>
* The following properties on the JiraService instance are utilized in the update of the settings:
*
* <p>
* mergeRequestsEvents (optional) - Enable notifications for merge request events
* commitEvents (optional) - Enable notifications for commit events
* url (required) - The URL to the JIRA project which is being linked to this GitLab project, e.g., https://jira.example.com.
Expand All @@ -281,7 +283,7 @@ public JiraService getJiraService(Object projectIdOrPath) throws GitLabApiExcept
* jiraIssueTransitionId (optional) - The ID of a transition that moves issues to a closed state.
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param jira the JiraService instance holding the settings
* @param jira the JiraService instance holding the settings
* @return a JiraService instance holding the newly updated settings
* @throws GitLabApiException if any exception occurs
*/
Expand All @@ -293,15 +295,18 @@ public JiraService updateJiraService(Object projectIdOrPath, JiraService jira) t
.withParam("api_url", jira.getApiUrl())
.withParam("project_key", jira.getProjectKey())
.withParam("username", jira.getUsername(), true)
.withParam("password", jira.getPassword(), true)
.withParam("password", jira.getPassword(), true)
.withParam("jira_issue_transition_id", jira.getJiraIssueTransitionId());
Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "services", "jira");
return (response.readEntity(JiraService.class));
}




/**
* Deletes the JIRA service for a project.
*
* <p>
* DELETE /projects/:id/services/jira
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
Expand All @@ -311,4 +316,55 @@ public void deleteJiraService(Object projectIdOrPath) throws GitLabApiException
Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
delete(expectedStatus, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "jira");
}


/**
* Get the JIRA service settings for a project.
* <p>
* Get /projects/:id/services/external-wiki
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @return a ExternalUncycloService instance holding the External Uncyclo service settings
* @throws GitLabApiException if any exception occurs
*/
public ExternalUncycloService getExternalUncycloService(Object projectIdOrPath) throws GitLabApiException {
Response response = this.get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "external-wiki");
return (response.readEntity(ExternalUncycloService.class));
}


/**
* Updates the ExternalUncycloService service settings for a project.
* <p>
* PUT /projects/:id/services/external-wiki
* <p>
* The following properties on the JiraService instance are utilized in the update of the settings:
* <p>
* external_wiki_url (required) - The URL to the External Uncyclo project which is being linked to this GitLab project, e.g., http://www.wikidot.com/
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param externalUncyclo the ExternalUncycloService instance holding the settings
* @return a ExternalUncycloService instance holding the newly updated settings
* @throws GitLabApiException if any exception occurs
*/
public ExternalUncycloService updateExternalUncycloService(Object projectIdOrPath, ExternalUncycloService externalUncyclo) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
.withParam("external_wiki_url", externalUncyclo.getExternalUncycloUrl());
Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "services", "external-wiki");
return (response.readEntity(ExternalUncycloService.class));
}

/**
* Deletes the ExternalUncyclo service for a project.
* <p>
* DELETE /projects/:id/services/external-wiki
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @throws GitLabApiException if any exception occurs
*/
public void deleteExternalUncycloService(Object projectIdOrPath) throws GitLabApiException {
Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
delete(expectedStatus, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "external-wiki");

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.gitlab4j.api.services;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class ExternalUncycloService extends NotificationService {

public static final String WIKIURL_KEY_PROP = "external_wiki_url";

public String getExternalUncycloUrl() {
return this.getProperty(WIKIURL_KEY_PROP);
}

public void setExternalUncycloUrl(String endpoint) {
this.setProperty(WIKIURL_KEY_PROP, endpoint);
}


public ExternalUncycloService withExternalUncycloUrl(String endpoint) {
setExternalUncycloUrl(endpoint);
return this;
}
}
33 changes: 33 additions & 0 deletions src/test/java/org/gitlab4j/api/TestServicesApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.services.ExternalUncycloService;
import org.gitlab4j.api.services.JiraService;
import org.gitlab4j.api.services.SlackService;
import org.junit.Before;
Expand Down Expand Up @@ -189,4 +190,36 @@ public void testDeleteSlackService() throws GitLabApiException {
assertNotNull(deleteSlackService);
assertFalse(deleteSlackService.getActive());
}

@Test
public void testGetExternalUncyclo() throws GitLabApiException {
ExternalUncycloService wikiService = gitLabApi.getServicesApi().getExternalUncycloService(testProject);
assertNotNull(wikiService);
}

@Test
public void testUpdateExternalUncyclo() throws GitLabApiException {
try {
ExternalUncycloService wikiService = new ExternalUncycloService()
.withExternalUncycloUrl("http://wiki.io");
ExternalUncycloService updatedExternalUncycloService = gitLabApi.getServicesApi().updateExternalUncycloService(testProject, wikiService);
assertNotNull(updatedExternalUncycloService);
} finally {
try { gitLabApi.getServicesApi().deleteExternalUncycloService(testProject); } catch (Exception ignore) {}
}
}

@Test
public void testDeleteExternalUncycloService() throws GitLabApiException {
ExternalUncycloService wikiService = new ExternalUncycloService()
.withExternalUncycloUrl("http://wiki.io");
ExternalUncycloService updatedExternalUncycloService = gitLabApi.getServicesApi().updateExternalUncycloService(testProject, wikiService);
assertNotNull(updatedExternalUncycloService);
assertTrue(updatedExternalUncycloService.getActive());

gitLabApi.getServicesApi().deleteExternalUncycloService(testProject);
ExternalUncycloService deleteExternalUncycloService = gitLabApi.getServicesApi().getExternalUncycloService(testProject);
assertNotNull(deleteExternalUncycloService);
assertFalse(deleteExternalUncycloService.getActive());
}
}