Skip to content

Commit fd7f5a2

Browse files
committed
Mods to support MattermostService (#401).
1 parent 4c4349f commit fd7f5a2

File tree

3 files changed

+108
-15
lines changed

3 files changed

+108
-15
lines changed

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

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.gitlab4j.api.services.ExternalWikiService;
55
import org.gitlab4j.api.services.HipChatService;
66
import org.gitlab4j.api.services.JiraService;
7+
import org.gitlab4j.api.services.MattermostService;
78
import org.gitlab4j.api.services.SlackService;
89

910
import javax.ws.rs.core.Form;
@@ -315,7 +316,7 @@ public void deleteJiraService(Object projectIdOrPath) throws GitLabApiException
315316
}
316317

317318
/**
318-
* Get the JIRA service settings for a project.
319+
* Get the ExternalWiki service settings for a project.
319320
*
320321
* <pre><code>GitLab Endpoint: GET /projects/:id/services/external-wiki</code></pre>
321322
*
@@ -362,4 +363,96 @@ public void deleteExternalWikiService(Object projectIdOrPath) throws GitLabApiEx
362363
delete(expectedStatus, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "external-wiki");
363364

364365
}
366+
367+
/**
368+
* Get the Mattermost service settings for a project.
369+
*
370+
* <pre><code>GitLab Endpoint: GET /projects/:id/services/mattermost</code></pre>
371+
*
372+
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
373+
* @return a MattermostService instance holding the Mattermost service settings
374+
* @throws GitLabApiException if any exception occurs
375+
*/
376+
public MattermostService getMattermostService(Object projectIdOrPath) throws GitLabApiException {
377+
Response response = this.get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "mattermost");
378+
return (response.readEntity(MattermostService.class));
379+
}
380+
381+
/**
382+
* Updates the Mattermost service settings for a project.
383+
*
384+
* <pre><code>GitLab Endpoint: PUT /projects/:id/services/mattermost</code></pre>
385+
*
386+
* The following properties on the MattermostService instance are utilized in the update of the settings:
387+
* <p>
388+
* webhook (required) - https://hooks.slack.com/services/...
389+
* username (optional) - username
390+
* defaultChannel (optional) - Default channel to use if others are not configured
391+
* notifyOnlyBrokenPipelines (optional) - Send notifications for broken pipelines
392+
* notifyOnlyDefault_branch (optional) - Send notifications only for the default branch
393+
* pushEvents (optional) - Enable notifications for push events
394+
* issuesEvents (optional) - Enable notifications for issue events
395+
* confidentialIssuesEvents (optional) - Enable notifications for confidential issue events
396+
* mergeRequestsEvents (optional) - Enable notifications for merge request events
397+
* tagPushEvents (optional) - Enable notifications for tag push events
398+
* noteEvents (optional) - Enable notifications for note events
399+
* confidentialNoteEvents (optional) - Enable notifications for confidential note events
400+
* pipelineEvents (optional) - Enable notifications for pipeline events
401+
* wikiPageEvents (optional) - Enable notifications for wiki page events
402+
* pushChannel (optional) - The name of the channel to receive push events notifications
403+
* issueChannel (optional) - The name of the channel to receive issues events notifications
404+
* confidentialIssueChannel (optional) - The name of the channel to receive confidential issues events notifications
405+
* mergeRequestChannel (optional) - The name of the channel to receive merge request events notifications
406+
* noteChannel (optional) - The name of the channel to receive note events notifications
407+
* confidentialNoteChannel (optional) - The name of the channel to receive confidential note events notifications
408+
* tagPushChannel (optional) - The name of the channel to receive tag push events notifications
409+
* pipelineChannel (optional) - The name of the channel to receive pipeline events notifications
410+
* wikiPageChannel (optional) - The name of the channel to receive wiki page events notifications
411+
*
412+
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
413+
* @param mattermostNotifications the MattermostService instance holding the settings
414+
* @return a MattermostService instance holding the newly updated settings
415+
* @throws GitLabApiException if any exception occurs
416+
*/
417+
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());
442+
Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "services", "mattermost");
443+
return (response.readEntity(MattermostService.class));
444+
}
445+
446+
/**
447+
* Deletes the Mattermost service for a project.
448+
*
449+
* <pre><code>GitLab Endpoint: DELETE /projects/:id/services/external-wiki</code></pre>
450+
*
451+
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
452+
* @throws GitLabApiException if any exception occurs
453+
*/
454+
public void deleteMattermostService(Object projectIdOrPath) throws GitLabApiException {
455+
Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
456+
delete(expectedStatus, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "mattermost");
457+
}
365458
}

src/main/java/org/gitlab4j/api/services/NotificationService.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@
88

99
public abstract class NotificationService {
1010

11+
public static final String WEBHOOK_PROP = "webhook";
12+
public static final String USERNAME_PROP = "username";
13+
public static final String NOTIFY_ONLY_BROKEN_PIPELINES_PROP = "notify_only_broken_pipelines";
14+
public static final String NOTIFY_ONLY_DEFAULT_BRANCH_PROP = "notify_only_default_branch";
15+
public static final String PUSH_CHANNEL_PROP = "push_channel";
16+
public static final String ISSUE_CHANNEL_PROP = "issue_channel";
17+
public static final String CONFIDENTIAL_ISSUE_CHANNEL_PROP = "confidential_issue_channel";
18+
public static final String MERGE_REQUEST_CHANNEL_PROP = "merge_request_channel";
19+
public static final String NOTE_CHANNEL_PROP = "note_channel";
20+
public static final String CONFIDENTIAL_NOTE_CHANNEL_PROP = "confidential_note_channel";
21+
public static final String TAG_PUSH_CHANNEL_PROP = "tag_push_channel";
22+
public static final String PIPELINE_CHANNEL_PROP = "pipeline_channel";
23+
public static final String WIKI_PAGE_CHANNEL_PROP = "wiki_page_channel";
24+
1125
private Integer id;
1226
private String title;
1327
private Date createdAt;

src/main/java/org/gitlab4j/api/services/SlackService.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,6 @@
33
import com.fasterxml.jackson.annotation.JsonIgnore;
44

55
public class SlackService extends NotificationService {
6-
7-
public static final String WEBHOOK_PROP = "webhook";
8-
public static final String USERNAME_PROP = "username";
9-
public static final String NOTIFY_ONLY_BROKEN_PIPELINES_PROP = "notify_only_broken_pipelines";
10-
public static final String NOTIFY_ONLY_DEFAULT_BRANCH_PROP = "notify_only_default_branch";
11-
public static final String PUSH_CHANNEL_PROP = "push_channel";
12-
public static final String ISSUE_CHANNEL_PROP = "issue_channel";
13-
public static final String CONFIDENTIAL_ISSUE_CHANNEL_PROP = "confidential_issue_channel";
14-
public static final String MERGE_REQUEST_CHANNEL_PROP = "merge_request_channel";
15-
public static final String NOTE_CHANNEL_PROP = "note_channel";
16-
public static final String CONFIDENTIAL_NOTE_CHANNEL_PROP = "confidential_note_channel";
17-
public static final String TAG_PUSH_CHANNEL_PROP = "tag_push_channel";
18-
public static final String PIPELINE_CHANNEL_PROP = "pipeline_channel";
19-
public static final String WIKI_PAGE_CHANNEL_PROP = "wiki_page_channel";
206

217
private String defaultChannel;
228

0 commit comments

Comments
 (0)