Commit 857ac6a8 authored by Preethi Atchudan's avatar Preethi Atchudan Committed by Heidi Berry
Browse files

feat(hooks): Add webexintegration

Changelog: Improvements
parent b6373c35
Loading
Loading
Loading
Loading
+72 −0
Original line number Diff line number Diff line
@@ -149,6 +149,25 @@ type (
		// GitLab API docs:
		// https://docs.gitlab.com/api/group_integrations/#mattermost-slash-commands
		DeleteGroupMattermostSlashCommandsIntegration(gid any, options ...RequestOptionFunc) (*Response, error)

		// GetGroupWebexTeamsSettings gets the Webex Teams integration for a group.
		//
		// GitLab API docs:
		// https://docs.gitlab.com/api/group_integrations/#get-webex-teams-settings
		GetGroupWebexTeamsSettings(gid any, options ...RequestOptionFunc) (*WebexTeamsIntegration, *Response, error)

		// SetGroupWebexTeamsSettings sets up the Webex Teams integration for a group.
		//
		// GitLab API docs:
		// https://docs.gitlab.com/api/group_integrations/#set-up-webex-teams
		SetGroupWebexTeamsSettings(gid any, opt *SetGroupWebexTeamsOptions, options ...RequestOptionFunc) (*WebexTeamsIntegration, *Response, error)

		// DisableGroupWebexTeams disables the Webex Teams integration for a group.
		// Integration settings are reset.
		//
		// GitLab API docs:
		// https://docs.gitlab.com/api/group_integrations/#disable-webex-teams
		DisableGroupWebexTeams(gid any, options ...RequestOptionFunc) (*Response, error)
	}

	// IntegrationsService handles communication with the group
@@ -290,6 +309,30 @@ type GoogleChatIntegrationProperties struct {
	BranchesToBeNotified      string `json:"branches_to_be_notified,omitempty"`
}

// WebexTeamsIntegration represents the WebexTeams integration settings.
//
// GitLab API docs:
// https://docs.gitlab.com/api/group_integrations/#get-webex-teams-settings
type WebexTeamsIntegration struct {
	Integration
	Properties WebexTeamsIntegrationProperties `json:"properties"`
}

// WebexTeamsIntegrationProperties represents WebexTeams specific properties
type WebexTeamsIntegrationProperties struct {
	NotifyOnlyBrokenPipelines bool   `json:"notify_only_broken_pipelines,omitempty"`
	BranchesToBeNotified      string `json:"branches_to_be_notified,omitempty"`
}

// SetGroupWebexTeamsOptions represents the available SetGroupWebexTeamsSettings() options.
//
// GitLab API docs:
// https://docs.gitlab.com/api/group_integrations/#set-up-webex-teams
type SetGroupWebexTeamsOptions struct {
	NotifyOnlyBrokenPipelines *bool   `url:"notify_only_broken_pipelines,omitempty" json:"notify_only_broken_pipelines,omitempty"`
	BranchesToBeNotified      *string `url:"branches_to_be_notified,omitempty" json:"branches_to_be_notified,omitempty"`
}

// ListActiveIntegrationsOptions represents the available
// ListActiveIntegrations() options.
//
@@ -499,3 +542,32 @@ func (s *IntegrationsService) GetGroupGoogleChatSettings(gid any, options ...Req
		withRequestOpts(options...),
	)
}

func (s *IntegrationsService) GetGroupWebexTeamsSettings(gid any, options ...RequestOptionFunc) (*WebexTeamsIntegration, *Response, error) {
	return do[*WebexTeamsIntegration](
		s.client,
		withPath("groups/%s/integrations/webex-teams", GroupID{gid}),
		withMethod(http.MethodGet),
		withRequestOpts(options...),
	)
}

func (s *IntegrationsService) SetGroupWebexTeamsSettings(gid any, opt *SetGroupWebexTeamsOptions, options ...RequestOptionFunc) (*WebexTeamsIntegration, *Response, error) {
	return do[*WebexTeamsIntegration](
		s.client,
		withPath("groups/%s/integrations/webex-teams", GroupID{gid}),
		withMethod(http.MethodPut),
		withAPIOpts(opt),
		withRequestOpts(options...),
	)
}

func (s *IntegrationsService) DisableGroupWebexTeams(gid any, options ...RequestOptionFunc) (*Response, error) {
	_, resp, err := do[none](
		s.client,
		withPath("groups/%s/integrations/webex-teams", GroupID{gid}),
		withMethod(http.MethodDelete),
		withRequestOpts(options...),
	)
	return resp, err
}
+70 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ import (
	"time"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

func TestListActiveGroupIntegrations(t *testing.T) {
@@ -666,3 +667,72 @@ func TestGetGroupGoogleChatSettings(t *testing.T) {
	assert.NotNil(t, resp)
	assert.Equal(t, "default", integration.Properties.BranchesToBeNotified)
}

func TestGetGroupWebexTeamsSettings(t *testing.T) {
	t.Parallel()
	mux, client := setup(t)

	mux.HandleFunc("/api/v4/groups/1/integrations/webex-teams", func(w http.ResponseWriter, r *http.Request) {
		testMethod(t, r, http.MethodGet)
		fmt.Fprint(w, `{
			"id": 1,
			"title": "Webex Teams",
			"slug": "webex-teams",
			"created_at": "2023-01-01T00:00:00.000Z",
			"updated_at": "2023-01-02T00:00:00.000Z",
			"active": true,
			"properties": {
				"notify_only_broken_pipelines": true,
				"branches_to_be_notified": "all"
			}
		}`)
	})

	integration, resp, err := client.Integrations.GetGroupWebexTeamsSettings(1)
	require.NoError(t, err)
	assert.NotNil(t, resp)

	assert.True(t, integration.Properties.NotifyOnlyBrokenPipelines)
	assert.Equal(t, "all", integration.Properties.BranchesToBeNotified)
}

func TestSetGroupWebexTeamsSettings(t *testing.T) {
	t.Parallel()
	mux, client := setup(t)

	mux.HandleFunc("/api/v4/groups/1/integrations/webex-teams", func(w http.ResponseWriter, r *http.Request) {
		testMethod(t, r, http.MethodPut)
		fmt.Fprint(w, `{
			"id": 1,
			"title": "Webex Teams",
			"slug": "webex-teams",
			"created_at": "2023-01-01T00:00:00.000Z",
			"updated_at": "2023-01-02T00:00:00.000Z",
			"active": true,
			"properties": {
				"notify_only_broken_pipelines": true,
				"branches_to_be_notified": "all"
			}
		}`)
	})

	integration, resp, err := client.Integrations.SetGroupWebexTeamsSettings(1, nil)
	require.NoError(t, err)
	assert.NotNil(t, resp)

	assert.True(t, integration.Properties.NotifyOnlyBrokenPipelines)
	assert.Equal(t, "all", integration.Properties.BranchesToBeNotified)
}

func TestDisableGroupWebexTeams(t *testing.T) {
	t.Parallel()
	mux, client := setup(t)

	mux.HandleFunc("/api/v4/groups/1/integrations/webex-teams", func(w http.ResponseWriter, r *http.Request) {
		testMethod(t, r, http.MethodDelete)
	})

	resp, err := client.Integrations.DisableGroupWebexTeams(1)
	require.NoError(t, err)
	assert.NotNil(t, resp)
}
+134 −0
Original line number Diff line number Diff line
@@ -259,6 +259,50 @@ func (c *MockIntegrationsServiceInterfaceDisableGroupMicrosoftTeamsNotifications
	return c
}

// DisableGroupWebexTeams mocks base method.
func (m *MockIntegrationsServiceInterface) DisableGroupWebexTeams(gid any, options ...gitlab.RequestOptionFunc) (*gitlab.Response, error) {
	m.ctrl.T.Helper()
	varargs := []any{gid}
	for _, a := range options {
		varargs = append(varargs, a)
	}
	ret := m.ctrl.Call(m, "DisableGroupWebexTeams", varargs...)
	ret0, _ := ret[0].(*gitlab.Response)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}

// DisableGroupWebexTeams indicates an expected call of DisableGroupWebexTeams.
func (mr *MockIntegrationsServiceInterfaceMockRecorder) DisableGroupWebexTeams(gid any, options ...any) *MockIntegrationsServiceInterfaceDisableGroupWebexTeamsCall {
	mr.mock.ctrl.T.Helper()
	varargs := append([]any{gid}, options...)
	call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DisableGroupWebexTeams", reflect.TypeOf((*MockIntegrationsServiceInterface)(nil).DisableGroupWebexTeams), varargs...)
	return &MockIntegrationsServiceInterfaceDisableGroupWebexTeamsCall{Call: call}
}

// MockIntegrationsServiceInterfaceDisableGroupWebexTeamsCall wrap *gomock.Call
type MockIntegrationsServiceInterfaceDisableGroupWebexTeamsCall struct {
	*gomock.Call
}

// Return rewrite *gomock.Call.Return
func (c *MockIntegrationsServiceInterfaceDisableGroupWebexTeamsCall) Return(arg0 *gitlab.Response, arg1 error) *MockIntegrationsServiceInterfaceDisableGroupWebexTeamsCall {
	c.Call = c.Call.Return(arg0, arg1)
	return c
}

// Do rewrite *gomock.Call.Do
func (c *MockIntegrationsServiceInterfaceDisableGroupWebexTeamsCall) Do(f func(any, ...gitlab.RequestOptionFunc) (*gitlab.Response, error)) *MockIntegrationsServiceInterfaceDisableGroupWebexTeamsCall {
	c.Call = c.Call.Do(f)
	return c
}

// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockIntegrationsServiceInterfaceDisableGroupWebexTeamsCall) DoAndReturn(f func(any, ...gitlab.RequestOptionFunc) (*gitlab.Response, error)) *MockIntegrationsServiceInterfaceDisableGroupWebexTeamsCall {
	c.Call = c.Call.DoAndReturn(f)
	return c
}

// GetGroupDiscordSettings mocks base method.
func (m *MockIntegrationsServiceInterface) GetGroupDiscordSettings(gid any, options ...gitlab.RequestOptionFunc) (*gitlab.DiscordIntegration, *gitlab.Response, error) {
	m.ctrl.T.Helper()
@@ -709,6 +753,51 @@ func (c *MockIntegrationsServiceInterfaceGetGroupTelegramSettingsCall) DoAndRetu
	return c
}

// GetGroupWebexTeamsSettings mocks base method.
func (m *MockIntegrationsServiceInterface) GetGroupWebexTeamsSettings(gid any, options ...gitlab.RequestOptionFunc) (*gitlab.WebexTeamsIntegration, *gitlab.Response, error) {
	m.ctrl.T.Helper()
	varargs := []any{gid}
	for _, a := range options {
		varargs = append(varargs, a)
	}
	ret := m.ctrl.Call(m, "GetGroupWebexTeamsSettings", varargs...)
	ret0, _ := ret[0].(*gitlab.WebexTeamsIntegration)
	ret1, _ := ret[1].(*gitlab.Response)
	ret2, _ := ret[2].(error)
	return ret0, ret1, ret2
}

// GetGroupWebexTeamsSettings indicates an expected call of GetGroupWebexTeamsSettings.
func (mr *MockIntegrationsServiceInterfaceMockRecorder) GetGroupWebexTeamsSettings(gid any, options ...any) *MockIntegrationsServiceInterfaceGetGroupWebexTeamsSettingsCall {
	mr.mock.ctrl.T.Helper()
	varargs := append([]any{gid}, options...)
	call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetGroupWebexTeamsSettings", reflect.TypeOf((*MockIntegrationsServiceInterface)(nil).GetGroupWebexTeamsSettings), varargs...)
	return &MockIntegrationsServiceInterfaceGetGroupWebexTeamsSettingsCall{Call: call}
}

// MockIntegrationsServiceInterfaceGetGroupWebexTeamsSettingsCall wrap *gomock.Call
type MockIntegrationsServiceInterfaceGetGroupWebexTeamsSettingsCall struct {
	*gomock.Call
}

// Return rewrite *gomock.Call.Return
func (c *MockIntegrationsServiceInterfaceGetGroupWebexTeamsSettingsCall) Return(arg0 *gitlab.WebexTeamsIntegration, arg1 *gitlab.Response, arg2 error) *MockIntegrationsServiceInterfaceGetGroupWebexTeamsSettingsCall {
	c.Call = c.Call.Return(arg0, arg1, arg2)
	return c
}

// Do rewrite *gomock.Call.Do
func (c *MockIntegrationsServiceInterfaceGetGroupWebexTeamsSettingsCall) Do(f func(any, ...gitlab.RequestOptionFunc) (*gitlab.WebexTeamsIntegration, *gitlab.Response, error)) *MockIntegrationsServiceInterfaceGetGroupWebexTeamsSettingsCall {
	c.Call = c.Call.Do(f)
	return c
}

// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockIntegrationsServiceInterfaceGetGroupWebexTeamsSettingsCall) DoAndReturn(f func(any, ...gitlab.RequestOptionFunc) (*gitlab.WebexTeamsIntegration, *gitlab.Response, error)) *MockIntegrationsServiceInterfaceGetGroupWebexTeamsSettingsCall {
	c.Call = c.Call.DoAndReturn(f)
	return c
}

// ListActiveGroupIntegrations mocks base method.
func (m *MockIntegrationsServiceInterface) ListActiveGroupIntegrations(gid any, opt *gitlab.ListActiveIntegrationsOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.Integration, *gitlab.Response, error) {
	m.ctrl.T.Helper()
@@ -889,6 +978,51 @@ func (c *MockIntegrationsServiceInterfaceSetGroupMicrosoftTeamsNotificationsCall
	return c
}

// SetGroupWebexTeamsSettings mocks base method.
func (m *MockIntegrationsServiceInterface) SetGroupWebexTeamsSettings(gid any, opt *gitlab.SetGroupWebexTeamsOptions, options ...gitlab.RequestOptionFunc) (*gitlab.WebexTeamsIntegration, *gitlab.Response, error) {
	m.ctrl.T.Helper()
	varargs := []any{gid, opt}
	for _, a := range options {
		varargs = append(varargs, a)
	}
	ret := m.ctrl.Call(m, "SetGroupWebexTeamsSettings", varargs...)
	ret0, _ := ret[0].(*gitlab.WebexTeamsIntegration)
	ret1, _ := ret[1].(*gitlab.Response)
	ret2, _ := ret[2].(error)
	return ret0, ret1, ret2
}

// SetGroupWebexTeamsSettings indicates an expected call of SetGroupWebexTeamsSettings.
func (mr *MockIntegrationsServiceInterfaceMockRecorder) SetGroupWebexTeamsSettings(gid, opt any, options ...any) *MockIntegrationsServiceInterfaceSetGroupWebexTeamsSettingsCall {
	mr.mock.ctrl.T.Helper()
	varargs := append([]any{gid, opt}, options...)
	call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetGroupWebexTeamsSettings", reflect.TypeOf((*MockIntegrationsServiceInterface)(nil).SetGroupWebexTeamsSettings), varargs...)
	return &MockIntegrationsServiceInterfaceSetGroupWebexTeamsSettingsCall{Call: call}
}

// MockIntegrationsServiceInterfaceSetGroupWebexTeamsSettingsCall wrap *gomock.Call
type MockIntegrationsServiceInterfaceSetGroupWebexTeamsSettingsCall struct {
	*gomock.Call
}

// Return rewrite *gomock.Call.Return
func (c *MockIntegrationsServiceInterfaceSetGroupWebexTeamsSettingsCall) Return(arg0 *gitlab.WebexTeamsIntegration, arg1 *gitlab.Response, arg2 error) *MockIntegrationsServiceInterfaceSetGroupWebexTeamsSettingsCall {
	c.Call = c.Call.Return(arg0, arg1, arg2)
	return c
}

// Do rewrite *gomock.Call.Do
func (c *MockIntegrationsServiceInterfaceSetGroupWebexTeamsSettingsCall) Do(f func(any, *gitlab.SetGroupWebexTeamsOptions, ...gitlab.RequestOptionFunc) (*gitlab.WebexTeamsIntegration, *gitlab.Response, error)) *MockIntegrationsServiceInterfaceSetGroupWebexTeamsSettingsCall {
	c.Call = c.Call.Do(f)
	return c
}

// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockIntegrationsServiceInterfaceSetGroupWebexTeamsSettingsCall) DoAndReturn(f func(any, *gitlab.SetGroupWebexTeamsOptions, ...gitlab.RequestOptionFunc) (*gitlab.WebexTeamsIntegration, *gitlab.Response, error)) *MockIntegrationsServiceInterfaceSetGroupWebexTeamsSettingsCall {
	c.Call = c.Call.DoAndReturn(f)
	return c
}

// SetUpGroupHarbor mocks base method.
func (m *MockIntegrationsServiceInterface) SetUpGroupHarbor(gid any, opt *gitlab.SetUpHarborOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Integration, *gitlab.Response, error) {
	m.ctrl.T.Helper()