Skip to content

Commit

Permalink
Merge pull request #1970 from deepflame/feature/update-jira-integration
Browse files Browse the repository at this point in the history
Update Jira Integration
  • Loading branch information
svanharmelen authored Jul 12, 2024
2 parents 138b042 + e43897f commit 7f1e0f7
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 30 deletions.
26 changes: 16 additions & 10 deletions services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" `
Expand Down
89 changes: 69 additions & 20 deletions services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 7f1e0f7

Please sign in to comment.