Skip to content

Commit 86ab17d

Browse files
committed
Add support for email on push integration.
1 parent 1287b23 commit 86ab17d

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed

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

Lines changed: 55 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,58 @@ 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 the Custom Issue Tracker service settings for a project.
500+
*
501+
* <pre><code>GitLab Endpoint: GET /projects/:id/services/custom_issue_tracker</code></pre>
502+
*
503+
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
504+
* @return a ExternalUncycloService instance holding the External Uncyclo service 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 Custom Issue Tracker service settings for a project.
514+
*
515+
* <pre><code>GitLab Endpoint: PUT /projects/:id/services/custom_issue_tracker</code></pre>
516+
*
517+
* The following properties on the CustomIssueTrackerService instance are utilized in the update of the settings:
518+
* <p>
519+
* description (optional), description
520+
* issuesUrl (required), issue url
521+
* newIssueUrl (required), new Issue url
522+
* projectUrl (required), project url
523+
* pushEvents (optional) - Enable notifications for push events
524+
* title (optional), the title for the custom issue tracker
525+
* </p>
526+
*
527+
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
528+
* @param customIssueTracker the CustomIssueTrackerService instance holding the settings
529+
* @return a CustomIssueTrackerService instance holding the newly updated settings
530+
* @throws GitLabApiException if any exception occurs
531+
*/
532+
public EmailOnPushService updateEmailOnPushService(Object projectIdOrPath, EmailOnPushService customIssueTracker) throws GitLabApiException {
533+
GitLabApiForm formData = customIssueTracker.servicePropertiesForm();
534+
Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "services", "emails-on-push");
535+
return (response.readEntity(EmailOnPushService.class));
536+
}
537+
538+
/**
539+
* Deletes the Custom Issue Tracker service for a project.
540+
*
541+
* <pre><code>GitLab Endpoint: DELETE /projects/:id/services/custom_issue_tracker</code></pre>
542+
*
543+
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
544+
* @throws GitLabApiException if any exception occurs
545+
*/
546+
public void deleteEmailonPushService(Object projectIdOrPath) throws GitLabApiException {
547+
delete(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "emails-on-push");
548+
549+
}
550+
496551
}
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 = "send_from_committer_email";
12+
public static final String BRANCHES_TO_BE_NOTIFIED = "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, getSendFromCommitterEmail())
20+
.withParam(PUSH_EVENTS_PROP, getPushEvents())
21+
.withParam("tag_push_events", getTagPushEvents())
22+
.withParam(BRANCHES_TO_BE_NOTIFIED, 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,"false"));
61+
}
62+
public void setSendFromCommitterEmail(Boolean sendFromCommitterEmail) {
63+
setProperty(SEND_FROM_COMMITTER_EMAIL, 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));
73+
}
74+
public void setBranchesToBeNotified(String branchesToBeNotified) {
75+
setProperty(BRANCHES_TO_BE_NOTIFIED, branchesToBeNotified);
76+
}
77+
public EmailOnPushService withBranchesToBeNotified(String branchesToBeNotified) {
78+
setBranchesToBeNotified(branchesToBeNotified);
79+
return this;
80+
}
81+
82+
83+
}

0 commit comments

Comments
 (0)