Skip to content

Commit

Permalink
Merge pull request #1999 from deepflame/feature/update-jira-integration
Browse files Browse the repository at this point in the history
Update jira integration pt2
  • Loading branch information
svanharmelen authored Aug 30, 2024
2 parents 000cfc0 + 3548be2 commit 315e1c6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
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

0 comments on commit 315e1c6

Please sign in to comment.