Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the Redmine Integration #2007

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions services.go
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,101 @@ func (s *ServicesService) DeletePrometheusService(pid interface{}, options ...Re
return s.client.Do(req, nil)
}

// RedmineService represents the Redmine service settings.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/integrations.html#redmine
type RedmineService struct {
Service
Properties *RedmineServiceProperties `json:"properties"`
}

// RedmineServiceProperties represents Redmine specific properties.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/integrations.html#redmine
type RedmineServiceProperties struct {
NewIssueURL string `json:"new_issue_url"`
ProjectURL string `json:"project_url"`
IssuesURL string `json:"issues_url"`
UseInheritedSettings BoolValue `json:"use_inherited_settings"`
}

// GetRedmineService gets Redmine service settings for a project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/integrations.html#get-redmine-settings
func (s *ServicesService) GetRedmineService(pid interface{}, options ...RequestOptionFunc) (*RedmineService, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/integrations/redmine", PathEscape(project))

req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}

svc := new(RedmineService)
resp, err := s.client.Do(req, svc)
if err != nil {
return nil, resp, err
}

return svc, resp, nil
}

// SetRedmineServiceOptions represents the available SetRedmineService().
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/integrations.html#set-up-redmine
type SetRedmineServiceOptions struct {
NewIssueURL *string `url:"new_issue_url,omitempty" json:"new_issue_url,omitempty"`
ProjectURL *string `url:"project_url,omitempty" json:"project_url,omitempty"`
IssuesURL *string `url:"issues_url,omitempty" json:"issues_url,omitempty"`
UseInheritedSettings *bool `url:"use_inherited_settings,omitempty" json:"use_inherited_settings,omitempty"`
}

// SetRedmineService sets Redmine service for a project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/integrations.html#set-up-redmine
func (s *ServicesService) SetRedmineService(pid interface{}, opt *SetRedmineServiceOptions, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/integrations/redmine", PathEscape(project))

req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, err
}

return s.client.Do(req, nil)
}

// DeleteRedmineService deletes Redmine service for project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/integrations.html#disable-redmine
func (s *ServicesService) DeleteRedmineService(pid interface{}, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/integrations/redmine", PathEscape(project))

req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}

return s.client.Do(req, nil)
}

// SlackService represents Slack service settings.
//
// GitLab API docs:
Expand Down
46 changes: 46 additions & 0 deletions services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,52 @@ func TestDeletePrometheusService(t *testing.T) {
}
}

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

mux.HandleFunc("/api/v4/projects/1/integrations/redmine", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"id":1}`)
})
want := &RedmineService{Service: Service{ID: 1}}

service, _, err := client.Services.GetRedmineService(1)
if err != nil {
t.Fatalf("Services.GetRedmineService returns an error: %v", err)
}
if !reflect.DeepEqual(want, service) {
t.Errorf("Services.GetRedmineService returned %+v, want %+v", service, want)
}
}

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

mux.HandleFunc("/api/v4/projects/1/integrations/redmine", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
})

opt := &SetRedmineServiceOptions{Ptr("t"), Ptr("u"), Ptr("a"), Ptr(false)}

_, err := client.Services.SetRedmineService(1, opt)
if err != nil {
t.Fatalf("Services.SetRedmineService returns an error: %v", err)
}
}

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

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

_, err := client.Services.DeleteRedmineService(1)
if err != nil {
t.Fatalf("Services.DeleteRedmineService returns an error: %v", err)
}
}

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

Expand Down