Skip to content

Commit c84bea9

Browse files
committed
Added support for BugzillaService and CustomIssueTrackerService (#404).
1 parent 3d87926 commit c84bea9

File tree

2 files changed

+204
-75
lines changed

2 files changed

+204
-75
lines changed

src/main/java/org/gitlab4j/api/ServicesApi.java

Lines changed: 113 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.gitlab4j.api;
22

33
import org.gitlab4j.api.GitLabApi.ApiVersion;
4+
import org.gitlab4j.api.services.BugzillaService;
5+
import org.gitlab4j.api.services.CustomIssueTrackerService;
46
import org.gitlab4j.api.services.ExternalWikiService;
57
import org.gitlab4j.api.services.HipChatService;
68
import org.gitlab4j.api.services.JiraService;
@@ -95,22 +97,7 @@ public HipChatService getHipChatService(Object projectIdOrPath) throws GitLabApi
9597
* @throws GitLabApiException if any exception occurs
9698
*/
9799
public HipChatService updateHipChatService(Object projectIdOrPath, HipChatService hipChat) throws GitLabApiException {
98-
GitLabApiForm formData = new GitLabApiForm()
99-
.withParam("push_events", hipChat.getPushEvents())
100-
.withParam("issues_events", hipChat.getIssuesEvents())
101-
.withParam("confidential_issues_events", hipChat.getConfidentialIssuesEvents())
102-
.withParam("merge_requests_events", hipChat.getMergeRequestsEvents())
103-
.withParam("tag_push_events", hipChat.getTagPushEvents())
104-
.withParam("note_events", hipChat.getNoteEvents())
105-
.withParam("confidential_note_events", hipChat.getConfidentialNoteEvents())
106-
.withParam("pipeline_events", hipChat.getPipelineEvents())
107-
.withParam("token", hipChat.getToken(), true)
108-
.withParam("color", hipChat.getColor())
109-
.withParam("notify", hipChat.getNotify())
110-
.withParam("room", hipChat.getRoom())
111-
.withParam("api_version", hipChat.getApiVersion())
112-
.withParam("server", hipChat.getServer())
113-
.withParam("notify_only_broken_pipelines", hipChat.getNotifyOnlyBrokenPipelines());
100+
GitLabApiForm formData = hipChat.servicePropertiesForm();
114101
Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "services", "hipchat");
115102
return (response.readEntity(HipChatService.class));
116103
}
@@ -212,30 +199,7 @@ public SlackService getSlackService(Object projectIdOrPath) throws GitLabApiExce
212199
* @throws GitLabApiException if any exception occurs
213200
*/
214201
public SlackService updateSlackService(Object projectIdOrPath, SlackService slackNotifications) throws GitLabApiException {
215-
GitLabApiForm formData = new GitLabApiForm()
216-
.withParam("webhook", slackNotifications.getWebhook(), true)
217-
.withParam("username", slackNotifications.getUsername())
218-
.withParam("channel", slackNotifications.getDefaultChannel())
219-
.withParam("notify_only_broken_pipelines", slackNotifications.getNotifyOnlyBrokenPipelines())
220-
.withParam("notify_only_default_branch", slackNotifications.getNotifyOnlyDefaultBranch())
221-
.withParam("push_events", slackNotifications.getPushEvents())
222-
.withParam("issues_events", slackNotifications.getIssuesEvents())
223-
.withParam("confidential_issues_events", slackNotifications.getConfidentialIssuesEvents())
224-
.withParam("merge_requests_events", slackNotifications.getMergeRequestsEvents())
225-
.withParam("tag_push_events", slackNotifications.getTagPushEvents())
226-
.withParam("note_events", slackNotifications.getNoteEvents())
227-
.withParam("confidential_note_events", slackNotifications.getConfidentialNoteEvents())
228-
.withParam("pipeline_events", slackNotifications.getPipelineEvents())
229-
.withParam("wiki_page_events", slackNotifications.getWikiPageEvents())
230-
.withParam("push_channel", slackNotifications.getPushChannel())
231-
.withParam("issue_channel", slackNotifications.getIssueChannel())
232-
.withParam("confidential_issue_channel", slackNotifications.getConfidentialIssueChannel())
233-
.withParam("merge_request_channel", slackNotifications.getMergeRequestChannel())
234-
.withParam("note_channel", slackNotifications.getNoteChannel())
235-
.withParam("confidential_note_channel", slackNotifications.getConfidentialNoteChannel())
236-
.withParam("tag_push_channel", slackNotifications.getTagPushChannel())
237-
.withParam("pipeline_channel", slackNotifications.getPipelineChannel())
238-
.withParam("wiki_page_channel", slackNotifications.getWikiPageChannel());
202+
GitLabApiForm formData = slackNotifications.servicePropertiesForm();
239203
Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "services", "slack");
240204
return (response.readEntity(SlackService.class));
241205
}
@@ -289,15 +253,7 @@ public JiraService getJiraService(Object projectIdOrPath) throws GitLabApiExcept
289253
* @throws GitLabApiException if any exception occurs
290254
*/
291255
public JiraService updateJiraService(Object projectIdOrPath, JiraService jira) throws GitLabApiException {
292-
GitLabApiForm formData = new GitLabApiForm()
293-
.withParam("merge_requests_events", jira.getMergeRequestsEvents())
294-
.withParam("commit_events", jira.getCommitEvents())
295-
.withParam("url", jira.getUrl(), true)
296-
.withParam("api_url", jira.getApiUrl())
297-
.withParam("project_key", jira.getProjectKey())
298-
.withParam("username", jira.getUsername(), true)
299-
.withParam("password", jira.getPassword(), true)
300-
.withParam("jira_issue_transition_id", jira.getJiraIssueTransitionId());
256+
GitLabApiForm formData = jira.servicePropertiesForm();
301257
Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "services", "jira");
302258
return (response.readEntity(JiraService.class));
303259
}
@@ -344,8 +300,7 @@ public ExternalWikiService getExternalWikiService(Object projectIdOrPath) throws
344300
* @throws GitLabApiException if any exception occurs
345301
*/
346302
public ExternalWikiService updateExternalWikiService(Object projectIdOrPath, ExternalWikiService externalWiki) throws GitLabApiException {
347-
GitLabApiForm formData = new GitLabApiForm()
348-
.withParam("external_wiki_url", externalWiki.getExternalWikiUrl());
303+
GitLabApiForm formData = externalWiki.servicePropertiesForm();
349304
Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "services", "external-wiki");
350305
return (response.readEntity(ExternalWikiService.class));
351306
}
@@ -415,30 +370,7 @@ public MattermostService getMattermostService(Object projectIdOrPath) throws Git
415370
* @throws GitLabApiException if any exception occurs
416371
*/
417372
public MattermostService updateMattermostService(Object projectIdOrPath, MattermostService mattermostNotifications) throws GitLabApiException {
418-
GitLabApiForm formData = new GitLabApiForm()
419-
.withParam("webhook", mattermostNotifications.getWebhook(), true)
420-
.withParam("username", mattermostNotifications.getUsername())
421-
.withParam("channel", mattermostNotifications.getDefaultChannel())
422-
.withParam("notify_only_broken_pipelines", mattermostNotifications.getNotifyOnlyBrokenPipelines())
423-
.withParam("notify_only_default_branch", mattermostNotifications.getNotifyOnlyDefaultBranch())
424-
.withParam("push_events", mattermostNotifications.getPushEvents())
425-
.withParam("issues_events", mattermostNotifications.getIssuesEvents())
426-
.withParam("confidential_issues_events", mattermostNotifications.getConfidentialIssuesEvents())
427-
.withParam("merge_requests_events", mattermostNotifications.getMergeRequestsEvents())
428-
.withParam("tag_push_events", mattermostNotifications.getTagPushEvents())
429-
.withParam("note_events", mattermostNotifications.getNoteEvents())
430-
.withParam("confidential_note_events", mattermostNotifications.getConfidentialNoteEvents())
431-
.withParam("pipeline_events", mattermostNotifications.getPipelineEvents())
432-
.withParam("wiki_page_events", mattermostNotifications.getWikiPageEvents())
433-
.withParam("push_channel", mattermostNotifications.getPushChannel())
434-
.withParam("issue_channel", mattermostNotifications.getIssueChannel())
435-
.withParam("confidential_issue_channel", mattermostNotifications.getConfidentialIssueChannel())
436-
.withParam("merge_request_channel", mattermostNotifications.getMergeRequestChannel())
437-
.withParam("note_channel", mattermostNotifications.getNoteChannel())
438-
.withParam("confidential_note_channel", mattermostNotifications.getConfidentialNoteChannel())
439-
.withParam("tag_push_channel", mattermostNotifications.getTagPushChannel())
440-
.withParam("pipeline_channel", mattermostNotifications.getPipelineChannel())
441-
.withParam("wiki_page_channel", mattermostNotifications.getWikiPageChannel());
373+
GitLabApiForm formData = mattermostNotifications.servicePropertiesForm();
442374
Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "services", "mattermost");
443375
return (response.readEntity(MattermostService.class));
444376
}
@@ -455,4 +387,110 @@ public void deleteMattermostService(Object projectIdOrPath) throws GitLabApiExce
455387
Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
456388
delete(expectedStatus, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "mattermost");
457389
}
390+
391+
/**
392+
* Get the Bugzilla service settings for a project.
393+
*
394+
* <pre><code>GitLab Endpoint: GET /projects/:id/services/bugzilla</code></pre>
395+
*
396+
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
397+
* @return a BugzillaService instance holding the External Wiki service settings
398+
* @throws GitLabApiException if any exception occurs
399+
*/
400+
public BugzillaService getBugzillaService(Object projectIdOrPath) throws GitLabApiException {
401+
Response response = this.get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "bugzilla");
402+
return (response.readEntity(BugzillaService.class));
403+
}
404+
405+
/**
406+
* Updates the Bugzilla service settings for a project.
407+
*
408+
* <pre><code>GitLab Endpoint: PUT /projects/:id/services/bugzilla</code></pre>
409+
*
410+
* The following properties on the BugzillaService instance are utilized in the update of the settings:
411+
* <p>
412+
* description (optional), description
413+
* issuesUrl (required), issue url
414+
* newIssueUrl (required), new Issue url
415+
* projectUrl (required), project url
416+
* pushEvents (optional) - Enable notifications for push events
417+
* title (optional), the title for the custom issue tracker
418+
* </p>
419+
*
420+
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
421+
* @param bugzillaService the BugzillaService instance holding the settings
422+
* @return a BugzillaService instance holding the newly updated settings
423+
* @throws GitLabApiException if any exception occurs
424+
*/
425+
public BugzillaService updateBugzillaService(Object projectIdOrPath, BugzillaService bugzillaService) throws GitLabApiException {
426+
GitLabApiForm formData = bugzillaService.servicePropertiesForm();
427+
Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "services", "bugzilla");
428+
return (response.readEntity(BugzillaService.class));
429+
}
430+
431+
/**
432+
* Deletes the Bugzilla service for a project.
433+
*
434+
* <pre><code>GitLab Endpoint: DELETE /projects/:id/services/bugzilla</code></pre>
435+
*
436+
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
437+
* @throws GitLabApiException if any exception occurs
438+
*/
439+
public void deleteBugzillaService(Object projectIdOrPath) throws GitLabApiException {
440+
delete(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "bugzilla");
441+
442+
}
443+
444+
/**
445+
* Get the Custom Issue Tracker service settings for a project.
446+
*
447+
* <pre><code>GitLab Endpoint: GET /projects/:id/services/custom_issue_tracker</code></pre>
448+
*
449+
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
450+
* @return a ExternalWikiService instance holding the External Wiki service settings
451+
* @throws GitLabApiException if any exception occurs
452+
*/
453+
public CustomIssueTrackerService getCustomIssueTrackerService(Object projectIdOrPath) throws GitLabApiException {
454+
Response response = this.get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "custom-issue-tracker");
455+
return (response.readEntity(CustomIssueTrackerService.class));
456+
}
457+
458+
/**
459+
* Updates the Custom Issue Tracker service settings for a project.
460+
*
461+
* <pre><code>GitLab Endpoint: PUT /projects/:id/services/custom_issue_tracker</code></pre>
462+
*
463+
* The following properties on the CustomIssueTrackerService instance are utilized in the update of the settings:
464+
* <p>
465+
* description (optional), description
466+
* issuesUrl (required), issue url
467+
* newIssueUrl (required), new Issue url
468+
* projectUrl (required), project url
469+
* pushEvents (optional) - Enable notifications for push events
470+
* title (optional), the title for the custom issue tracker
471+
* </p>
472+
*
473+
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
474+
* @param customIssueTracker the CustomIssueTrackerService instance holding the settings
475+
* @return a CustomIssueTrackerService instance holding the newly updated settings
476+
* @throws GitLabApiException if any exception occurs
477+
*/
478+
public CustomIssueTrackerService updateCustomIssueTrackerService(Object projectIdOrPath, CustomIssueTrackerService customIssueTracker) throws GitLabApiException {
479+
GitLabApiForm formData = customIssueTracker.servicePropertiesForm();
480+
Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "services", "custom-issue-tracker");
481+
return (response.readEntity(CustomIssueTrackerService.class));
482+
}
483+
484+
/**
485+
* Deletes the Custom Issue Tracker service for a project.
486+
*
487+
* <pre><code>GitLab Endpoint: DELETE /projects/:id/services/custom_issue_tracker</code></pre>
488+
*
489+
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
490+
* @throws GitLabApiException if any exception occurs
491+
*/
492+
public void deleteCustomIssueTrackerService(Object projectIdOrPath) throws GitLabApiException {
493+
delete(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "custom-issue-tracker");
494+
495+
}
458496
}

0 commit comments

Comments
 (0)