Repository: xanzy/go-gitlab
Pull request #1970 (2024-07-11 14:08:54)

Update Jira Integration
Update Jira-Integration-API according to the docs of Gitlab 17.2
https://docs.gitlab.com/ee/api/integrations.html#set-up-jira


Patch:
diff --git a/services.go b/services.go
index f630661..a7eeb72 100644
--- a/services.go
+++ b/services.go
@@ -1174,16 +1174,22 @@ func (s *ServicesService) GetJiraService(pid interface{}, options ...RequestOpti
 // GitLab API docs:
 // https://docs.gitlab.com/ee/api/integrations.html#edit-jira-service
 type SetJiraServiceOptions struct {
-	URL                   *string   `url:"url,omitempty" json:"url,omitempty"`
-	APIURL                *string   `url:"api_url,omitempty" json:"api_url,omitempty"`
-	ProjectKeys           *[]string `url:"project_keys,comma,omitempty" json:"project_keys,omitempty" `
-	Username              *string   `url:"username,omitempty" json:"username,omitempty" `
-	Password              *string   `url:"password,omitempty" json:"password,omitempty" `
-	Active                *bool     `url:"active,omitempty" json:"active,omitempty"`
-	JiraIssueTransitionID *string   `url:"jira_issue_transition_id,omitempty" json:"jira_issue_transition_id,omitempty"`
-	CommitEvents          *bool     `url:"commit_events,omitempty" json:"commit_events,omitempty"`
-	MergeRequestsEvents   *bool     `url:"merge_requests_events,omitempty" json:"merge_requests_events,omitempty"`
-	CommentOnEventEnabled *bool     `url:"comment_on_event_enabled,omitempty" json:"comment_on_event_enabled,omitempty"`
+	URL                          *string   `url:"url,omitempty" json:"url,omitempty"`
+	APIURL                       *string   `url:"api_url,omitempty" json:"api_url,omitempty"`
+	Username                     *string   `url:"username,omitempty" json:"username,omitempty" `
+	Password                     *string   `url:"password,omitempty" json:"password,omitempty" `
+	Active                       *bool     `url:"active,omitempty" json:"active,omitempty"`
+	JiraAuthType                 *int      `url:"jira_auth_type,omitempty" json:"jira_auth_type,omitempty"`
+	JiraIssuePrefix              *string   `url:"jira_issue_prefix,omitempty" json:"jira_issue_prefix,omitempty"`
+	JiraIssueRegex               *string   `url:"jira_issue_regex,omitempty" json:"jira_issue_regex,omitempty"`
+	JiraIssueTransitionAutomatic *bool     `url:"jira_issue_transition_automatic,omitempty" json:"jira_issue_transition_automatic,omitempty"`
+	JiraIssueTransitionID        *string   `url:"jira_issue_transition_id,omitempty" json:"jira_issue_transition_id,omitempty"`
+	CommitEvents                 *bool     `url:"commit_events,omitempty" json:"commit_events,omitempty"`
+	MergeRequestsEvents          *bool     `url:"merge_requests_events,omitempty" json:"merge_requests_events,omitempty"`
+	CommentOnEventEnabled        *bool     `url:"comment_on_event_enabled,omitempty" json:"comment_on_event_enabled,omitempty"`
+	IssuesEnabled                *bool     `url:"issues_enabled,omitempty" json:"issues_enabled,omitempty"`
+	ProjectKeys                  *[]string `url:"project_keys,comma,omitempty" json:"project_keys,omitempty" `
+	UseInheritedSettings         *bool     `url:"use_inherited_settings,omitempty" json:"use_inherited_settings,omitempty"`
 
 	// Deprecated: This parameter was removed in GitLab 17.0
 	ProjectKey *string `url:"project_key,omitempty" json:"project_key,omitempty" `


Test patch:
diff --git a/services_test.go b/services_test.go
index be9c2f9..69d2bfc 100644
--- a/services_test.go
+++ b/services_test.go
@@ -441,16 +441,21 @@ func TestSetJiraService(t *testing.T) {
 	})
 
 	opt := &SetJiraServiceOptions{
-		URL:                   Ptr("asd"),
-		APIURL:                Ptr("asd"),
-		ProjectKey:            Ptr("as"),
-		Username:              Ptr("aas"),
-		Password:              Ptr("asd"),
-		Active:                Ptr(true),
-		JiraIssueTransitionID: Ptr("2,3"),
-		CommitEvents:          Ptr(true),
-		CommentOnEventEnabled: Ptr(true),
-		MergeRequestsEvents:   Ptr(true),
+		URL:                          Ptr("asd"),
+		APIURL:                       Ptr("asd"),
+		ProjectKey:                   Ptr("as"),
+		Username:                     Ptr("aas"),
+		Password:                     Ptr("asd"),
+		Active:                       Ptr(true),
+		JiraIssuePrefix:              Ptr("ASD"),
+		JiraIssueRegex:               Ptr("ASD"),
+		JiraIssueTransitionAutomatic: Ptr(true),
+		JiraIssueTransitionID:        Ptr("2,3"),
+		CommitEvents:                 Ptr(true),
+		MergeRequestsEvents:          Ptr(true),
+		CommentOnEventEnabled:        Ptr(true),
+		IssuesEnabled:                Ptr(true),
+		UseInheritedSettings:         Ptr(true),
 	}
 
 	_, err := client.Services.SetJiraService(1, opt)
@@ -467,16 +472,60 @@ func TestSetJiraServiceProjecKeys(t *testing.T) {
 	})
 
 	opt := &SetJiraServiceOptions{
-		URL:                   Ptr("asd"),
-		APIURL:                Ptr("asd"),
-		ProjectKeys:           Ptr([]string{"as"}),
-		Username:              Ptr("aas"),
-		Password:              Ptr("asd"),
-		Active:                Ptr(true),
-		JiraIssueTransitionID: Ptr("2,3"),
-		CommitEvents:          Ptr(true),
-		CommentOnEventEnabled: Ptr(true),
-		MergeRequestsEvents:   Ptr(true),
+		URL:                          Ptr("asd"),
+		APIURL:                       Ptr("asd"),
+		Username:                     Ptr("aas"),
+		Password:                     Ptr("asd"),
+		Active:                       Ptr(true),
+		JiraIssuePrefix:              Ptr("ASD"),
+		JiraIssueRegex:               Ptr("ASD"),
+		JiraIssueTransitionAutomatic: Ptr(true),
+		JiraIssueTransitionID:        Ptr("2,3"),
+		CommitEvents:                 Ptr(true),
+		MergeRequestsEvents:          Ptr(true),
+		CommentOnEventEnabled:        Ptr(true),
+		IssuesEnabled:                Ptr(true),
+		ProjectKeys:                  Ptr([]string{"as"}),
+		UseInheritedSettings:         Ptr(true),
+	}
+
+	_, err := client.Services.SetJiraService(1, opt)
+	if err != nil {
+		t.Fatalf("Services.SetJiraService returns an error: %v", err)
+	}
+}
+
+func TestSetJiraServiceAuthTypeBasicAuth(t *testing.T) {
+	mux, client := setup(t)
+
+	mux.HandleFunc("/api/v4/projects/1/services/jira", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, http.MethodPut)
+	})
+
+	opt := &SetJiraServiceOptions{
+		URL:          Ptr("asd"),
+		Username:     Ptr("aas"),
+		Password:     Ptr("asd"),
+		JiraAuthType: Ptr(0),
+	}
+
+	_, err := client.Services.SetJiraService(1, opt)
+	if err != nil {
+		t.Fatalf("Services.SetJiraService returns an error: %v", err)
+	}
+}
+
+func TestSetJiraServiceAuthTypeTokenAuth(t *testing.T) {
+	mux, client := setup(t)
+
+	mux.HandleFunc("/api/v4/projects/1/services/jira", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, http.MethodPut)
+	})
+
+	opt := &SetJiraServiceOptions{
+		URL:          Ptr("asd"),
+		Password:     Ptr("asd"),
+		JiraAuthType: Ptr(1),
 	}
 
 	_, err := client.Services.SetJiraService(1, opt)