Commit 10319475 authored by Christopher Luu's avatar Christopher Luu

Added project hook methods.

Fetches, adds, and deletes project hooks.
parent c26ab735
......@@ -9,6 +9,7 @@ import org.gitlab.api.models.GitlabBranch;
import org.gitlab.api.models.GitlabMergeRequest;
import org.gitlab.api.models.GitlabNote;
import org.gitlab.api.models.GitlabProject;
import org.gitlab.api.models.GitlabProjectHook;
import org.gitlab.api.models.GitlabUser;
import java.io.IOException;
......@@ -52,6 +53,10 @@ public class GitlabAPI {
return new GitlabHTTPRequestor(this).method("POST");
}
public GitlabHTTPRequestor delete() {
return new GitlabHTTPRequestor(this).method("DELETE");
}
public boolean isIgnoreCertificateErrors() {
return _ignoreCertificateErrors;
}
......@@ -115,7 +120,35 @@ public class GitlabAPI {
}
return results;
}
// Get list of project hooks for a project
// GET /projects/:id/hooks
public List<GitlabProjectHook> getProjectHooks(Integer projectId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + projectId + GitlabProjectHook.URL;
GitlabProjectHook[] hooks = retrieve().to(tailUrl, GitlabProjectHook[].class);
return Arrays.asList(hooks);
}
// Create a new project hook
// POST /projects/:id/hooks
public GitlabProjectHook createProjectHook(Integer projectId, String url, boolean pushEvents, boolean issuesEvents, boolean mergeRequestEvents) throws IOException {
String tailUrl = GitlabProject.URL + "/" + projectId + GitlabProjectHook.URL;
return dispatch()
.with("url", url)
.with("push_events", pushEvents ? "true" : "false")
.with("issues_events", issuesEvents ? "true" : "false")
.with("merge_requests_events", mergeRequestEvents ? "true" : "false")
.to(tailUrl, GitlabProjectHook.class);
}
// Removes a hook from project
// DELETE /projects/:id/hooks/:hook_id
public void deleteProjectHook(GitlabProjectHook hook) throws IOException {
String tailUrl = GitlabProject.URL + "/" + hook.getProjectId() + GitlabProjectHook.URL + "/" + hook.getId();
delete().to(tailUrl, GitlabProjectHook.class);
}
/*
......
package org.gitlab.api.models;
import java.util.Date;
import org.codehaus.jackson.annotate.JsonProperty;
public class GitlabProjectHook {
public static final String URL = "/hooks";
private Integer _id;
private String _url;
@JsonProperty("project_id")
private Integer _projectId;
@JsonProperty("push_events")
private boolean _pushEvents;
@JsonProperty("issues_events")
private boolean _issueEvents;
@JsonProperty("merge_requests_events")
private boolean _mergeRequestsEvents;
@JsonProperty("created_at")
private Date _createdAt;
public Integer getId() {
return _id;
}
public void setId(Integer id) {
_id = id;
}
public String getUrl() {
return _url;
}
public void setUrl(String url) {
_url = url;
}
public Integer getProjectId() {
return _projectId;
}
public void setProjectId(Integer projectId) {
_projectId = projectId;
}
public boolean getPushEvents() {
return _pushEvents;
}
public void setPushEvents(boolean pushEvents) {
_pushEvents = pushEvents;
}
public Date getCreatedAt() {
return _createdAt;
}
public void setCreatedAt(Date createdAt) {
_createdAt = createdAt;
}
public boolean getIssueEvents() {
return _issueEvents;
}
public void setIssueEvents(boolean issueEvents) {
_issueEvents = issueEvents;
}
public boolean isMergeRequestsEvents() {
return _mergeRequestsEvents;
}
public void setMergeRequestsEvents(boolean mergeRequestsEvents) {
_mergeRequestsEvents = mergeRequestsEvents;
}
}
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