Commit 28be1a72 authored by Greg Messner's avatar Greg Messner
Browse files

Mods to support new services (#175, #176).

parent d4abafc3
...@@ -47,7 +47,7 @@ public abstract class AbstractApi implements Constants { ...@@ -47,7 +47,7 @@ public abstract class AbstractApi implements Constants {
return (id); return (id);
} }
String path = ((Project) obj).getPath(); String path = ((Project) obj).getPathWithNamespace();
if (path != null && path.trim().length() > 0) { if (path != null && path.trim().length() > 0) {
return (urlEncode(path.trim())); return (urlEncode(path.trim()));
} }
......
...@@ -26,6 +26,7 @@ public class ServicesApi extends AbstractApi { ...@@ -26,6 +26,7 @@ public class ServicesApi extends AbstractApi {
* @param token for authentication * @param token for authentication
* @param projectCIUrl URL of the GitLab-CI project * @param projectCIUrl URL of the GitLab-CI project
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
* @deprecated No longer supported
*/ */
public void setGitLabCI(Object projectIdOrPath, String token, String projectCIUrl) throws GitLabApiException { public void setGitLabCI(Object projectIdOrPath, String token, String projectCIUrl) throws GitLabApiException {
final Form formData = new Form(); final Form formData = new Form();
...@@ -41,6 +42,7 @@ public class ServicesApi extends AbstractApi { ...@@ -41,6 +42,7 @@ public class ServicesApi extends AbstractApi {
* *
* @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
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
* @deprecated No longer supported
*/ */
public void deleteGitLabCI(Object projectIdOrPath) throws GitLabApiException { public void deleteGitLabCI(Object projectIdOrPath) throws GitLabApiException {
Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT); Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
...@@ -56,7 +58,7 @@ public class ServicesApi extends AbstractApi { ...@@ -56,7 +58,7 @@ public class ServicesApi extends AbstractApi {
* @return a HipChatService instance holding the HipChatService notification settings * @return a HipChatService instance holding the HipChatService notification settings
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public HipChatService getHipChat(Object projectIdOrPath) throws GitLabApiException { public HipChatService getHipChatService(Object projectIdOrPath) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "hipchat"); Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "hipchat");
return (response.readEntity(HipChatService.class)); return (response.readEntity(HipChatService.class));
} }
...@@ -89,7 +91,7 @@ public class ServicesApi extends AbstractApi { ...@@ -89,7 +91,7 @@ public class ServicesApi extends AbstractApi {
* @return a HipChatService instance holding the newly updated settings * @return a HipChatService instance holding the newly updated settings
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public HipChatService updateHipChat(Object projectIdOrPath, HipChatService hipChat) throws GitLabApiException { public HipChatService updateHipChatService(Object projectIdOrPath, HipChatService hipChat) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm() GitLabApiForm formData = new GitLabApiForm()
.withParam("push_events", hipChat.getPushEvents()) .withParam("push_events", hipChat.getPushEvents())
.withParam("issues_events", hipChat.getIssuesEvents()) .withParam("issues_events", hipChat.getIssuesEvents())
...@@ -137,12 +139,25 @@ public class ServicesApi extends AbstractApi { ...@@ -137,12 +139,25 @@ public class ServicesApi extends AbstractApi {
* *
* @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
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
* @deprecated replaced with {@link #deleteHipChatService(Object) updateHipChat} method
*/ */
public void deleteHipChat(Object projectIdOrPath) throws GitLabApiException { public void deleteHipChat(Object projectIdOrPath) throws GitLabApiException {
deleteHipChatService(projectIdOrPath);
}
/**
* Deletes the HipChatService service for a project.
*
* DELETE /projects/:id/services/hipchat
*
* @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 deleteHipChatService(Object projectIdOrPath) throws GitLabApiException {
Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT); Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
delete(expectedStatus, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "hipchat"); delete(expectedStatus, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "hipchat");
} }
/** /**
* Get the Slack notification settings for a project. * Get the Slack notification settings for a project.
* *
...@@ -152,7 +167,7 @@ public class ServicesApi extends AbstractApi { ...@@ -152,7 +167,7 @@ public class ServicesApi extends AbstractApi {
* @return a SlackService instance holding the Slack notification settings * @return a SlackService instance holding the Slack notification settings
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public SlackService getSlackNotifications(Object projectIdOrPath) throws GitLabApiException { public SlackService getSlackService(Object projectIdOrPath) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "slack"); Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "slack");
return (response.readEntity(SlackService.class)); return (response.readEntity(SlackService.class));
} }
...@@ -193,7 +208,7 @@ public class ServicesApi extends AbstractApi { ...@@ -193,7 +208,7 @@ public class ServicesApi extends AbstractApi {
* @return a SlackService instance holding the newly updated settings * @return a SlackService instance holding the newly updated settings
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public SlackService updateSlackNotifications(Object projectIdOrPath, SlackService slackNotifications) throws GitLabApiException { public SlackService updateSlackService(Object projectIdOrPath, SlackService slackNotifications) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm() GitLabApiForm formData = new GitLabApiForm()
.withParam("webhook", slackNotifications.getWebhook(), true) .withParam("webhook", slackNotifications.getWebhook(), true)
.withParam("username", slackNotifications.getUsername()) .withParam("username", slackNotifications.getUsername())
...@@ -230,7 +245,7 @@ public class ServicesApi extends AbstractApi { ...@@ -230,7 +245,7 @@ public class ServicesApi extends AbstractApi {
* @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
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public void deleteSlackNotifications(Object projectIdOrPath) throws GitLabApiException { public void deleteSlackService(Object projectIdOrPath) throws GitLabApiException {
Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT); Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
delete(expectedStatus, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "slack"); delete(expectedStatus, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "slack");
} }
...@@ -244,7 +259,7 @@ public class ServicesApi extends AbstractApi { ...@@ -244,7 +259,7 @@ public class ServicesApi extends AbstractApi {
* @return a JiraService instance holding the JIRA service settings * @return a JiraService instance holding the JIRA service settings
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public JiraService getJira(Object projectIdOrPath) throws GitLabApiException { public JiraService getJiraService(Object projectIdOrPath) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "jira"); Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "jira");
return (response.readEntity(JiraService.class)); return (response.readEntity(JiraService.class));
} }
...@@ -270,7 +285,7 @@ public class ServicesApi extends AbstractApi { ...@@ -270,7 +285,7 @@ public class ServicesApi extends AbstractApi {
* @return a JiraService instance holding the newly updated settings * @return a JiraService instance holding the newly updated settings
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public JiraService updateJira(Object projectIdOrPath, JiraService jira) throws GitLabApiException { public JiraService updateJiraService(Object projectIdOrPath, JiraService jira) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm() GitLabApiForm formData = new GitLabApiForm()
.withParam("merge_requests_events", jira.getMergeRequestsEvents()) .withParam("merge_requests_events", jira.getMergeRequestsEvents())
.withParam("commit_events", jira.getCommitEvents()) .withParam("commit_events", jira.getCommitEvents())
...@@ -292,7 +307,7 @@ public class ServicesApi extends AbstractApi { ...@@ -292,7 +307,7 @@ public class ServicesApi extends AbstractApi {
* @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
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public void deleteJira(Object projectIdOrPath) throws GitLabApiException { public void deleteJiraService(Object projectIdOrPath) throws GitLabApiException {
Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT); Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
delete(expectedStatus, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "jira"); delete(expectedStatus, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "jira");
} }
......
...@@ -4,8 +4,6 @@ import javax.xml.bind.annotation.XmlAccessType; ...@@ -4,8 +4,6 @@ import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import org.gitlab4j.api.utils.SecretString;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
@XmlRootElement @XmlRootElement
...@@ -18,7 +16,7 @@ public class JiraService extends NotificationService { ...@@ -18,7 +16,7 @@ public class JiraService extends NotificationService {
public static final String USERNAME_PROP = "username"; public static final String USERNAME_PROP = "username";
public static final String JIRA_ISSUE_TRANSITION_ID_PROP = "jira_issue_transition_id"; public static final String JIRA_ISSUE_TRANSITION_ID_PROP = "jira_issue_transition_id";
private SecretString password; private CharSequence password;
public JiraService withCommitEvents(Boolean commitEvents) { public JiraService withCommitEvents(Boolean commitEvents) {
return withCommitEvents(commitEvents, this); return withCommitEvents(commitEvents, this);
...@@ -29,15 +27,15 @@ public class JiraService extends NotificationService { ...@@ -29,15 +27,15 @@ public class JiraService extends NotificationService {
} }
@JsonIgnore @JsonIgnore
public SecretString getPassword() { public CharSequence getPassword() {
return password; return password;
} }
public void setPassword(SecretString password) { public void setPassword(CharSequence password) {
this.password = password; this.password = password;
} }
public JiraService withUrl(SecretString password) { public JiraService withPassword(CharSequence password) {
setPassword(password); setPassword(password);
return (this); return (this);
} }
......
...@@ -84,7 +84,7 @@ public abstract class NotificationService { ...@@ -84,7 +84,7 @@ public abstract class NotificationService {
this.pushEvents = pushEvents; this.pushEvents = pushEvents;
} }
public <T> T withPushEvents(Boolean pushEvents, T derivedInstance) { protected <T> T withPushEvents(Boolean pushEvents, T derivedInstance) {
this.pushEvents = pushEvents; this.pushEvents = pushEvents;
return (derivedInstance); return (derivedInstance);
} }
...@@ -97,7 +97,7 @@ public abstract class NotificationService { ...@@ -97,7 +97,7 @@ public abstract class NotificationService {
this.issuesEvents = issuesEvents; this.issuesEvents = issuesEvents;
} }
public <T> T withIssuesEvents(Boolean issuesEvents, T derivedInstance) { protected <T> T withIssuesEvents(Boolean issuesEvents, T derivedInstance) {
this.issuesEvents = issuesEvents; this.issuesEvents = issuesEvents;
return (derivedInstance); return (derivedInstance);
} }
...@@ -110,7 +110,7 @@ public abstract class NotificationService { ...@@ -110,7 +110,7 @@ public abstract class NotificationService {
this.confidentialIssuesEvents = confidentialIssuesEvents; this.confidentialIssuesEvents = confidentialIssuesEvents;
} }
public <T> T withConfidentialIssuesEvents(Boolean confidentialIssuesEvents, T derivedInstance) { protected <T> T withConfidentialIssuesEvents(Boolean confidentialIssuesEvents, T derivedInstance) {
this.confidentialIssuesEvents = confidentialIssuesEvents; this.confidentialIssuesEvents = confidentialIssuesEvents;
return (derivedInstance); return (derivedInstance);
} }
...@@ -124,7 +124,7 @@ public abstract class NotificationService { ...@@ -124,7 +124,7 @@ public abstract class NotificationService {
this.commitEvents = commitEvents; this.commitEvents = commitEvents;
} }
public <T> T withCommitEvents(Boolean commitEvents, T derivedInstance) { protected <T> T withCommitEvents(Boolean commitEvents, T derivedInstance) {
setCommitEvents(commitEvents); setCommitEvents(commitEvents);
return (derivedInstance); return (derivedInstance);
} }
...@@ -137,7 +137,7 @@ public abstract class NotificationService { ...@@ -137,7 +137,7 @@ public abstract class NotificationService {
this.mergeRequestsEvents = mergeRequestsEvents; this.mergeRequestsEvents = mergeRequestsEvents;
} }
public <T> T withMergeRequestsEvents(Boolean mergeRequestsEvents, T derivedInstance) { protected <T> T withMergeRequestsEvents(Boolean mergeRequestsEvents, T derivedInstance) {
this.mergeRequestsEvents = mergeRequestsEvents; this.mergeRequestsEvents = mergeRequestsEvents;
return (derivedInstance); return (derivedInstance);
} }
...@@ -150,7 +150,7 @@ public abstract class NotificationService { ...@@ -150,7 +150,7 @@ public abstract class NotificationService {
this.tagPushEvents = tagPushEvents; this.tagPushEvents = tagPushEvents;
} }
public <T> T withTagPushEvents(Boolean tagPushEvents, T derivedInstance) { protected <T> T withTagPushEvents(Boolean tagPushEvents, T derivedInstance) {
this.tagPushEvents = tagPushEvents; this.tagPushEvents = tagPushEvents;
return (derivedInstance); return (derivedInstance);
} }
...@@ -163,7 +163,7 @@ public abstract class NotificationService { ...@@ -163,7 +163,7 @@ public abstract class NotificationService {
this.noteEvents = noteEvents; this.noteEvents = noteEvents;
} }
public <T> T withNoteEvents(Boolean noteEvents, T derivedInstance) { protected <T> T withNoteEvents(Boolean noteEvents, T derivedInstance) {
this.noteEvents = noteEvents; this.noteEvents = noteEvents;
return (derivedInstance); return (derivedInstance);
} }
...@@ -176,7 +176,7 @@ public abstract class NotificationService { ...@@ -176,7 +176,7 @@ public abstract class NotificationService {
this.confidentialNoteEvents = confidentialNoteEvents; this.confidentialNoteEvents = confidentialNoteEvents;
} }
public <T> T withConfidentialNoteEvents(Boolean confidentialNoteEvents, T derivedInstance) { protected <T> T withConfidentialNoteEvents(Boolean confidentialNoteEvents, T derivedInstance) {
this.confidentialNoteEvents = confidentialNoteEvents; this.confidentialNoteEvents = confidentialNoteEvents;
return (derivedInstance); return (derivedInstance);
} }
...@@ -189,7 +189,7 @@ public abstract class NotificationService { ...@@ -189,7 +189,7 @@ public abstract class NotificationService {
this.pipelineEvents = pipelineEvents; this.pipelineEvents = pipelineEvents;
} }
public <T> T withPipelineEvents(Boolean pipelineEvents, T derivedInstance) { protected <T> T withPipelineEvents(Boolean pipelineEvents, T derivedInstance) {
this.pipelineEvents = pipelineEvents; this.pipelineEvents = pipelineEvents;
return (derivedInstance); return (derivedInstance);
} }
...@@ -202,7 +202,7 @@ public abstract class NotificationService { ...@@ -202,7 +202,7 @@ public abstract class NotificationService {
this.wikiPageEvents = wikiPageEvents; this.wikiPageEvents = wikiPageEvents;
} }
public <T> T withWikiPageEvents(Boolean wikiPageEvents, T derivedInstance) { protected <T> T withWikiPageEvents(Boolean wikiPageEvents, T derivedInstance) {
this.wikiPageEvents = wikiPageEvents; this.wikiPageEvents = wikiPageEvents;
return (derivedInstance); return (derivedInstance);
} }
...@@ -215,7 +215,7 @@ public abstract class NotificationService { ...@@ -215,7 +215,7 @@ public abstract class NotificationService {
this.jobEvents = jobEvents; this.jobEvents = jobEvents;
} }
public <T> T withJobEvents(Boolean jobEvents, T derivedInstance) { protected <T> T withJobEvents(Boolean jobEvents, T derivedInstance) {
this.jobEvents = jobEvents; this.jobEvents = jobEvents;
return (derivedInstance); return (derivedInstance);
} }
......
...@@ -57,7 +57,7 @@ import org.gitlab4j.api.models.Project; ...@@ -57,7 +57,7 @@ import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.ProjectHook; import org.gitlab4j.api.models.ProjectHook;
import org.gitlab4j.api.models.ProjectUser; import org.gitlab4j.api.models.ProjectUser;
import org.gitlab4j.api.models.ProtectedBranch; import org.gitlab4j.api.models.ProtectedBranch;
import org.gitlab4j.api.models.PushRule; import org.gitlab4j.api.models.PushRules;
import org.gitlab4j.api.models.Runner; import org.gitlab4j.api.models.Runner;
import org.gitlab4j.api.models.RunnerDetail; import org.gitlab4j.api.models.RunnerDetail;
import org.gitlab4j.api.models.Session; import org.gitlab4j.api.models.Session;
...@@ -67,6 +67,7 @@ import org.gitlab4j.api.models.SystemHook; ...@@ -67,6 +67,7 @@ import org.gitlab4j.api.models.SystemHook;
import org.gitlab4j.api.models.Tag; import org.gitlab4j.api.models.Tag;
import org.gitlab4j.api.models.TreeItem; import org.gitlab4j.api.models.TreeItem;
import org.gitlab4j.api.models.User; import org.gitlab4j.api.models.User;
import org.gitlab4j.api.services.JiraService;
import org.gitlab4j.api.services.SlackService; import org.gitlab4j.api.services.SlackService;
import org.gitlab4j.api.systemhooks.ProjectSystemHookEvent; import org.gitlab4j.api.systemhooks.ProjectSystemHookEvent;
import org.gitlab4j.api.systemhooks.PushSystemHookEvent; import org.gitlab4j.api.systemhooks.PushSystemHookEvent;
...@@ -310,7 +311,7 @@ public class TestGitLabApiBeans { ...@@ -310,7 +311,7 @@ public class TestGitLabApiBeans {
public void testPushRule() { public void testPushRule() {
try { try {
PushRule pushRule = makeFakeApiCall(PushRule.class, "push-rule"); PushRules pushRule = makeFakeApiCall(PushRules.class, "push-rule");
assertTrue(compareJson(pushRule, "push-rule")); assertTrue(compareJson(pushRule, "push-rule"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -343,6 +344,17 @@ public class TestGitLabApiBeans { ...@@ -343,6 +344,17 @@ public class TestGitLabApiBeans {
} }
} }
@Test
public void testJiraService() {
try {
JiraService jira = makeFakeApiCall(JiraService.class, "jira");
assertTrue(compareJson(jira, "jira"));
} catch (Exception e) {
e.printStackTrace();
}
}
@Test @Test
public void testKey() { public void testKey() {
......
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