Skip to content

Commit d155674

Browse files
authored
Merge pull request #662 from ttaxon/emails-on-push
Add support for email on push integration.
2 parents cac2267 + 718e747 commit d155674

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed

src/main/java/org/gitlab4j/api/ServicesApi.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.gitlab4j.api.GitLabApi.ApiVersion;
44
import org.gitlab4j.api.services.BugzillaService;
55
import org.gitlab4j.api.services.CustomIssueTrackerService;
6+
import org.gitlab4j.api.services.EmailOnPushService;
67
import org.gitlab4j.api.services.ExternalUncycloService;
78
import org.gitlab4j.api.services.HipChatService;
89
import org.gitlab4j.api.services.JiraService;
@@ -493,4 +494,60 @@ public void deleteCustomIssueTrackerService(Object projectIdOrPath) throws GitLa
493494
delete(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "custom-issue-tracker");
494495

495496
}
497+
498+
/**
499+
* Get Emails on push service settings for a project.
500+
*
501+
* <pre><code>GitLab Endpoint: GET /projects/:id/services/emails-on-push</code></pre>
502+
*
503+
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
504+
* @return a EmailOnPushService instance holding the Email on push settings
505+
* @throws GitLabApiException if any exception occurs
506+
*/
507+
public EmailOnPushService getEmailOnPushService(Object projectIdOrPath) throws GitLabApiException {
508+
Response response = this.get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "emails-on-push");
509+
return (response.readEntity(EmailOnPushService.class));
510+
}
511+
512+
/**
513+
* Updates the EmailsOnPush service settings for a project.
514+
*
515+
* <pre><code>GitLab Endpoint: PUT /projects/:id/services/emails-on-push</code></pre>
516+
*
517+
* The following properties on the EmailOnPushService instance are utilized in the update of the settings:
518+
* <p>
519+
* recipients (required), Emails separated by whitespace
520+
* disable_diffs (optional), Disable code diffs
521+
* send_from_committer_email (optional), Send from committer
522+
* push_events (optional), Enable notifications for push events
523+
* tag_push_events(optional), Enable notifications for tag push events
524+
* branches_to_be_notified (optional), Branches to send notifications for. Valid options are "all", "default",
525+
* "protected", and "default_and_protected". Notifications are always fired
526+
* for tag pushes. The default value is "all"
527+
* </p>
528+
*
529+
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
530+
* @param emailsOnPush the EmailOnPushService instance holding the settings
531+
* @return a EmailOnPushService instance holding the newly updated settings
532+
* @throws GitLabApiException if any exception occurs
533+
*/
534+
public EmailOnPushService updateEmailOnPushService(Object projectIdOrPath, EmailOnPushService emailsOnPush) throws GitLabApiException {
535+
GitLabApiForm formData = emailsOnPush.servicePropertiesForm();
536+
Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "services", "emails-on-push");
537+
return (response.readEntity(EmailOnPushService.class));
538+
}
539+
540+
/**
541+
* Deletes the Emails on push service for a project.
542+
*
543+
* <pre><code>GitLab Endpoint: DELETE /projects/:id/services/emails-on-push</code></pre>
544+
*
545+
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
546+
* @throws GitLabApiException if any exception occurs
547+
*/
548+
public void deleteEmailonPushService(Object projectIdOrPath) throws GitLabApiException {
549+
delete(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "emails-on-push");
550+
551+
}
552+
496553
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package org.gitlab4j.api.services;
2+
3+
import org.gitlab4j.api.GitLabApiForm;
4+
5+
import com.fasterxml.jackson.annotation.JsonIgnore;
6+
7+
public class EmailOnPushService extends NotificationService {
8+
9+
public static final String RECIPIENT_PROP = "recipients";
10+
public static final String DISABLE_DIFFS_PROP = "disable_diffs";
11+
public static final String SEND_FROM_COMMITTER_EMAIL_PROP = "send_from_committer_email";
12+
public static final String BRANCHES_TO_BE_NOTIFIED_PROP = "branches_to_be_notified";
13+
14+
@Override
15+
public GitLabApiForm servicePropertiesForm() {
16+
GitLabApiForm formData = new GitLabApiForm()
17+
.withParam(RECIPIENT_PROP, getRecipients(), true)
18+
.withParam(DISABLE_DIFFS_PROP, getDisableDiffs())
19+
.withParam(SEND_FROM_COMMITTER_EMAIL_PROP, getSendFromCommitterEmail())
20+
.withParam(PUSH_EVENTS_PROP, getPushEvents())
21+
.withParam("tag_push_events", getTagPushEvents())
22+
.withParam(BRANCHES_TO_BE_NOTIFIED_PROP, getBranchesToBeNotified());
23+
return formData;
24+
}
25+
26+
public EmailOnPushService withPushEvents(Boolean pushEvents) {
27+
return withPushEvents(pushEvents, this);
28+
}
29+
public EmailOnPushService withTagPushEvents(Boolean pushEvents) {
30+
return withTagPushEvents(pushEvents, this);
31+
}
32+
33+
@JsonIgnore
34+
public String getRecipients() {
35+
return ((String)getProperty(RECIPIENT_PROP));
36+
}
37+
public void setRecipients(String recipients) {
38+
setProperty(RECIPIENT_PROP, recipients);
39+
}
40+
public EmailOnPushService withRecipients(String recipients) {
41+
setRecipients(recipients);
42+
return this;
43+
}
44+
45+
46+
@JsonIgnore
47+
public Boolean getDisableDiffs() {
48+
return Boolean.valueOf(getProperty(DISABLE_DIFFS_PROP,"false"));
49+
}
50+
public void setDisableDiffs(Boolean disableDiffs) {
51+
setProperty(DISABLE_DIFFS_PROP, disableDiffs);
52+
}
53+
public EmailOnPushService withDisableDiffs(Boolean disableDiffs) {
54+
setDisableDiffs(disableDiffs);
55+
return this;
56+
}
57+
58+
@JsonIgnore
59+
public Boolean getSendFromCommitterEmail() {
60+
return Boolean.valueOf(getProperty(SEND_FROM_COMMITTER_EMAIL_PROP,"false"));
61+
}
62+
public void setSendFromCommitterEmail(Boolean sendFromCommitterEmail) {
63+
setProperty(SEND_FROM_COMMITTER_EMAIL_PROP, sendFromCommitterEmail);
64+
}
65+
public EmailOnPushService withSendFromCommitterEmail(Boolean sendFromCommitterEmail) {
66+
setSendFromCommitterEmail(sendFromCommitterEmail);
67+
return this;
68+
}
69+
70+
@JsonIgnore
71+
public String getBranchesToBeNotified() {
72+
return ((String)getProperty(BRANCHES_TO_BE_NOTIFIED_PROP));
73+
}
74+
public void setBranchesToBeNotified(String branchesToBeNotified) {
75+
setProperty(BRANCHES_TO_BE_NOTIFIED_PROP, branchesToBeNotified);
76+
}
77+
public EmailOnPushService withBranchesToBeNotified(String branchesToBeNotified) {
78+
setBranchesToBeNotified(branchesToBeNotified);
79+
return this;
80+
}
81+
82+
83+
}

0 commit comments

Comments
 (0)