Commit 4d9a8a08 authored by Amudha Palani's avatar Amudha Palani Committed by Tim Olshansky

Add Service Email-On-Push (#161)

Add Service Email-On-Push
parent 96372c20
...@@ -2404,4 +2404,59 @@ public class GitlabAPI { ...@@ -2404,4 +2404,59 @@ public class GitlabAPI {
return retrieve().getAll(GitlabProject.URL + "/" + project.getId() + GitlabTrigger.URL, GitlabTrigger[].class); return retrieve().getAll(GitlabProject.URL + "/" + project.getId() + GitlabTrigger.URL, GitlabTrigger[].class);
} }
} }
/**
* Gets email-on-push service setup for a projectId.
* @param projectId The ID of the project containing the variable.
* @throws IOException
*/
public GitlabServiceEmailOnPush getEmailsOnPush(Integer projectId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + projectId + GitlabServiceEmailOnPush.URL;
return retrieve().to(tailUrl, GitlabServiceEmailOnPush.class);
}
/**
* Update recipients for email-on-push service for a projectId.
* @param projectId The ID of the project containing the variable.
* @param emailAddress The emailaddress of the recipent who is going to receive push notification.
* @return
* @throws IOException
*/
public boolean updateEmailsOnPush(Integer projectId, String emailAddress) throws IOException {
String tailUrl = GitlabProject.URL + "/" + projectId + GitlabServiceEmailOnPush.URL;
GitlabServiceEmailOnPush emailOnPush = this.getEmailsOnPush(projectId);
GitlabEmailonPushProperties properties = emailOnPush.getProperties();
String appendedRecipients = properties.getRecipients();
if(appendedRecipients != "")
{
if(appendedRecipients.contains(emailAddress))
return true;
appendedRecipients = appendedRecipients + " " + emailAddress;
}
else
appendedRecipients = emailAddress;
Query query = new Query()
.appendIf("active", true)
.appendIf("recipients", appendedRecipients);
tailUrl = GitlabProject.URL + "/" + projectId + GitlabServiceEmailOnPush.URL + query.toString();
return retrieve().method("PUT").to(tailUrl, Boolean.class);
}
/**
*
* Get a list of projects accessible by the authenticated user by search.
*
* @return A list of gitlab projects
* @throws IOException
*/
public List<GitlabProject> searchProjects(String query) throws IOException {
List<GitlabProject> projects = new ArrayList<GitlabProject>();
String tailUrl = GitlabProject.URL + "/search/" + query;
GitlabProject[] response = retrieve().to(tailUrl, GitlabProject[].class);
projects = Arrays.asList(response);
return projects;
}
} }
package org.gitlab.api.models;
public class GitlabEmailonPushProperties {
private Integer disable_diffs;
private String recipients;
private Integer send_from_committer_email;
public Integer getDisableDiffs() {
return disable_diffs;
}
public void setDisableDiffs(Integer disable_diffs) {
this.disable_diffs = disable_diffs;
}
public String getRecipients() {
return recipients;
}
public void setRecipients(String recipients) {
this.recipients = recipients;
}
public Integer getSendFromCommitterEmail() {
return send_from_committer_email;
}
public void setSendFromCommitterEmail(Integer send_from_committer_email) {
this.send_from_committer_email = send_from_committer_email;
}
}
package org.gitlab.api.models;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonProperty;
public class GitlabServiceEmailOnPush {
public static final String URL = "/services/emails-on-push/";
private Integer id;
private String title;
@JsonProperty("created_at")
private Date createdAt;
@JsonProperty("updated_at")
private Date updatedAt;
private boolean active;
private boolean push_events;
private boolean issues_events;
private boolean merge_requests_events;
private boolean tag_push_events;
private boolean note_events;
private boolean build_events;
private GitlabEmailonPushProperties properties;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public boolean isPushEvents() {
return push_events;
}
public void setPushEvents(boolean push_events) {
this.push_events = push_events;
}
public boolean isIssuesEvents() {
return issues_events;
}
public void setIssuesEvents(boolean issues_events) {
this.issues_events = issues_events;
}
public boolean isMergeRequestsEvents() {
return merge_requests_events;
}
public void setMergeRequestsEvents(boolean merge_requests_events) {
this.merge_requests_events = merge_requests_events;
}
public boolean isTagPushEvents() {
return tag_push_events;
}
public void setTagPushEvents(boolean tag_push_events) {
this.tag_push_events = tag_push_events;
}
public boolean isNoteEvents() {
return note_events;
}
public void setNoteEvents(boolean note_events) {
this.note_events = note_events;
}
public boolean isBuildEvents() {
return build_events;
}
public void setBuildEvents(boolean build_events) {
this.build_events = build_events;
}
public GitlabEmailonPushProperties getProperties() {
return properties;
}
public void setProperties(GitlabEmailonPushProperties properties) {
this.properties = properties;
}
}
Markdown is supported
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