Skip to content

Add support for email on push integration. #662

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 2 commits into from
Mar 22, 2021
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
57 changes: 57 additions & 0 deletions src/main/java/org/gitlab4j/api/ServicesApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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.ExternalUncycloService;
import org.gitlab4j.api.services.HipChatService;
import org.gitlab4j.api.services.JiraService;
Expand Down Expand Up @@ -493,4 +494,60 @@ public void deleteCustomIssueTrackerService(Object projectIdOrPath) throws GitLa
delete(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "custom-issue-tracker");

}

/**
* Get Emails on push service settings for a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/services/emails-on-push</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @return a EmailOnPushService instance holding the Email on push 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 EmailsOnPush service settings for a project.
*
* <pre><code>GitLab Endpoint: PUT /projects/:id/services/emails-on-push</code></pre>
*
* The following properties on the EmailOnPushService instance are utilized in the update of the settings:
* <p>
* recipients (required), Emails separated by whitespace
* disable_diffs (optional), Disable code diffs
* send_from_committer_email (optional), Send from committer
* push_events (optional), Enable notifications for push events
* tag_push_events(optional), Enable notifications for tag push events
* branches_to_be_notified (optional), Branches to send notifications for. Valid options are "all", "default",
* "protected", and "default_and_protected". Notifications are always fired
* for tag pushes. The default value is "all"
* </p>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param emailsOnPush the EmailOnPushService instance holding the settings
* @return a EmailOnPushService instance holding the newly updated settings
* @throws GitLabApiException if any exception occurs
*/
public EmailOnPushService updateEmailOnPushService(Object projectIdOrPath, EmailOnPushService emailsOnPush) throws GitLabApiException {
GitLabApiForm formData = emailsOnPush.servicePropertiesForm();
Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "services", "emails-on-push");
return (response.readEntity(EmailOnPushService.class));
}

/**
* Deletes the Emails on push service for a project.
*
* <pre><code>GitLab Endpoint: DELETE /projects/:id/services/emails-on-push</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");

}

}
83 changes: 83 additions & 0 deletions src/main/java/org/gitlab4j/api/services/EmailOnPushService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
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_PROP = "send_from_committer_email";
public static final String BRANCHES_TO_BE_NOTIFIED_PROP = "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_PROP, getSendFromCommitterEmail())
.withParam(PUSH_EVENTS_PROP, getPushEvents())
.withParam("tag_push_events", getTagPushEvents())
.withParam(BRANCHES_TO_BE_NOTIFIED_PROP, 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_PROP,"false"));
}
public void setSendFromCommitterEmail(Boolean sendFromCommitterEmail) {
setProperty(SEND_FROM_COMMITTER_EMAIL_PROP, sendFromCommitterEmail);
}
public EmailOnPushService withSendFromCommitterEmail(Boolean sendFromCommitterEmail) {
setSendFromCommitterEmail(sendFromCommitterEmail);
return this;
}

@JsonIgnore
public String getBranchesToBeNotified() {
return ((String)getProperty(BRANCHES_TO_BE_NOTIFIED_PROP));
}
public void setBranchesToBeNotified(String branchesToBeNotified) {
setProperty(BRANCHES_TO_BE_NOTIFIED_PROP, branchesToBeNotified);
}
public EmailOnPushService withBranchesToBeNotified(String branchesToBeNotified) {
setBranchesToBeNotified(branchesToBeNotified);
return this;
}


}