Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Update jira integration pt2 #1999

Merged
merged 4 commits into from
Aug 30, 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
28 changes: 19 additions & 9 deletions services.go
Original file line number Diff line number Diff line change
Expand Up @@ -1102,12 +1102,22 @@ type JiraService struct {
// GitLab API docs:
// https://docs.gitlab.com/ee/api/integrations.html#jira
type JiraServiceProperties struct {
URL string `json:"url"`
APIURL string `json:"api_url"`
ProjectKeys []string `json:"project_keys" `
Username string `json:"username" `
Password string `json:"password" `
JiraIssueTransitionID string `json:"jira_issue_transition_id"`
URL string `json:"url"`
APIURL string `json:"api_url"`
Username string `json:"username" `
Password string `json:"password" `
Active bool `json:"active"`
JiraAuthType int `json:"jira_auth_type"`
JiraIssuePrefix string `json:"jira_issue_prefix"`
JiraIssueRegex string `json:"jira_issue_regex"`
JiraIssueTransitionAutomatic bool `json:"jira_issue_transition_automatic"`
JiraIssueTransitionID string `json:"jira_issue_transition_id"`
CommitEvents bool `json:"commit_events"`
MergeRequestsEvents bool `json:"merge_requests_events"`
CommentOnEventEnabled bool `json:"comment_on_event_enabled"`
IssuesEnabled bool `json:"issues_enabled"`
ProjectKeys []string `json:"project_keys" `
UseInheritedSettings bool `json:"use_inherited_settings"`

// Deprecated: This parameter was removed in GitLab 17.0
ProjectKey string `json:"project_key" `
Expand Down Expand Up @@ -1152,7 +1162,7 @@ func (s *ServicesService) GetJiraService(pid interface{}, options ...RequestOpti
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/services/jira", PathEscape(project))
u := fmt.Sprintf("projects/%s/integrations/jira", PathEscape(project))

req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
Expand Down Expand Up @@ -1204,7 +1214,7 @@ func (s *ServicesService) SetJiraService(pid interface{}, opt *SetJiraServiceOpt
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/services/jira", PathEscape(project))
u := fmt.Sprintf("projects/%s/integrations/jira", PathEscape(project))

req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
Expand All @@ -1223,7 +1233,7 @@ func (s *ServicesService) DeleteJiraService(pid interface{}, options ...RequestO
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/services/jira", PathEscape(project))
u := fmt.Sprintf("projects/%s/integrations/jira", PathEscape(project))

req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
Expand Down
35 changes: 23 additions & 12 deletions services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,27 +376,36 @@ func TestDisableSlackApplication(t *testing.T) {
func TestGetJiraService(t *testing.T) {
mux, client := setup(t)

mux.HandleFunc("/api/v4/projects/0/services/jira", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/api/v4/projects/0/integrations/jira", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"id":1, "properties": {}}`)
})

mux.HandleFunc("/api/v4/projects/1/integrations/jira", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"id":1, "properties": {"jira_issue_transition_id": "2"}}`)
})

mux.HandleFunc("/api/v4/projects/1/services/jira", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/api/v4/projects/2/integrations/jira", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"id":1, "properties": {"jira_issue_transition_id": 2}}`)
})

mux.HandleFunc("/api/v4/projects/2/services/jira", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/api/v4/projects/3/integrations/jira", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"id":1, "properties": {"jira_issue_transition_id": "2,3"}}`)
})

mux.HandleFunc("/api/v4/projects/3/services/jira", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/api/v4/projects/4/integrations/jira", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"id":1, "properties": {}}`)
fmt.Fprint(w, `{"id":1, "properties": {"jira_auth_type": 1}}`)
})

want := []*JiraService{
{
Service: Service{ID: 1},
Properties: &JiraServiceProperties{},
},
{
Service: Service{ID: 1},
Properties: &JiraServiceProperties{
Expand All @@ -416,8 +425,10 @@ func TestGetJiraService(t *testing.T) {
},
},
{
Service: Service{ID: 1},
Properties: &JiraServiceProperties{},
Service: Service{ID: 1},
Properties: &JiraServiceProperties{
JiraAuthType: 1,
},
},
}

Expand All @@ -436,7 +447,7 @@ func TestGetJiraService(t *testing.T) {
func TestSetJiraService(t *testing.T) {
mux, client := setup(t)

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

Expand Down Expand Up @@ -467,7 +478,7 @@ func TestSetJiraService(t *testing.T) {
func TestSetJiraServiceProjecKeys(t *testing.T) {
mux, client := setup(t)

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

Expand Down Expand Up @@ -498,7 +509,7 @@ func TestSetJiraServiceProjecKeys(t *testing.T) {
func TestSetJiraServiceAuthTypeBasicAuth(t *testing.T) {
mux, client := setup(t)

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

Expand All @@ -518,7 +529,7 @@ func TestSetJiraServiceAuthTypeBasicAuth(t *testing.T) {
func TestSetJiraServiceAuthTypeTokenAuth(t *testing.T) {
mux, client := setup(t)

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

Expand All @@ -537,7 +548,7 @@ func TestSetJiraServiceAuthTypeTokenAuth(t *testing.T) {
func TestDeleteJiraService(t *testing.T) {
mux, client := setup(t)

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

Expand Down