Commit 29b8d041 authored by Greg Messner's avatar Greg Messner
Browse files

Brought into spec with latest GitLab API docs (#357).

No related merge requests found
Showing with 403 additions and 129 deletions
+403 -129
......@@ -25,6 +25,8 @@ public class Job {
private String webUrl;
private String stage;
private JobStatus status;
private String when;
private Boolean manual;
public Integer getId() {
return id;
......@@ -170,6 +172,22 @@ public class Job {
this.runner = runner;
}
public String getWhen() {
return when;
}
public void setWhen(String when) {
this.when = when;
}
public Boolean getManual() {
return manual;
}
public void setManual(Boolean manual) {
this.manual = manual;
}
public Job withId(Integer id) {
this.id = id;
return this;
......@@ -245,6 +263,16 @@ public class Job {
return this;
}
public Job withWhen(String when) {
this.when = when;
return this;
}
public Job withManual(Boolean manual) {
this.manual = manual;
return this;
}
@Override
public String toString() {
return (JacksonJson.toJsonString(this));
......
......@@ -33,7 +33,7 @@ import com.fasterxml.jackson.annotation.JsonValue;
*/
public enum JobStatus {
RUNNING, PENDING, SUCCESS, FAILED, CANCELED, SKIPPED, MANUAL;
CREATED, RUNNING, PENDING, SUCCESS, FAILED, CANCELED, SKIPPED, MANUAL;
private static JacksonJsonEnumHelper<JobStatus> enumHelper = new JacksonJsonEnumHelper<>(JobStatus.class);
......
......@@ -8,8 +8,8 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
include=JsonTypeInfo.As.PROPERTY,
property="object_kind")
@JsonSubTypes({
@JsonSubTypes.Type(value = BuildEvent.class, name = BuildEvent.OBJECT_KIND),
@JsonSubTypes.Type(value = IssueEvent.class, name = IssueEvent.OBJECT_KIND),
@JsonSubTypes.Type(value = JobEvent.class, name = JobEvent.OBJECT_KIND),
@JsonSubTypes.Type(value = MergeRequestEvent.class, name = MergeRequestEvent.OBJECT_KIND),
@JsonSubTypes.Type(value = NoteEvent.class, name = NoteEvent.OBJECT_KIND),
@JsonSubTypes.Type(value = PipelineEvent.class, name = PipelineEvent.OBJECT_KIND),
......
package org.gitlab4j.api.webhook;
import java.util.Date;
import org.gitlab4j.api.models.User;
import org.gitlab4j.api.utils.JacksonJson;
public class JobEvent extends AbstractEvent {
public static final String JOB_HOOK_X_GITLAB_EVENT = "Job Hook";
public static final String OBJECT_KIND = "job";
private String ref;
private Boolean tag;
private String beforeSha;
private String sha;
private Integer jobId;
private String jobName;
private String jobStage;
private String jobStatus;
private Date jobStarted_at;
private Date jobFinished_at;
private Integer jobDuration;
private Boolean jobAllowFailure;
private String jobFailureReason;
private Integer projectId;
private String projectName;
private User user;
private JobCommit commit;
private EventRepository repository;
public String getObjectKind() {
return (OBJECT_KIND);
}
public void setObjectKind(String objectKind) {
if (!OBJECT_KIND.equals(objectKind))
throw new RuntimeException("Invalid object_kind (" + objectKind + "), must be '" + OBJECT_KIND + "'");
}
public String getRef() {
return ref;
}
public void setRef(String ref) {
this.ref = ref;
}
public Boolean getTag() {
return tag;
}
public void setTag(Boolean tag) {
this.tag = tag;
}
public String getBeforeSha() {
return beforeSha;
}
public void setBeforeSha(String beforeSha) {
this.beforeSha = beforeSha;
}
public String getSha() {
return sha;
}
public void setSha(String sha) {
this.sha = sha;
}
public Integer getJobId() {
return jobId;
}
public void setJobId(Integer jobId) {
this.jobId = jobId;
}
public String getJobName() {
return jobName;
}
public void setJobName(String jobName) {
this.jobName = jobName;
}
public String getJobStage() {
return jobStage;
}
public void setJobStage(String jobStage) {
this.jobStage = jobStage;
}
public String getJobStatus() {
return jobStatus;
}
public void setJobStatus(String jobStatus) {
this.jobStatus = jobStatus;
}
public Date getJobStarted_at() {
return jobStarted_at;
}
public void setJobStarted_at(Date jobStarted_at) {
this.jobStarted_at = jobStarted_at;
}
public Date getJobFinished_at() {
return jobFinished_at;
}
public void setJobFinished_at(Date jobFinished_at) {
this.jobFinished_at = jobFinished_at;
}
public Integer getJobDuration() {
return jobDuration;
}
public void setJobDuration(Integer jobDuration) {
this.jobDuration = jobDuration;
}
public Boolean getJobAllowFailure() {
return jobAllowFailure;
}
public void setJobAllowFailure(Boolean jobAllowFailure) {
this.jobAllowFailure = jobAllowFailure;
}
public String getJobFailureReason() {
return jobFailureReason;
}
public void setJobFailureReason(String jobFailureReason) {
this.jobFailureReason = jobFailureReason;
}
public Integer getProjectId() {
return projectId;
}
public void setProjectId(Integer projectId) {
this.projectId = projectId;
}
public String getProjectName() {
return projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public JobCommit getCommit() {
return commit;
}
public void setCommit(JobCommit commit) {
this.commit = commit;
}
public EventRepository getRepository() {
return repository;
}
public void setRepository(EventRepository repository) {
this.repository = repository;
}
public class JobCommit {
private Integer id;
private String sha;
private String message;
private String authorName;
private String authorEmail;
private String status;
private Integer duration;
private Date startedAt;
private Date finishedAt;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getSha() {
return sha;
}
public void setSha(String sha) {
this.sha = sha;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getAuthorName() {
return authorName;
}
public void setAuthorName(String authorName) {
this.authorName = authorName;
}
public String getAuthorEmail() {
return authorEmail;
}
public void setAuthorEmail(String authorEmail) {
this.authorEmail = authorEmail;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Integer getDuration() {
return duration;
}
public void setDuration(Integer duration) {
this.duration = duration;
}
public Date getStartedAt() {
return startedAt;
}
public void setStartedAt(Date startedAt) {
this.startedAt = startedAt;
}
public Date getFinishedAt() {
return finishedAt;
}
public void setFinishedAt(Date finishedAt) {
this.finishedAt = finishedAt;
}
@Override
public String toString() {
return (JacksonJson.toJsonString(this));
}
}
@Override
public String toString() {
return (JacksonJson.toJsonString(this));
}
}
......@@ -4,7 +4,9 @@ import java.util.Date;
import java.util.List;
import org.gitlab4j.api.models.ArtifactsFile;
import org.gitlab4j.api.models.Job;
import org.gitlab4j.api.models.User;
import org.gitlab4j.api.models.Variable;
import org.gitlab4j.api.utils.JacksonJson;
public class PipelineEvent extends AbstractEvent {
......@@ -16,7 +18,7 @@ public class PipelineEvent extends AbstractEvent {
private User user;
private EventProject project;
private EventCommit commit;
private List<Build> builds;
private List<Job> jobs;
public String getObjectKind() {
return (OBJECT_KIND);
......@@ -59,115 +61,12 @@ public class PipelineEvent extends AbstractEvent {
this.commit = commit;
}
public List<Build> getBuilds() {
return builds;
public List<Job> getJobs() {
return jobs;
}
public void setBuilds(List<Build> builds) {
this.builds = builds;
}
public static class Build {
private Integer id;
private String stage;
private String name;
private String status;
private Date createdAt;
private Date startedAt;
private Date finishedAt;
private String when;
private Boolean manual;
private User user;
private ArtifactsFile artifactsFile;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getStage() {
return stage;
}
public void setStage(String stage) {
this.stage = stage;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getStartedAt() {
return startedAt;
}
public void setStartedAt(Date startedAt) {
this.startedAt = startedAt;
}
public Date getFinishedAt() {
return finishedAt;
}
public void setFinishedAt(Date finishedAt) {
this.finishedAt = finishedAt;
}
public String getWhen() {
return when;
}
public void setWhen(String when) {
this.when = when;
}
public Boolean getManual() {
return manual;
}
public void setManual(Boolean manual) {
this.manual = manual;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public ArtifactsFile getArtifactsFile() {
return artifactsFile;
}
public void setArtifactsFile(ArtifactsFile artifactsFile) {
this.artifactsFile = artifactsFile;
}
public void setJobs(List<Job> jobs) {
this.jobs = jobs;
}
public static class ObjectAttributes {
......@@ -182,6 +81,7 @@ public class PipelineEvent extends AbstractEvent {
private Date createdAt;
private Date finishedAt;
private Integer duration;
private List<Variable> variables;
public Integer getId() {
return id;
......@@ -262,6 +162,14 @@ public class PipelineEvent extends AbstractEvent {
public void setDuration(Integer duration) {
this.duration = duration;
}
public List<Variable> getVariables() {
return variables;
}
public void setVariables(List<Variable> variables) {
this.variables = variables;
}
}
@Override
......
......@@ -8,11 +8,11 @@ package org.gitlab4j.api.webhook;
public interface WebHookListener extends java.util.EventListener {
/**
* This method is called when a WebHook build event has been received.
* This method is called when a WebHook job event has been received.
*
* @param buildEvent the BuildEvent instance
* @param jobEvent the JobEvent instance
*/
default void onBuildEvent(BuildEvent buildEvent) {
default void onJobEvent(JobEvent jobEvent) {
}
/**
......
......@@ -98,8 +98,7 @@ public class WebHookManager implements HookManager {
LOGGER.info("handleEvent: X-Gitlab-Event=" + eventName);
switch (eventName) {
case BuildEvent.BUILD_HOOK_X_GITLAB_EVENT:
case BuildEvent.JOB_HOOK_X_GITLAB_EVENT:
case JobEvent.JOB_HOOK_X_GITLAB_EVENT:
case IssueEvent.X_GITLAB_EVENT:
case MergeRequestEvent.X_GITLAB_EVENT:
case NoteEvent.X_GITLAB_EVENT:
......@@ -160,7 +159,7 @@ public class WebHookManager implements HookManager {
LOGGER.info("handleEvent: object_kind=" + event.getObjectKind());
switch (event.getObjectKind()) {
case BuildEvent.OBJECT_KIND:
case JobEvent.OBJECT_KIND:
case IssueEvent.OBJECT_KIND:
case MergeRequestEvent.OBJECT_KIND:
case NoteEvent.OBJECT_KIND:
......@@ -209,8 +208,8 @@ public class WebHookManager implements HookManager {
public void fireEvent(Event event) throws GitLabApiException {
switch (event.getObjectKind()) {
case BuildEvent.OBJECT_KIND:
fireBuildEvent((BuildEvent) event);
case JobEvent.OBJECT_KIND:
fireJobEvent((JobEvent) event);
break;
case IssueEvent.OBJECT_KIND:
......@@ -248,9 +247,9 @@ public class WebHookManager implements HookManager {
}
}
protected void fireBuildEvent(BuildEvent buildEvent) {
protected void fireJobEvent(JobEvent jobEvent) {
for (WebHookListener listener : webhookListeners) {
listener.onBuildEvent(buildEvent);
listener.onJobEvent(jobEvent);
}
}
......
......@@ -23,9 +23,9 @@ import org.gitlab4j.api.systemhooks.SystemHookListener;
import org.gitlab4j.api.systemhooks.SystemHookManager;
import org.gitlab4j.api.systemhooks.TeamMemberSystemHookEvent;
import org.gitlab4j.api.utils.JacksonJson;
import org.gitlab4j.api.webhook.BuildEvent;
import org.gitlab4j.api.webhook.Event;
import org.gitlab4j.api.webhook.IssueEvent;
import org.gitlab4j.api.webhook.JobEvent;
import org.gitlab4j.api.webhook.MergeRequestEvent;
import org.gitlab4j.api.webhook.NoteEvent;
import org.gitlab4j.api.webhook.PipelineEvent;
......@@ -77,7 +77,6 @@ public class TestGitLabApiEvents {
@Test
public void testPipelineEvent() throws Exception {
Event event = unmarshalResource(PipelineEvent.class, "pipeline-event.json");
assertTrue(compareJson(event, "pipeline-event.json"));
}
......@@ -125,10 +124,10 @@ public class TestGitLabApiEvents {
}
@Test
public void testBuildEvent() throws Exception {
public void testJobEvent() throws Exception {
Event event = unmarshalResource(BuildEvent.class, "build-event.json");
assertTrue(compareJson(event, "build-event.json"));
Event event = unmarshalResource(JobEvent.class, "job-event.json");
assertTrue(compareJson(event, "job-event.json"));
}
@Test
......@@ -141,8 +140,8 @@ public class TestGitLabApiEvents {
@Test
public void testPolymorphicEvent() throws Exception {
Event event = unmarshalResource(Event.class, "build-event.json");
assertTrue(compareJson(event, "build-event.json"));
Event event = unmarshalResource(Event.class, "job-event.json");
assertTrue(compareJson(event, "job-event.json"));
event = unmarshalResource(Event.class, "issue-event.json");
assertTrue(compareJson(event, "issue-event.json"));
......
{
"object_kind": "job",
"ref": "gitlab-script-trigger",
"tag": false,
"before_sha": "2293ada6b400935a1378653304eaf6221e0fdb8f",
"sha": "2293ada6b400935a1378653304eaf6221e0fdb8f",
"job_id": 1977,
"job_name": "test",
"job_stage": "test",
"job_status": "created",
"job_allow_failure": false,
"job_failure_reason": "script_failure",
"project_id": 380,
"project_name": "gitlab-org/gitlab-test",
"user": {
"id": 3,
"name": "User",
"email": "user@gitlab.com"
},
"commit": {
"id": 2366,
"sha": "2293ada6b400935a1378653304eaf6221e0fdb8f",
"message": "test\n",
"author_name": "User",
"author_email": "user@gitlab.com",
"status": "created"
},
"repository": {
"name": "gitlab_test",
"description": "Atque in sunt eos similique dolores voluptatem.",
"homepage": "http://192.168.64.1:3005/gitlab-org/gitlab-test",
"git_ssh_url": "git@192.168.64.1:gitlab-org/gitlab-test.git",
"git_http_url": "http://192.168.64.1:3005/gitlab-org/gitlab-test.git",
"visibility_level": 20
}
}
\ No newline at end of file
......@@ -14,7 +14,13 @@
],
"created_at": "2016-08-12T15:23:28Z",
"finished_at": "2016-08-12T15:26:29Z",
"duration": 63
"duration": 63,
"variables": [
{
"key": "NESTOR_PROD_ENVIRONMENT",
"value": "us-west-1"
}
]
},
"user":{
"name": "Administrator",
......@@ -22,6 +28,7 @@
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon"
},
"project":{
"id": 1,
"name": "Gitlab Test",
"description": "Atque in sunt eos similique dolores voluptatem.",
"web_url": "http://192.168.64.1:3005/gitlab-org/gitlab-test",
......@@ -42,7 +49,7 @@
"email": "user@gitlab.com"
}
},
"builds":[
"jobs":[
{
"id": 380,
"stage": "deploy",
......@@ -73,6 +80,12 @@
"username": "root",
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon"
},
"runner": {
"id":380987,
"description":"shared-runners-manager-6.gitlab.com",
"active":true,
"is_shared":true
},
"artifacts_file":{
}
},
......@@ -91,6 +104,12 @@
"username": "root",
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon"
},
"runner": {
"id":380987,
"description":"shared-runners-manager-6.gitlab.com",
"active":true,
"is_shared":true
},
"artifacts_file":{
}
},
......@@ -109,6 +128,12 @@
"username": "root",
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon"
},
"runner": {
"id":380987,
"description":"shared-runners-manager-6.gitlab.com",
"active":true,
"is_shared":true
},
"artifacts_file":{
}
},
......
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