Skip to content

Commit ceac986

Browse files
authored
Merge pull request xanzy#1883 from KqLLL/feature/support-for-the-gitlab-for-slack-app
Support for the GitLab for Slack app
2 parents d276988 + a8f2a84 commit ceac986

File tree

2 files changed

+172
-0
lines changed

2 files changed

+172
-0
lines changed

services.go

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,132 @@ func (s *ServicesService) DeleteGithubService(pid interface{}, options ...Reques
756756
return s.client.Do(req, nil)
757757
}
758758

759+
// SlackApplication represents GitLab for slack application settings.
760+
//
761+
// GitLab API docs:
762+
// https://docs.gitlab.com/ee/api/integrations.html#gitlab-for-slack-app
763+
type SlackApplication struct {
764+
Service
765+
Properties *SlackApplicationProperties `json:"properties"`
766+
}
767+
768+
// SlackApplicationProperties represents GitLab for slack application specific properties.
769+
//
770+
// GitLab API docs:
771+
// https://docs.gitlab.com/ee/api/integrations.html#gitlab-for-slack-app
772+
type SlackApplicationProperties struct {
773+
Channel string `json:"channel"`
774+
NotifyOnlyBrokenPipelines bool `json:"notify_only_broken_pipelines"`
775+
BranchesToBeNotified string `json:"branches_to_be_notified"`
776+
AlertEvents bool `json:"alert_events"`
777+
IssuesEvents bool `json:"issues_events"`
778+
ConfidentialIssuesEvents bool `json:"confidential_issues_events"`
779+
MergeRequestsEvents bool `json:"merge_requests_events"`
780+
NoteEvents bool `json:"note_events"`
781+
ConfidentialNoteEvents bool `json:"confidential_note_events"`
782+
DeploymentEvents bool `json:"deployment_events"`
783+
IncidentsEvents bool `json:"incidents_events"`
784+
PipelineEvents bool `json:"pipeline_events"`
785+
PushEvents bool `json:"push_events"`
786+
TagPushEvents bool `json:"tag_push_events"`
787+
VulnerabilityEvents bool `json:"vulnerability_events"`
788+
WikiPageEvents bool `json:"wiki_page_events"`
789+
790+
// Deprecated: This parameter has been replaced with BranchesToBeNotified.
791+
NotifyOnlyDefaultBranch bool `json:"notify_only_default_branch"`
792+
}
793+
794+
// GetSlackApplication gets the GitLab for Slack app integration settings for a
795+
// project.
796+
//
797+
// GitLab API docs:
798+
// https://docs.gitlab.com/ee/api/integrations.html#get-gitlab-for-slack-app-settings
799+
func (s *ServicesService) GetSlackApplication(pid interface{}, options ...RequestOptionFunc) (*SlackApplication, *Response, error) {
800+
project, err := parseID(pid)
801+
if err != nil {
802+
return nil, nil, err
803+
}
804+
u := fmt.Sprintf("projects/%s/integrations/gitlab-slack-application", PathEscape(project))
805+
806+
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
807+
if err != nil {
808+
return nil, nil, err
809+
}
810+
811+
svc := new(SlackApplication)
812+
resp, err := s.client.Do(req, svc)
813+
if err != nil {
814+
return nil, resp, err
815+
}
816+
817+
return svc, resp, nil
818+
}
819+
820+
// SetSlackApplicationOptions represents the available SetSlackApplication()
821+
// options.
822+
//
823+
// GitLab API docs:
824+
// https://docs.gitlab.com/ee/api/integrations.html#set-up-gitlab-for-slack-app
825+
type SetSlackApplicationOptions struct {
826+
Channel *string `url:"channel,omitempty" json:"channel,omitempty"`
827+
NotifyOnlyBrokenPipelines *bool `url:"notify_only_broken_pipelines,omitempty" json:"notify_only_broken_pipelines,omitempty"`
828+
BranchesToBeNotified *string `url:"branches_to_be_notified,omitempty" json:"branches_to_be_notified,omitempty"`
829+
AlertEvents *bool `url:"alert_events,omitempty" json:"alert_events,omitempty"`
830+
IssuesEvents *bool `url:"issues_events,omitempty" json:"issues_events,omitempty"`
831+
ConfidentialIssuesEvents *bool `url:"confidential_issues_events,omitempty" json:"confidential_issues_events,omitempty"`
832+
MergeRequestsEvents *bool `url:"merge_requests_events,omitempty" json:"merge_requests_events,omitempty"`
833+
NoteEvents *bool `url:"note_events,omitempty" json:"note_events,omitempty"`
834+
ConfidentialNoteEvents *bool `url:"confidential_note_events,omitempty" json:"confidential_note_events,omitempty"`
835+
DeploymentEvents *bool `url:"deployment_events,omitempty" json:"deployment_events,omitempty"`
836+
IncidentsEvents *bool `url:"incidents_events,omitempty" json:"incidents_events,omitempty"`
837+
PipelineEvents *bool `url:"pipeline_events,omitempty" json:"pipeline_events,omitempty"`
838+
PushEvents *bool `url:"push_events,omitempty" json:"push_events,omitempty"`
839+
TagPushEvents *bool `url:"tag_push_events,omitempty" json:"tag_push_events,omitempty"`
840+
VulnerabilityEvents *bool `url:"vulnerability_events,omitempty" json:"vulnerability_events,omitempty"`
841+
WikiPageEvents *bool `url:"wiki_page_events,omitempty" json:"wiki_page_events,omitempty"`
842+
843+
// Deprecated: This parameter has been replaced with BranchesToBeNotified.
844+
NotifyOnlyDefaultBranch *bool `url:"notify_only_default_branch,omitempty" json:"notify_only_default_branch,omitempty"`
845+
}
846+
847+
// SetSlackApplication update the GitLab for Slack app integration for a project.
848+
//
849+
// GitLab API docs:
850+
// https://docs.gitlab.com/ee/api/integrations.html#set-up-gitlab-for-slack-app
851+
func (s *ServicesService) SetSlackApplication(pid interface{}, opt *SetSlackApplicationOptions, options ...RequestOptionFunc) (*Response, error) {
852+
project, err := parseID(pid)
853+
if err != nil {
854+
return nil, err
855+
}
856+
u := fmt.Sprintf("projects/%s/integrations/gitlab-slack-application", PathEscape(project))
857+
858+
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
859+
if err != nil {
860+
return nil, err
861+
}
862+
863+
return s.client.Do(req, nil)
864+
}
865+
866+
// DisableSlackApplication disable the GitLab for Slack app integration for a project.
867+
//
868+
// GitLab API docs:
869+
// https://docs.gitlab.com/ee/api/integrations.html#disable-gitlab-for-slack-app
870+
func (s *ServicesService) DisableSlackApplication(pid interface{}, options ...RequestOptionFunc) (*Response, error) {
871+
project, err := parseID(pid)
872+
if err != nil {
873+
return nil, err
874+
}
875+
u := fmt.Sprintf("projects/%s/integrations/gitlab-slack-application", PathEscape(project))
876+
877+
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
878+
if err != nil {
879+
return nil, err
880+
}
881+
882+
return s.client.Do(req, nil)
883+
}
884+
759885
// SetGitLabCIServiceOptions represents the available SetGitLabCIService()
760886
// options.
761887
//

services_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,52 @@ func TestDeleteEmailsOnPushService(t *testing.T) {
330330
}
331331
}
332332

333+
func TestGetSlackApplication(t *testing.T) {
334+
mux, client := setup(t)
335+
336+
mux.HandleFunc("/api/v4/projects/1/integrations/gitlab-slack-application", func(w http.ResponseWriter, r *http.Request) {
337+
testMethod(t, r, http.MethodGet)
338+
fmt.Fprint(w, `{"id":1}`)
339+
})
340+
want := &SlackApplication{Service: Service{ID: 1}}
341+
342+
service, _, err := client.Services.GetSlackApplication(1)
343+
if err != nil {
344+
t.Fatalf("Services.GetSlackApplication returns an error: %v", err)
345+
}
346+
if !reflect.DeepEqual(want, service) {
347+
t.Errorf("Services.GetSlackApplication returned %+v, want %+v", service, want)
348+
}
349+
}
350+
351+
func TestSetSlackApplication(t *testing.T) {
352+
mux, client := setup(t)
353+
354+
mux.HandleFunc("/api/v4/projects/1/integrations/gitlab-slack-application", func(w http.ResponseWriter, r *http.Request) {
355+
testMethod(t, r, http.MethodPut)
356+
})
357+
358+
opt := &SetSlackApplicationOptions{Channel: Ptr("#channel1"), NoteEvents: Ptr(true), AlertEvents: Ptr(true)}
359+
360+
_, err := client.Services.SetSlackApplication(1, opt)
361+
if err != nil {
362+
t.Fatalf("Services.SetSlackApplication returns an error: %v", err)
363+
}
364+
}
365+
366+
func TestDisableSlackApplication(t *testing.T) {
367+
mux, client := setup(t)
368+
369+
mux.HandleFunc("/api/v4/projects/1/integrations/gitlab-slack-application", func(w http.ResponseWriter, r *http.Request) {
370+
testMethod(t, r, http.MethodDelete)
371+
})
372+
373+
_, err := client.Services.DisableSlackApplication(1)
374+
if err != nil {
375+
t.Fatalf("Services.DisableSlackApplication returns an error: %v", err)
376+
}
377+
}
378+
333379
func TestGetJiraService(t *testing.T) {
334380
mux, client := setup(t)
335381

0 commit comments

Comments
 (0)