Commit 86ab17d4 authored by Tom Taxon's avatar Tom Taxon
Browse files

Add support for email on push integration.

parent 1287b236
......@@ -3,6 +3,7 @@ package org.gitlab4j.api;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.services.BugzillaService;
import org.gitlab4j.api.services.CustomIssueTrackerService;
import org.gitlab4j.api.services.EmailOnPushService;
import org.gitlab4j.api.services.ExternalWikiService;
import org.gitlab4j.api.services.HipChatService;
import org.gitlab4j.api.services.JiraService;
......@@ -493,4 +494,58 @@ public class ServicesApi extends AbstractApi {
delete(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "custom-issue-tracker");
}
/**
* Get the Custom Issue Tracker service settings for a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/services/custom_issue_tracker</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @return a ExternalWikiService instance holding the External Wiki service settings
* @throws GitLabApiException if any exception occurs
*/
public EmailOnPushService getEmailOnPushService(Object projectIdOrPath) throws GitLabApiException {
Response response = this.get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "emails-on-push");
return (response.readEntity(EmailOnPushService.class));
}
/**
* Updates the Custom Issue Tracker service settings for a project.
*
* <pre><code>GitLab Endpoint: PUT /projects/:id/services/custom_issue_tracker</code></pre>
*
* The following properties on the CustomIssueTrackerService instance are utilized in the update of the settings:
* <p>
* description (optional), description
* issuesUrl (required), issue url
* newIssueUrl (required), new Issue url
* projectUrl (required), project url
* pushEvents (optional) - Enable notifications for push events
* title (optional), the title for the custom issue tracker
* </p>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param customIssueTracker the CustomIssueTrackerService instance holding the settings
* @return a CustomIssueTrackerService instance holding the newly updated settings
* @throws GitLabApiException if any exception occurs
*/
public EmailOnPushService updateEmailOnPushService(Object projectIdOrPath, EmailOnPushService customIssueTracker) throws GitLabApiException {
GitLabApiForm formData = customIssueTracker.servicePropertiesForm();
Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "services", "emails-on-push");
return (response.readEntity(EmailOnPushService.class));
}
/**
* Deletes the Custom Issue Tracker service for a project.
*
* <pre><code>GitLab Endpoint: DELETE /projects/:id/services/custom_issue_tracker</code></pre>
*
* @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 deleteEmailonPushService(Object projectIdOrPath) throws GitLabApiException {
delete(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "emails-on-push");
}
}
package org.gitlab4j.api.services;
import org.gitlab4j.api.GitLabApiForm;
import com.fasterxml.jackson.annotation.JsonIgnore;
public class EmailOnPushService extends NotificationService {
public static final String RECIPIENT_PROP = "recipients";
public static final String DISABLE_DIFFS_PROP = "disable_diffs";
public static final String SEND_FROM_COMMITTER_EMAIL = "send_from_committer_email";
public static final String BRANCHES_TO_BE_NOTIFIED = "branches_to_be_notified";
@Override
public GitLabApiForm servicePropertiesForm() {
GitLabApiForm formData = new GitLabApiForm()
.withParam(RECIPIENT_PROP, getRecipients(), true)
.withParam(DISABLE_DIFFS_PROP, getDisableDiffs())
.withParam(SEND_FROM_COMMITTER_EMAIL, getSendFromCommitterEmail())
.withParam(PUSH_EVENTS_PROP, getPushEvents())
.withParam("tag_push_events", getTagPushEvents())
.withParam(BRANCHES_TO_BE_NOTIFIED, getBranchesToBeNotified());
return formData;
}
public EmailOnPushService withPushEvents(Boolean pushEvents) {
return withPushEvents(pushEvents, this);
}
public EmailOnPushService withTagPushEvents(Boolean pushEvents) {
return withTagPushEvents(pushEvents, this);
}
@JsonIgnore
public String getRecipients() {
return ((String)getProperty(RECIPIENT_PROP));
}
public void setRecipients(String recipients) {
setProperty(RECIPIENT_PROP, recipients);
}
public EmailOnPushService withRecipients(String recipients) {
setRecipients(recipients);
return this;
}
@JsonIgnore
public Boolean getDisableDiffs() {
return Boolean.valueOf(getProperty(DISABLE_DIFFS_PROP,"false"));
}
public void setDisableDiffs(Boolean disableDiffs) {
setProperty(DISABLE_DIFFS_PROP, disableDiffs);
}
public EmailOnPushService withDisableDiffs(Boolean disableDiffs) {
setDisableDiffs(disableDiffs);
return this;
}
@JsonIgnore
public Boolean getSendFromCommitterEmail() {
return Boolean.valueOf(getProperty(SEND_FROM_COMMITTER_EMAIL,"false"));
}
public void setSendFromCommitterEmail(Boolean sendFromCommitterEmail) {
setProperty(SEND_FROM_COMMITTER_EMAIL, sendFromCommitterEmail);
}
public EmailOnPushService withSendFromCommitterEmail(Boolean sendFromCommitterEmail) {
setSendFromCommitterEmail(sendFromCommitterEmail);
return this;
}
@JsonIgnore
public String getBranchesToBeNotified() {
return ((String)getProperty(BRANCHES_TO_BE_NOTIFIED));
}
public void setBranchesToBeNotified(String branchesToBeNotified) {
setProperty(BRANCHES_TO_BE_NOTIFIED, branchesToBeNotified);
}
public EmailOnPushService withBranchesToBeNotified(String branchesToBeNotified) {
setBranchesToBeNotified(branchesToBeNotified);
return this;
}
}
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