From 94db1a71a16d1afd02711901644337cca75b503d Mon Sep 17 00:00:00 2001 From: Greg Messner Date: Fri, 17 May 2019 12:07:18 -0700 Subject: [PATCH] Needed to support actual Job Hook event (docs at GitLab are wrong) (#357). --- .../org/gitlab4j/api/webhook/BuildCommit.java | 104 ++++++++++ .../org/gitlab4j/api/webhook/BuildEvent.java | 193 ++++++++++++++++++ .../org/gitlab4j/api/build-event.json | 40 ++++ 3 files changed, 337 insertions(+) create mode 100644 src/main/java/org/gitlab4j/api/webhook/BuildCommit.java create mode 100644 src/main/java/org/gitlab4j/api/webhook/BuildEvent.java create mode 100644 src/test/resources/org/gitlab4j/api/build-event.json diff --git a/src/main/java/org/gitlab4j/api/webhook/BuildCommit.java b/src/main/java/org/gitlab4j/api/webhook/BuildCommit.java new file mode 100644 index 00000000..40abbdb6 --- /dev/null +++ b/src/main/java/org/gitlab4j/api/webhook/BuildCommit.java @@ -0,0 +1,104 @@ +package org.gitlab4j.api.webhook; + +import java.util.Date; + +import org.gitlab4j.api.utils.JacksonJson; + +public class BuildCommit { + + private Integer id; + private String sha; + private String message; + private String authorName; + private String authorEmail; + private String authorUrl; + private String status; + private Float 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 getAuthorUrl() { + return authorUrl; + } + + public void setAuthorUrl(String authorUrl) { + this.authorUrl = authorUrl; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public Float getDuration() { + return duration; + } + + public void setDuration(Float 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)); + } +} \ No newline at end of file diff --git a/src/main/java/org/gitlab4j/api/webhook/BuildEvent.java b/src/main/java/org/gitlab4j/api/webhook/BuildEvent.java new file mode 100644 index 00000000..fe61b03d --- /dev/null +++ b/src/main/java/org/gitlab4j/api/webhook/BuildEvent.java @@ -0,0 +1,193 @@ +package org.gitlab4j.api.webhook; + +import java.util.Date; + +import org.gitlab4j.api.models.User; +import org.gitlab4j.api.utils.JacksonJson; + +/** + * The documentation at: + * Job Events is incorrect, this class represents the actual content of the Job Hook event. + */ +public class BuildEvent extends AbstractEvent { + + public static final String JOB_HOOK_X_GITLAB_EVENT = "Job Hook"; + public static final String OBJECT_KIND = "build"; + + private String ref; + private Boolean tag; + private String beforeSha; + private String sha; + private Integer buildId; + private String buildName; + private String buildStage; + private String buildStatus; + private Date buildStarted_at; + private Date buildFinished_at; + private Float buildDuration; + private Boolean buildAllowFailure; + private String buildFailureReason; + private Integer projectId; + private String projectName; + private User user; + private BuildCommit 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 getBuildId() { + return buildId; + } + + public void setBuildId(Integer buildId) { + this.buildId = buildId; + } + + public String getBuildName() { + return buildName; + } + + public void setBuildName(String buildName) { + this.buildName = buildName; + } + + public String getBuildStage() { + return buildStage; + } + + public void setBuildStage(String buildStage) { + this.buildStage = buildStage; + } + + public String getBuildStatus() { + return buildStatus; + } + + public void setBuildStatus(String buildStatus) { + this.buildStatus = buildStatus; + } + + public Date getBuildStarted_at() { + return buildStarted_at; + } + + public void setBuildStarted_at(Date buildStarted_at) { + this.buildStarted_at = buildStarted_at; + } + + public Date getBuildFinished_at() { + return buildFinished_at; + } + + public void setBuildFinished_at(Date buildFinished_at) { + this.buildFinished_at = buildFinished_at; + } + + public Float getBuildDuration() { + return buildDuration; + } + + public void setBuildDuration(Float buildDuration) { + this.buildDuration = buildDuration; + } + + public Boolean getBuildAllowFailure() { + return buildAllowFailure; + } + + public void setBuildAllowFailure(Boolean buildAllowFailure) { + this.buildAllowFailure = buildAllowFailure; + } + + public String getBuildFailureReason() { + return buildFailureReason; + } + + public void setBuildFailureReason(String buildFailureReason) { + this.buildFailureReason = buildFailureReason; + } + + 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 BuildCommit getCommit() { + return commit; + } + + public void setCommit(BuildCommit commit) { + this.commit = commit; + } + + public EventRepository getRepository() { + return repository; + } + + public void setRepository(EventRepository repository) { + this.repository = repository; + } + + @Override + public String toString() { + return (JacksonJson.toJsonString(this)); + } +} diff --git a/src/test/resources/org/gitlab4j/api/build-event.json b/src/test/resources/org/gitlab4j/api/build-event.json new file mode 100644 index 00000000..ad431fa4 --- /dev/null +++ b/src/test/resources/org/gitlab4j/api/build-event.json @@ -0,0 +1,40 @@ +{ + "object_kind": "build", + "ref": "master", + "tag": false, + "before_sha": "8a49a94f1a7cd64985074cb11b1a42a7ab2d9b46", + "sha": "a890bee24574603c522c756b9346649fbec4c812", + "build_id": 214655258, + "build_name": "build1", + "build_stage": "build", + "build_status": "running", + "build_started_at": "2019-05-17T18:09:21Z", + "build_duration": 0.05880817, + "build_allow_failure": false, + "build_failure_reason": "unknown_failure", + "project_id": 3115610, + "project_name": "GitLab4J / test-project", + "user": { + "id": 20493, + "name": "GitLab4J Tester", + "email": "gitlab4j@gitlab4j.org" + }, + "commit": { + "id": 61897408, + "sha": "a890bee24574603c522c756b9346649fbec4c812", + "message": "Add new file", + "author_name": "GitLab4J Tester", + "author_email": "gitlab4j@gitlab4j.org", + "author_url": "https://gitlab.com/gitlab4j", + "status": "pending" + }, + "repository": { + "name": "test-project", + "url": "git@gitlab.com:gitlab4j/test-project.git", + "description": "This is a test project to be used for testing the GitLab4J-API", + "homepage": "https://gitlab.com/gitlab4j/test-project", + "git_http_url": "https://gitlab.com/gitlab4j/test-project.git", + "git_ssh_url": "git@gitlab.com:gitlab4j/test-project.git", + "visibility_level": 20 + } +} \ No newline at end of file -- GitLab