11package org .gitlab4j .api ;
22
3- import javax .ws .rs .core .Form ;
4- import javax .ws .rs .core .Response ;
5-
63import org .gitlab4j .api .GitLabApi .ApiVersion ;
4+ import org .gitlab4j .api .services .ExternalWikiService ;
75import org .gitlab4j .api .services .HipChatService ;
86import org .gitlab4j .api .services .JiraService ;
97import org .gitlab4j .api .services .SlackService ;
108
9+ import javax .ws .rs .core .Form ;
10+ import javax .ws .rs .core .Response ;
11+
1112/**
1213 * Access for the services API. Currently only the gitlab-ci, HipChatService, Slack, and JIRA service are supported.
1314 * See <a href="https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/services.md">GitLab documentation</a> for more info.
@@ -20,11 +21,12 @@ public ServicesApi(GitLabApi gitLabApi) {
2021
2122 /**
2223 * Activates the gitlab-ci service for a project.
23- *
24+ * <p>
2425 * PUT /projects/:id/services/gitlab-ci
26+ *
2527 * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
26- * @param token for authentication
27- * @param projectCIUrl URL of the GitLab-CI project
28+ * @param token for authentication
29+ * @param projectCIUrl URL of the GitLab-CI project
2830 * @throws GitLabApiException if any exception occurs
2931 * @deprecated No longer supported
3032 */
@@ -37,7 +39,7 @@ public void setGitLabCI(Object projectIdOrPath, String token, String projectCIUr
3739
3840 /**
3941 * Deletes the gitlab-ci service for a project.
40- *
42+ * <p>
4143 * DELETE /projects/:id/services/gitlab-ci
4244 *
4345 * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
@@ -51,7 +53,7 @@ public void deleteGitLabCI(Object projectIdOrPath) throws GitLabApiException {
5153
5254 /**
5355 * Get the HipChatService notification configuration for a project.
54- *
56+ * <p>
5557 * Get /projects/:id/services/hipchat
5658 *
5759 * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
@@ -60,16 +62,16 @@ public void deleteGitLabCI(Object projectIdOrPath) throws GitLabApiException {
6062 */
6163 public HipChatService getHipChatService (Object projectIdOrPath ) throws GitLabApiException {
6264 Response response = get (Response .Status .OK , null , "projects" , getProjectIdOrPath (projectIdOrPath ), "services" , "hipchat" );
63- return (response .readEntity (HipChatService .class ));
65+ return (response .readEntity (HipChatService .class ));
6466 }
65-
67+
6668 /**
6769 * Updates the HipChatService notification settings for a project.
68- *
70+ * <p>
6971 * PUT /projects/:id/services/hipchat
70- *
72+ * <p>
7173 * The following properties on the HipChatService instance are utilized in the update of the settings:
72- *
74+ * <p>
7375 * pushEvents (optional) - Enable notifications for push events
7476 * issuesEvents (optional) - Enable notifications for issue events
7577 * confidentialIssuesEvents (optional) - Enable notifications for confidential issue events
@@ -87,7 +89,7 @@ public HipChatService getHipChatService(Object projectIdOrPath) throws GitLabApi
8789 * notifyOnlyBrokenPipelines (optional) - Send notifications for broken pipelines
8890 *
8991 * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
90- * @param hipChat the HipChatService instance holding the settings
92+ * @param hipChat the HipChatService instance holding the settings
9193 * @return a HipChatService instance holding the newly updated settings
9294 * @throws GitLabApiException if any exception occurs
9395 */
@@ -114,13 +116,13 @@ public HipChatService updateHipChatService(Object projectIdOrPath, HipChatServic
114116
115117 /**
116118 * Activates HipChatService notifications.
117- *
119+ * <p>
118120 * PUT /projects/:id/services/hipchat
119121 *
120122 * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
121- * @param token for authentication
122- * @param room HipChatService Room
123- * @param server HipChatService Server URL
123+ * @param token for authentication
124+ * @param room HipChatService Room
125+ * @param server HipChatService Server URL
124126 * @throws GitLabApiException if any exception occurs
125127 * @deprecated replaced with {@link #updateHipChatService(Object, HipChatService) updateHipChat} method
126128 */
@@ -134,7 +136,7 @@ public void setHipChat(Object projectIdOrPath, String token, String room, String
134136
135137 /**
136138 * Deletes the HipChatService service for a project.
137- *
139+ * <p>
138140 * DELETE /projects/:id/services/hipchat
139141 *
140142 * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
@@ -147,7 +149,7 @@ public void deleteHipChat(Object projectIdOrPath) throws GitLabApiException {
147149
148150 /**
149151 * Deletes the HipChatService service for a project.
150- *
152+ * <p>
151153 * DELETE /projects/:id/services/hipchat
152154 *
153155 * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
@@ -160,7 +162,7 @@ public void deleteHipChatService(Object projectIdOrPath) throws GitLabApiExcepti
160162
161163 /**
162164 * Get the Slack notification settings for a project.
163- *
165+ * <p>
164166 * Get /projects/:id/services/slack
165167 *
166168 * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
@@ -169,16 +171,16 @@ public void deleteHipChatService(Object projectIdOrPath) throws GitLabApiExcepti
169171 */
170172 public SlackService getSlackService (Object projectIdOrPath ) throws GitLabApiException {
171173 Response response = get (Response .Status .OK , null , "projects" , getProjectIdOrPath (projectIdOrPath ), "services" , "slack" );
172- return (response .readEntity (SlackService .class ));
174+ return (response .readEntity (SlackService .class ));
173175 }
174176
175177 /**
176178 * Updates the Slack notification settings for a project.
177- *
179+ * <p>
178180 * PUT /projects/:id/services/slack
179- *
181+ * <p>
180182 * The following properties on the SlackService instance are utilized in the update of the settings:
181- *
183+ * <p>
182184 * webhook (required) - https://hooks.slack.com/services/...
183185 * username (optional) - username
184186 * defaultChannel (optional) - Default channel to use if others are not configured
@@ -203,7 +205,7 @@ public SlackService getSlackService(Object projectIdOrPath) throws GitLabApiExce
203205 * pipelineChannel (optional) - The name of the channel to receive pipeline events notifications
204206 * wikiPageChannel (optional) - The name of the channel to receive wiki page events notifications
205207 *
206- * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
208+ * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
207209 * @param slackNotifications the SlackService instance holding the settings
208210 * @return a SlackService instance holding the newly updated settings
209211 * @throws GitLabApiException if any exception occurs
@@ -212,7 +214,7 @@ public SlackService updateSlackService(Object projectIdOrPath, SlackService slac
212214 GitLabApiForm formData = new GitLabApiForm ()
213215 .withParam ("webhook" , slackNotifications .getWebhook (), true )
214216 .withParam ("username" , slackNotifications .getUsername ())
215- .withParam ("channel" , slackNotifications .getDefaultChannel ())
217+ .withParam ("channel" , slackNotifications .getDefaultChannel ())
216218 .withParam ("notify_only_broken_pipelines" , slackNotifications .getNotifyOnlyBrokenPipelines ())
217219 .withParam ("notify_only_default_branch" , slackNotifications .getNotifyOnlyDefaultBranch ())
218220 .withParam ("push_events" , slackNotifications .getPushEvents ())
@@ -239,7 +241,7 @@ public SlackService updateSlackService(Object projectIdOrPath, SlackService slac
239241
240242 /**
241243 * Deletes the Slack notifications service for a project.
242- *
244+ * <p>
243245 * DELETE /projects/:id/services/slack
244246 *
245247 * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
@@ -249,10 +251,10 @@ public void deleteSlackService(Object projectIdOrPath) throws GitLabApiException
249251 Response .Status expectedStatus = (isApiVersion (ApiVersion .V3 ) ? Response .Status .OK : Response .Status .NO_CONTENT );
250252 delete (expectedStatus , null , "projects" , getProjectIdOrPath (projectIdOrPath ), "services" , "slack" );
251253 }
252-
254+
253255 /**
254256 * Get the JIRA service settings for a project.
255- *
257+ * <p>
256258 * Get /projects/:id/services/jira
257259 *
258260 * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
@@ -261,16 +263,16 @@ public void deleteSlackService(Object projectIdOrPath) throws GitLabApiException
261263 */
262264 public JiraService getJiraService (Object projectIdOrPath ) throws GitLabApiException {
263265 Response response = get (Response .Status .OK , null , "projects" , getProjectIdOrPath (projectIdOrPath ), "services" , "jira" );
264- return (response .readEntity (JiraService .class ));
266+ return (response .readEntity (JiraService .class ));
265267 }
266268
267269 /**
268270 * Updates the JIRA service settings for a project.
269- *
271+ * <p>
270272 * PUT /projects/:id/services/jira
271- *
273+ * <p>
272274 * The following properties on the JiraService instance are utilized in the update of the settings:
273- *
275+ * <p>
274276 * mergeRequestsEvents (optional) - Enable notifications for merge request events
275277 * commitEvents (optional) - Enable notifications for commit events
276278 * url (required) - The URL to the JIRA project which is being linked to this GitLab project, e.g., https://jira.example.com.
@@ -281,7 +283,7 @@ public JiraService getJiraService(Object projectIdOrPath) throws GitLabApiExcept
281283 * jiraIssueTransitionId (optional) - The ID of a transition that moves issues to a closed state.
282284 *
283285 * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
284- * @param jira the JiraService instance holding the settings
286+ * @param jira the JiraService instance holding the settings
285287 * @return a JiraService instance holding the newly updated settings
286288 * @throws GitLabApiException if any exception occurs
287289 */
@@ -293,15 +295,18 @@ public JiraService updateJiraService(Object projectIdOrPath, JiraService jira) t
293295 .withParam ("api_url" , jira .getApiUrl ())
294296 .withParam ("project_key" , jira .getProjectKey ())
295297 .withParam ("username" , jira .getUsername (), true )
296- .withParam ("password" , jira .getPassword (), true )
298+ .withParam ("password" , jira .getPassword (), true )
297299 .withParam ("jira_issue_transition_id" , jira .getJiraIssueTransitionId ());
298300 Response response = put (Response .Status .OK , formData .asMap (), "projects" , getProjectIdOrPath (projectIdOrPath ), "services" , "jira" );
299301 return (response .readEntity (JiraService .class ));
300302 }
301303
304+
305+
306+
302307 /**
303308 * Deletes the JIRA service for a project.
304- *
309+ * <p>
305310 * DELETE /projects/:id/services/jira
306311 *
307312 * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
@@ -311,4 +316,55 @@ public void deleteJiraService(Object projectIdOrPath) throws GitLabApiException
311316 Response .Status expectedStatus = (isApiVersion (ApiVersion .V3 ) ? Response .Status .OK : Response .Status .NO_CONTENT );
312317 delete (expectedStatus , null , "projects" , getProjectIdOrPath (projectIdOrPath ), "services" , "jira" );
313318 }
319+
320+
321+ /**
322+ * Get the JIRA service settings for a project.
323+ * <p>
324+ * Get /projects/:id/services/external-wiki
325+ *
326+ * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
327+ * @return a ExternalWikiService instance holding the External Wiki service settings
328+ * @throws GitLabApiException if any exception occurs
329+ */
330+ public ExternalWikiService getExternalWikiService (Object projectIdOrPath ) throws GitLabApiException {
331+ Response response = this .get (Response .Status .OK , null , "projects" , getProjectIdOrPath (projectIdOrPath ), "services" , "external-wiki" );
332+ return (response .readEntity (ExternalWikiService .class ));
333+ }
334+
335+
336+ /**
337+ * Updates the ExternalWikiService service settings for a project.
338+ * <p>
339+ * PUT /projects/:id/services/external-wiki
340+ * <p>
341+ * The following properties on the JiraService instance are utilized in the update of the settings:
342+ * <p>
343+ * external_wiki_url (required) - The URL to the External Wiki project which is being linked to this GitLab project, e.g., http://www.wikidot.com/
344+ *
345+ * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
346+ * @param externalWiki the ExternalWikiService instance holding the settings
347+ * @return a ExternalWikiService instance holding the newly updated settings
348+ * @throws GitLabApiException if any exception occurs
349+ */
350+ public ExternalWikiService updateExternalWikiService (Object projectIdOrPath , ExternalWikiService externalWiki ) throws GitLabApiException {
351+ GitLabApiForm formData = new GitLabApiForm ()
352+ .withParam ("external_wiki_url" , externalWiki .getExternalWikiUrl ());
353+ Response response = put (Response .Status .OK , formData .asMap (), "projects" , getProjectIdOrPath (projectIdOrPath ), "services" , "external-wiki" );
354+ return (response .readEntity (ExternalWikiService .class ));
355+ }
356+
357+ /**
358+ * Deletes the ExternalWiki service for a project.
359+ * <p>
360+ * DELETE /projects/:id/services/external-wiki
361+ *
362+ * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
363+ * @throws GitLabApiException if any exception occurs
364+ */
365+ public void deleteExternalWikiService (Object projectIdOrPath ) throws GitLabApiException {
366+ Response .Status expectedStatus = (isApiVersion (ApiVersion .V3 ) ? Response .Status .OK : Response .Status .NO_CONTENT );
367+ delete (expectedStatus , null , "projects" , getProjectIdOrPath (projectIdOrPath ), "services" , "external-wiki" );
368+
369+ }
314370}
0 commit comments