Skip to content

Commit b7de09c

Browse files
committed
System hook improvements
1 parent 398d357 commit b7de09c

File tree

2 files changed

+57
-8
lines changed

2 files changed

+57
-8
lines changed

gitlab4j-api/src/main/java/org/gitlab4j/api/SystemHooksApi.java

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public SystemHooksApi(GitLabApi gitLabApi) {
2323
*
2424
* <pre><code>GitLab Endpoint: GET /hooks</code></pre>
2525
*
26-
* @return a list of SystemHookEvent
26+
* @return a list of SystemHook
2727
* @throws GitLabApiException if any exception occurs
2828
*/
2929
public List<SystemHook> getSystemHooks() throws GitLabApiException {
@@ -38,7 +38,7 @@ public List<SystemHook> getSystemHooks() throws GitLabApiException {
3838
*
3939
* @param page the page to get
4040
* @param perPage the number of deploy keys per page
41-
* @return the list of SystemHookEvent in the specified range
41+
* @return the list of SystemHook in the specified range
4242
* @throws GitLabApiException if any exception occurs
4343
*/
4444
public List<SystemHook> getSystemHooks(int page, int perPage) throws GitLabApiException {
@@ -51,8 +51,8 @@ public List<SystemHook> getSystemHooks(int page, int perPage) throws GitLabApiEx
5151
*
5252
* <pre><code>GitLab Endpoint: GET /hooks</code></pre>
5353
*
54-
* @param itemsPerPage the number of SystemHookEvent instances that will be fetched per page
55-
* @return a Pager of SystemHookEvent
54+
* @param itemsPerPage the number of SystemHook instances that will be fetched per page
55+
* @return a Pager of SystemHook
5656
* @throws GitLabApiException if any exception occurs
5757
*/
5858
public Pager<SystemHook> getSystemHooks(int itemsPerPage) throws GitLabApiException {
@@ -64,13 +64,27 @@ public Pager<SystemHook> getSystemHooks(int itemsPerPage) throws GitLabApiExcept
6464
*
6565
* <pre><code>GitLab Endpoint: GET /hooks</code></pre>
6666
*
67-
* @return a Stream of SystemHookEvent
67+
* @return a Stream of SystemHook
6868
* @throws GitLabApiException if any exception occurs
6969
*/
7070
public Stream<SystemHook> getSystemHookStream() throws GitLabApiException {
7171
return (getSystemHooks(getDefaultPerPage()).stream());
7272
}
7373

74+
/**
75+
* Get a list of all system hooks. This method requires admin access.
76+
*
77+
* <pre><code>GitLab Endpoint: GET /hooks</code></pre>
78+
*
79+
* @param hookId the ID of the system hook.
80+
* @return the SystemHook
81+
* @throws GitLabApiException if any exception occurs
82+
*/
83+
public SystemHook getSystemHook(Long hookId) throws GitLabApiException {
84+
Response response = get(Response.Status.OK, null, "hooks", hookId);
85+
return response.readEntity(SystemHook.class);
86+
}
87+
7488
/**
7589
* Add a new system hook. This method requires admin access.
7690
*
@@ -81,7 +95,7 @@ public Stream<SystemHook> getSystemHookStream() throws GitLabApiException {
8195
* @param pushEvents when true, the hook will fire on push events, optional
8296
* @param tagPushEvents when true, the hook will fire on new tags being pushed, optional
8397
* @param enableSslVerification do SSL verification when triggering the hook, optional
84-
* @return an SystemHookEvent instance with info on the added system hook
98+
* @return an SystemHook instance with info on the added system hook
8599
* @throws GitLabApiException if any exception occurs
86100
*/
87101
public SystemHook addSystemHook(
@@ -104,7 +118,7 @@ public SystemHook addSystemHook(
104118
* @param url the hook URL, required
105119
* @param token secret token to validate received payloads, optional
106120
* @param systemHook the systemHook to create
107-
* @return an SystemHookEvent instance with info on the added system hook
121+
* @return an SystemHook instance with info on the added system hook
108122
* @throws GitLabApiException if any exception occurs
109123
*/
110124
public SystemHook addSystemHook(String url, String token, SystemHook systemHook) throws GitLabApiException {
@@ -116,6 +130,8 @@ public SystemHook addSystemHook(String url, String token, SystemHook systemHook)
116130
GitLabApiForm formData = new GitLabApiForm()
117131
.withParam("url", url, true)
118132
.withParam("token", token)
133+
.withParam("name", systemHook.getName())
134+
.withParam("description", systemHook.getDescription())
119135
.withParam("push_events", systemHook.getPushEvents())
120136
.withParam("tag_push_events", systemHook.getTagPushEvents())
121137
.withParam("merge_requests_events", systemHook.getMergeRequestsEvents())
@@ -166,7 +182,7 @@ public void deleteSystemHook(Long hookId) throws GitLabApiException {
166182
*
167183
* <pre><code>GitLab Endpoint: GET /hooks/:hook_id</code></pre>
168184
*
169-
* @param hook the SystemHookEvent instance to test
185+
* @param hook the SystemHook instance to test
170186
* @throws GitLabApiException if any exception occurs
171187
*/
172188
public void testSystemHook(SystemHook hook) throws GitLabApiException {
@@ -194,4 +210,19 @@ public void testSystemHook(Long hookId) throws GitLabApiException {
194210

195211
get(Response.Status.OK, null, "hooks", hookId);
196212
}
213+
214+
/**
215+
* Add a new system hook. This method requires admin access.
216+
*
217+
* <pre><code>GitLab Endpoint: PUT /hooks/:hook_id/url_variables/:key</code></pre>
218+
*
219+
* @param hookId the ID of the system hook
220+
* @param key Key of the URL variable
221+
* @param value Value of the URL variable.
222+
* @throws GitLabApiException if any exception occurs
223+
*/
224+
public void addSystemHookUrlVariable(Long hookId, String key, String value) throws GitLabApiException {
225+
GitLabApiForm formData = new GitLabApiForm().withParam("value", value, true);
226+
put(Response.Status.CREATED, formData, "hooks", hookId, "url_variables", key);
227+
}
197228
}

gitlab4j-models/src/main/java/org/gitlab4j/api/models/SystemHook.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public class SystemHook implements Serializable {
99
private static final long serialVersionUID = 1L;
1010

1111
private Long id;
12+
private String name;
13+
private String description;
1214
private String url;
1315
private Date createdAt;
1416
private Boolean pushEvents;
@@ -25,6 +27,22 @@ public void setId(Long id) {
2527
this.id = id;
2628
}
2729

30+
public String getName() {
31+
return name;
32+
}
33+
34+
public void setName(String name) {
35+
this.name = name;
36+
}
37+
38+
public String getDescription() {
39+
return description;
40+
}
41+
42+
public void setDescription(String description) {
43+
this.description = description;
44+
}
45+
2846
public String getUrl() {
2947
return url;
3048
}

0 commit comments

Comments
 (0)