diff --git a/gitlab4j-api/src/main/java/org/gitlab4j/api/SystemHooksApi.java b/gitlab4j-api/src/main/java/org/gitlab4j/api/SystemHooksApi.java index f82c34baa..539b6e303 100644 --- a/gitlab4j-api/src/main/java/org/gitlab4j/api/SystemHooksApi.java +++ b/gitlab4j-api/src/main/java/org/gitlab4j/api/SystemHooksApi.java @@ -23,7 +23,7 @@ public SystemHooksApi(GitLabApi gitLabApi) { * *
GitLab Endpoint: GET /hooks
*
- * @return a list of SystemHookEvent
+ * @return a list of SystemHook
* @throws GitLabApiException if any exception occurs
*/
public ListGitLab Endpoint: GET /hooks
*
- * @param itemsPerPage the number of SystemHookEvent instances that will be fetched per page
- * @return a Pager of SystemHookEvent
+ * @param itemsPerPage the number of SystemHook instances that will be fetched per page
+ * @return a Pager of SystemHook
* @throws GitLabApiException if any exception occurs
*/
public PagerGitLab Endpoint: GET /hooks
*
- * @return a Stream of SystemHookEvent
+ * @return a Stream of SystemHook
* @throws GitLabApiException if any exception occurs
*/
public StreamGitLab Endpoint: GET /hooks
+ *
+ * @param hookId the ID of the system hook.
+ * @return the SystemHook
+ * @throws GitLabApiException if any exception occurs
+ */
+ public SystemHook getSystemHook(Long hookId) throws GitLabApiException {
+ Response response = get(Response.Status.OK, null, "hooks", hookId);
+ return response.readEntity(SystemHook.class);
+ }
+
/**
* Add a new system hook. This method requires admin access.
*
@@ -81,7 +95,7 @@ public StreamGitLab 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