Commit 80d32ac6 authored by Greg Messner's avatar Greg Messner
Browse files

Mods for webhook support.

parent e9f806a4
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.gitlab4j</groupId>
......@@ -193,6 +194,11 @@
<artifactId>jersey-client</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
......
package org.gitlab4j.api;
import org.gitlab4j.api.utils.JacksonJson;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.ClientProperties;
......
......@@ -15,6 +15,16 @@ public class GitLabApiException extends Exception {
private StatusType statusInfo;
private int httpStatus;
private String message;
/**
* Create a GitLabApiException instance with the specified message.
*
* @param message the message for the exception
*/
public GitLabApiException(String message) {
super(message);
this.message = message;
}
/**
* Create a GitLabApiException instance based on the ClientResponse.
......
......@@ -14,6 +14,7 @@ import javax.ws.rs.core.Response;
import org.gitlab4j.api.models.Branch;
import org.gitlab4j.api.models.Tag;
import org.gitlab4j.api.models.TreeItem;
import org.gitlab4j.api.utils.FileUtils;
/**
* This class provides an entry point to all the GitLab API repository calls.
......@@ -180,7 +181,7 @@ public class RepositoryApi extends AbstractApi {
String releaseNotes;
if (releaseNotesFile != null) {
try {
releaseNotes = Utils.readFileContents(releaseNotesFile);
releaseNotes = FileUtils.readFileContents(releaseNotesFile);
} catch (IOException ioe) {
throw (new GitLabApiException(ioe));
}
......@@ -335,7 +336,7 @@ public class RepositoryApi extends AbstractApi {
if (directory == null)
directory = new File(System.getProperty("java.io.tmpdir"));
String filename = Utils.getFilenameFromContentDisposition(response);
String filename = FileUtils.getFilenameFromContentDisposition(response);
File file = new File(directory, filename);
InputStream in = response.readEntity(InputStream.class);
......
package org.gitlab4j.api;
package org.gitlab4j.api.utils;
import java.io.File;
import java.io.IOException;
......@@ -9,7 +9,7 @@ import javax.ws.rs.core.Response;
/**
* This class provides static utility methods used throughout GitLab4J.
*/
public class Utils {
public class FileUtils {
/**
* Creates a File that is unique in the specified directory. If the specified
......
package org.gitlab4j.api;
package org.gitlab4j.api.utils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
......
package org.gitlab4j.api;
package org.gitlab4j.api.utils;
import java.io.IOException;
import java.io.Reader;
......
package org.gitlab4j.api.webhook;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
@JsonTypeInfo(use=JsonTypeInfo.Id.NAME,
include=JsonTypeInfo.As.PROPERTY,
property="object_kind")
@JsonSubTypes({
@JsonSubTypes.Type(value = IssueEvent.class, name = IssueEvent.OBJECT_KIND),
@JsonSubTypes.Type(value = MergeRequestEvent.class, name = MergeRequestEvent.OBJECT_KIND),
@JsonSubTypes.Type(value = NoteEvent.class, name = NoteEvent.OBJECT_KIND),
@JsonSubTypes.Type(value = PushEvent.class, name = PushEvent.OBJECT_KIND),
@JsonSubTypes.Type(value = TagPushEvent.class, name = TagPushEvent.OBJECT_KIND)
})
public interface Event {
public String getObjectKind();
}
......@@ -3,8 +3,12 @@ package org.gitlab4j.api.webhook;
import java.util.Date;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import org.gitlab4j.api.models.Author;
@XmlAccessorType(XmlAccessType.FIELD)
public class EventCommit {
private String id;
......
package org.gitlab4j.api.webhook;
import java.util.Date;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
......@@ -19,12 +17,12 @@ public class IssueEvent implements Event {
private EventRepository repository;
private ObjectAttributes objectAttributes;
private Assignee assignee;
public String getObjectKind() {
return (OBJECT_KIND);
}
public void setObjectKind(String objectKind) {
public void setObjectKind(String objectKind) {
if (!OBJECT_KIND.equals(objectKind))
throw new RuntimeException("Invalid object_kind (" + objectKind + "), must be '" + OBJECT_KIND + "'");
}
......@@ -69,147 +67,6 @@ public class IssueEvent implements Event {
this.objectAttributes = objectAttributes;
}
@XmlAccessorType(XmlAccessType.FIELD)
public static class ObjectAttributes {
private Integer assigneeId;
private Integer authorId;
private String branchName;
private Date createdAt;
private String description;
private Integer id;
private Integer iid;
private String milestoneId;
private Integer position;
private Integer projectId;
private String state;
private String title;
private Date updatedAt;
private String url;
private String action;
public Integer getAssigneeId() {
return this.assigneeId;
}
public void setAssigneeId(Integer assigneeId) {
this.assigneeId = assigneeId;
}
public Integer getAuthorId() {
return this.authorId;
}
public void setAuthorId(Integer authorId) {
this.authorId = authorId;
}
public String getBranchName() {
return this.branchName;
}
public void setBranchName(String branchName) {
this.branchName = branchName;
}
public Date getCreatedAt() {
return this.createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getIid() {
return this.iid;
}
public void setIid(Integer iid) {
this.iid = iid;
}
public String getMilestoneId() {
return this.milestoneId;
}
public void setMilestoneId(String milestoneId) {
this.milestoneId = milestoneId;
}
public Integer getPosition() {
return this.position;
}
public void setPosition(Integer position) {
this.position = position;
}
public Integer getProjectId() {
return this.projectId;
}
public void setProjectId(Integer projectId) {
this.projectId = projectId;
}
public String getState() {
return this.state;
}
public void setState(String state) {
this.state = state;
}
public String getTitle() {
return this.title;
}
public void setTitle(String title) {
this.title = title;
}
public Date getUpdatedAt() {
return this.updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
public static class ObjectAttributes extends EventIssue {
}
}
package org.gitlab4j.api.webhook;
import java.util.Date;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import org.gitlab4j.api.models.Assignee;
import org.gitlab4j.api.models.User;
@XmlAccessorType(XmlAccessType.FIELD)
......@@ -43,251 +40,6 @@ public class MergeRequestEvent implements Event {
}
@XmlAccessorType(XmlAccessType.FIELD)
public static class ObjectAttributes {
private Integer assigneeId;
private Integer authorId;
private String branchName;
private Date createdAt;
private String description;
private Integer id;
private Integer iid;
private String mergeStatus;
private String milestoneId;
private Integer position;
private Integer projectId;
private String sourceBranch;
private Integer sourceProjectId;
private String stCommits;
private String stDiffs;
private String state;
private String targetBranch;
private Integer targetProjectId;
private String title;
private Date updatedAt;
private EventProject source;
private EventProject target;
private EventCommit lastCommit;
private Boolean workInProgress;
private String url;
private String action;
private Assignee assignee;
public Integer getAssigneeId() {
return this.assigneeId;
}
public void setAssigneeId(Integer assigneeId) {
this.assigneeId = assigneeId;
}
public Integer getAuthorId() {
return this.authorId;
}
public void setAuthorId(Integer authorId) {
this.authorId = authorId;
}
public String getBranchName() {
return this.branchName;
}
public void setBranchName(String branchName) {
this.branchName = branchName;
}
public Date getCreatedAt() {
return this.createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getIid() {
return this.iid;
}
public void setIid(Integer iid) {
this.iid = iid;
}
public String getMergeStatus() {
return this.mergeStatus;
}
public void setMergeStatus(String mergeStatus) {
this.mergeStatus = mergeStatus;
}
public String getMilestoneId() {
return this.milestoneId;
}
public void setMilestoneId(String milestoneId) {
this.milestoneId = milestoneId;
}
public Integer getPosition() {
return this.position;
}
public void setPosition(Integer position) {
this.position = position;
}
public Integer getProjectId() {
return this.projectId;
}
public void setProjectId(Integer projectId) {
this.projectId = projectId;
}
public String getSourceBranch() {
return this.sourceBranch;
}
public void setSourceBranch(String sourceBranch) {
this.sourceBranch = sourceBranch;
}
public Integer getSourceProjectId() {
return this.sourceProjectId;
}
public void setSourceProjectId(Integer sourceProjectId) {
this.sourceProjectId = sourceProjectId;
}
public String getStCommits() {
return this.stCommits;
}
public void setStCommits(String stCommits) {
this.stCommits = stCommits;
}
public String getStDiffs() {
return this.stDiffs;
}
public void setStDiffs(String stDiffs) {
this.stDiffs = stDiffs;
}
public String getState() {
return this.state;
}
public void setState(String state) {
this.state = state;
}
public String getTargetBranch() {
return this.targetBranch;
}
public void setTargetBranch(String targetBranch) {
this.targetBranch = targetBranch;
}
public Integer getTargetProjectId() {
return this.targetProjectId;
}
public void setTargetProjectId(Integer targetProjectId) {
this.targetProjectId = targetProjectId;
}
public String getTitle() {
return this.title;
}
public void setTitle(String title) {
this.title = title;
}
public Date getUpdatedAt() {
return this.updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
public EventProject getSource() {
return source;
}
public void setSource(EventProject source) {
this.source = source;
}
public EventProject getTarget() {
return target;
}
public void setTarget(EventProject target) {
this.target = target;
}
public EventCommit getLastCommit() {
return lastCommit;
}
public void setLastCommit(EventCommit lastCommit) {
this.lastCommit = lastCommit;
}
public Boolean getWorkInProgress() {
return workInProgress;
}
public void setWorkInProgress(Boolean workInProgress) {
this.workInProgress = workInProgress;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
public Assignee getAssignee() {
return assignee;
}
public void setAssignee(Assignee assignee) {
this.assignee = assignee;
}
public static class ObjectAttributes extends EventMergeRequest {
}
}
......@@ -7,7 +7,6 @@ import java.io.InputStreamReader;
import java.util.List;
import org.gitlab4j.api.GitLabApi;
import org.gitlab4j.api.JacksonJson;
import org.gitlab4j.api.models.Branch;
import org.gitlab4j.api.models.Commit;
import org.gitlab4j.api.models.Diff;
......@@ -27,6 +26,7 @@ import org.gitlab4j.api.models.SystemHook;
import org.gitlab4j.api.models.Tag;
import org.gitlab4j.api.models.TreeItem;
import org.gitlab4j.api.models.User;
import org.gitlab4j.api.utils.JacksonJson;
import org.junit.BeforeClass;
import org.junit.Test;
......
......@@ -5,12 +5,13 @@ import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.io.InputStreamReader;
import org.gitlab4j.api.GitLabApi;
import org.gitlab4j.api.JacksonJson;
import org.gitlab4j.api.utils.JacksonJson;
import org.gitlab4j.api.webhook.Event;
import org.gitlab4j.api.webhook.IssueEvent;
import org.gitlab4j.api.webhook.MergeRequestEvent;
import org.gitlab4j.api.webhook.NoteEvent;
import org.gitlab4j.api.webhook.PushEvent;
import org.gitlab4j.api.webhook.TagPushEvent;
import org.junit.BeforeClass;
import org.junit.Test;
......@@ -36,36 +37,84 @@ public class TestGitLabApiEvents {
}
@Test
public void testIssueEvent() {
public void testIssueEvent() throws Exception {
try {
Event issueEvent = makeFakeApiCall(IssueEvent.class, "issue-event");
assertTrue(compareJson(issueEvent, "issue-event"));
} catch (Exception e) {
e.printStackTrace();
}
Event issueEvent = makeFakeApiCall(IssueEvent.class, "issue-event");
assertTrue(compareJson(issueEvent, "issue-event"));
}
@Test
public void testMergeRequestEvent() {
public void testMergeRequestEvent() throws Exception {
try {
Event mergeRequestEvent = makeFakeApiCall(MergeRequestEvent.class, "merge-request-event");
assertTrue(compareJson(mergeRequestEvent, "merge-request-event"));
} catch (Exception e) {
e.printStackTrace();
}
Event mergeRequestEvent = makeFakeApiCall(MergeRequestEvent.class, "merge-request-event");
assertTrue(compareJson(mergeRequestEvent, "merge-request-event"));
}
@Test
public void testPushEvent() {
public void testPushEvent() throws Exception {
try {
PushEvent pushEvent = makeFakeApiCall(PushEvent.class, "push-event");
assertTrue(compareJson(pushEvent, "push-event"));
} catch (Exception e) {
e.printStackTrace();
}
Event pushEvent = makeFakeApiCall(PushEvent.class, "push-event");
assertTrue(compareJson(pushEvent, "push-event"));
}
@Test
public void testTagPushEvent() throws Exception {
Event pushEvent = makeFakeApiCall(TagPushEvent.class, "tag-push-event");
assertTrue(compareJson(pushEvent, "tag-push-event"));
}
@Test
public void testNoteCommitEvent() throws Exception {
Event noteEvent = makeFakeApiCall(NoteEvent.class, "note-commit-event");
assertTrue(compareJson(noteEvent, "note-commit-event"));
}
@Test
public void testNoteMergeRequestEvent() throws Exception {
Event noteEvent = makeFakeApiCall(NoteEvent.class, "note-merge-request-event");
assertTrue(compareJson(noteEvent, "note-merge-request-event"));
}
@Test
public void testNoteIssueEvent() throws Exception {
Event noteEvent = makeFakeApiCall(NoteEvent.class, "note-issue-event");
assertTrue(compareJson(noteEvent, "note-issue-event"));
}
@Test
public void testNoteSnippetEvent() throws Exception {
Event noteEvent = makeFakeApiCall(NoteEvent.class, "note-snippet-event");
assertTrue(compareJson(noteEvent, "note-snippet-event"));
}
@Test
public void testPolymorphicEvent() throws Exception {
Event event = makeFakeApiCall(Event.class, "issue-event");
assertTrue(compareJson(event, "issue-event"));
event = makeFakeApiCall(Event.class, "merge-request-event");
assertTrue(compareJson(event, "merge-request-event"));
event = makeFakeApiCall(Event.class, "note-commit-event");
assertTrue(compareJson(event, "note-commit-event"));
event = makeFakeApiCall(Event.class, "note-issue-event");
assertTrue(compareJson(event, "note-issue-event"));
event = makeFakeApiCall(Event.class, "note-merge-request-event");
assertTrue(compareJson(event, "note-merge-request-event"));
event = makeFakeApiCall(Event.class, "note-snippet-event");
assertTrue(compareJson(event, "note-snippet-event"));
event = makeFakeApiCall(Event.class, "tag-push-event");
assertTrue(compareJson(event, "tag-push-event"));
}
private <T> T makeFakeApiCall(Class<T> returnType, String file) throws JsonParseException, JsonMappingException, IOException {
......@@ -90,8 +139,8 @@ public class TestGitLabApiEvents {
}
return (sameJson);
}
private void sortedDump(final JsonNode node) throws JsonProcessingException {
private void sortedDump(final JsonNode node) throws JsonProcessingException {
final Object obj = jacksonJson.getObjectMapper().treeToValue(node, Object.class);
System.out.println(jacksonJson.getObjectMapper().writeValueAsString(obj));
}
......
Supports Markdown
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