getSystemHookStream() throws GitLabApiException {
* @param pushEvents when true, the hook will fire on push events, optional
* @param tagPushEvents when true, the hook will fire on new tags being pushed, optional
* @param enableSslVerification do SSL verification when triggering the hook, optional
- * @return an SystemHookEvent instance with info on the added system hook
+ * @return an SystemHook instance with info on the added system hook
* @throws GitLabApiException if any exception occurs
*/
public SystemHook addSystemHook(
@@ -104,7 +118,7 @@ public SystemHook addSystemHook(
* @param url the hook URL, required
* @param token secret token to validate received payloads, optional
* @param systemHook the systemHook to create
- * @return an SystemHookEvent instance with info on the added system hook
+ * @return an SystemHook instance with info on the added system hook
* @throws GitLabApiException if any exception occurs
*/
public SystemHook addSystemHook(String url, String token, SystemHook systemHook) throws GitLabApiException {
@@ -116,6 +130,8 @@ public SystemHook addSystemHook(String url, String token, SystemHook systemHook)
GitLabApiForm formData = new GitLabApiForm()
.withParam("url", url, true)
.withParam("token", token)
+ .withParam("name", systemHook.getName())
+ .withParam("description", systemHook.getDescription())
.withParam("push_events", systemHook.getPushEvents())
.withParam("tag_push_events", systemHook.getTagPushEvents())
.withParam("merge_requests_events", systemHook.getMergeRequestsEvents())
@@ -125,6 +141,36 @@ public SystemHook addSystemHook(String url, String token, SystemHook systemHook)
return (response.readEntity(SystemHook.class));
}
+ /**
+ * Add a new system hook. This method requires admin access.
+ *
+ * GitLab Endpoint: PUT /hooks/:hook_id
+ *
+ * @param systemHook the systemHook to update
+ * @param token secret token to validate received payloads, optional
+ * @return an SystemHook instance with info on the added system hook
+ * @throws GitLabApiException if any exception occurs
+ */
+ public SystemHook updateSystemHook(SystemHook systemHook, String token) throws GitLabApiException {
+
+ if (systemHook.getId() == null) {
+ throw new RuntimeException("systemHook id cannot be null");
+ }
+
+ GitLabApiForm formData = new GitLabApiForm()
+ .withParam("url", systemHook.getUrl())
+ .withParam("token", token)
+ .withParam("name", systemHook.getName())
+ .withParam("description", systemHook.getDescription())
+ .withParam("push_events", systemHook.getPushEvents())
+ .withParam("tag_push_events", systemHook.getTagPushEvents())
+ .withParam("merge_requests_events", systemHook.getMergeRequestsEvents())
+ .withParam("repository_update_events", systemHook.getRepositoryUpdateEvents())
+ .withParam("enable_ssl_verification", systemHook.getEnableSslVerification());
+ Response response = putWithFormData(Response.Status.OK, formData, "hooks", systemHook.getId());
+ return (response.readEntity(SystemHook.class));
+ }
+
/**
* Deletes a system hook. This method requires admin access.
*
@@ -166,7 +212,7 @@ public void deleteSystemHook(Long hookId) throws GitLabApiException {
*
* GitLab Endpoint: GET /hooks/:hook_id
*
- * @param hook the SystemHookEvent instance to test
+ * @param hook the SystemHook instance to test
* @throws GitLabApiException if any exception occurs
*/
public void testSystemHook(SystemHook hook) throws GitLabApiException {
@@ -194,4 +240,32 @@ public void testSystemHook(Long hookId) throws GitLabApiException {
get(Response.Status.OK, null, "hooks", hookId);
}
+
+ /**
+ * Add a new URL variable.
+ *
+ * GitLab Endpoint: PUT /hooks/:hook_id/url_variables/:key
+ *
+ * @param hookId the ID of the system hook
+ * @param key Key of the URL variable
+ * @param value Value of the URL variable.
+ * @throws GitLabApiException if any exception occurs
+ */
+ public void addSystemHookUrlVariable(Long hookId, String key, String value) throws GitLabApiException {
+ GitLabApiForm formData = new GitLabApiForm().withParam("value", value, true);
+ put(Response.Status.CREATED, formData.asMap(), "hooks", hookId, "url_variables", key);
+ }
+
+ /**
+ * Delete a URL variable.
+ *
+ * GitLab Endpoint: DELETE /hooks/:hook_id/url_variables/:key
+ *
+ * @param hookId the ID of the system hook
+ * @param key Key of the URL variable
+ * @throws GitLabApiException if any exception occurs
+ */
+ public void deleteSystemHookUrlVariable(Long hookId, String key) throws GitLabApiException {
+ delete(Response.Status.NO_CONTENT, null, "hooks", hookId, "url_variables", key);
+ }
}
diff --git a/gitlab4j-models/src/main/java/org/gitlab4j/api/models/SystemHook.java b/gitlab4j-models/src/main/java/org/gitlab4j/api/models/SystemHook.java
index c04e51054..8b2baa186 100644
--- a/gitlab4j-models/src/main/java/org/gitlab4j/api/models/SystemHook.java
+++ b/gitlab4j-models/src/main/java/org/gitlab4j/api/models/SystemHook.java
@@ -2,6 +2,7 @@
import java.io.Serializable;
import java.util.Date;
+import java.util.List;
import org.gitlab4j.models.utils.JacksonJson;
@@ -9,6 +10,8 @@ public class SystemHook implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
+ private String name;
+ private String description;
private String url;
private Date createdAt;
private Boolean pushEvents;
@@ -16,6 +19,7 @@ public class SystemHook implements Serializable {
private Boolean enableSslVerification;
private Boolean repositoryUpdateEvents;
private Boolean mergeRequestsEvents;
+ private List urlVariables;
public Long getId() {
return id;
@@ -25,6 +29,22 @@ public void setId(Long id) {
this.id = id;
}
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
public String getUrl() {
return url;
}
@@ -81,48 +101,85 @@ public Boolean getMergeRequestsEvents() {
return mergeRequestsEvents;
}
+ public List getUrlVariables() {
+ return urlVariables;
+ }
+
+ public void setUrlVariables(List urlVariables) {
+ this.urlVariables = urlVariables;
+ }
+
public SystemHook withId(Long id) {
this.id = id;
- return (this);
+ return this;
+ }
+
+ public SystemHook withName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public SystemHook withDescription(String description) {
+ this.description = description;
+ return this;
}
public SystemHook withUrl(String url) {
this.url = url;
- return (this);
+ return this;
}
public SystemHook withCreatedAt(Date createdAt) {
this.createdAt = createdAt;
- return (this);
+ return this;
}
public SystemHook withPushEvents(Boolean pushEvents) {
this.pushEvents = pushEvents;
- return (this);
+ return this;
}
public SystemHook withTagPushEvents(Boolean tagPushEvents) {
this.tagPushEvents = tagPushEvents;
- return (this);
+ return this;
}
public SystemHook withEnableSslVerification(Boolean enableSslVerification) {
this.enableSslVerification = enableSslVerification;
- return (this);
+ return this;
}
public SystemHook withRepositoryUpdateEvents(Boolean repositoryUpdateEvents) {
this.repositoryUpdateEvents = repositoryUpdateEvents;
- return (this);
+ return this;
}
public SystemHook withMergeRequestsEvents(Boolean mergeRequestsEvents) {
this.mergeRequestsEvents = mergeRequestsEvents;
- return (this);
+ return this;
}
@Override
public String toString() {
return (JacksonJson.toJsonString(this));
}
+
+ public static class UrlVariable implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ private String key;
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ @Override
+ public String toString() {
+ return (JacksonJson.toJsonString(this));
+ }
+ }
}
diff --git a/gitlab4j-models/src/test/resources/org/gitlab4j/models/system-hook.json b/gitlab4j-models/src/test/resources/org/gitlab4j/models/system-hook.json
index d1cc6ea9a..5af118b12 100644
--- a/gitlab4j-models/src/test/resources/org/gitlab4j/models/system-hook.json
+++ b/gitlab4j-models/src/test/resources/org/gitlab4j/models/system-hook.json
@@ -1,9 +1,15 @@
{
"id": 1,
"url": "https://gitlab.example.com/hook",
+ "name": "Hook name",
+ "description": "Hook description",
"created_at": "2016-10-31T12:32:15.192Z",
"push_events": true,
"tag_push_events": false,
- "enable_ssl_verification": true
-}
-
+ "merge_requests_events": true,
+ "repository_update_events": true,
+ "enable_ssl_verification": true,
+ "url_variables": [{
+ "key": "example"
+ }]
+}
\ No newline at end of file