Skip to content

Commit

Permalink
Project Service: Project.GetList removed, Project.ListWithOptions
Browse files Browse the repository at this point in the history
… renamed to `Project.GetAll`

Related #294
  • Loading branch information
andygrunwald committed Sep 12, 2022
1 parent 5a66ee4 commit d2547bd
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 74 deletions.
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,38 @@ After:
client.Issue.GetCreateMeta(ctx, &GetQueryOptions{ProjectKeys: "SPN", Expand: "projects.issuetypes.fields"})
```

#### `Project.GetList` removed, `Project.ListWithOptions` renamed

The function `client.Project.ListWithOptions()` has been renamed to `client.Project.GetAll()`.

##### If you used `client.Project.GetList()`:

Before:

```go
client.Project.GetList(context.Background())
```

After:

```go
client.Project.GetAll(context.Background(), nil)
```

##### If you used `client.Project.ListWithOptions()`:

Before:

```go
client.Project.ListWithOptions(ctx, &GetQueryOptions{})
```

After:

```go
client.Project.GetAll(ctx, &GetQueryOptions{})
```

### Breaking changes

* Jira On-Premise and Jira Cloud have now different clients, because the API differs
Expand All @@ -304,6 +336,8 @@ client.Issue.GetCreateMeta(ctx, &GetQueryOptions{ProjectKeys: "SPN", Expand: "pr
* `BoardService.GetAllSprints` has been removed and `BoardService.GetAllSprintsWithOptions` has been renamed to `BoardService.GetAllSprints`
* `GroupService.Get` has been removed and `GroupService.GetWithOptions` has been renamed to `GroupService.Get`
* `Issue.Update` has been removed and `Issue.UpdateWithOptions` has been renamed to `Issue.Update`
* `Issue.GetCreateMeta` has been removed and `Issue.GetCreateMetaWithOptions` has been renamed to `Issue.GetCreateMeta`
* `Project.GetList` has been removed and `Project.ListWithOptions` has been renamed to `Project.GetAll`

### Features

Expand Down
15 changes: 4 additions & 11 deletions cloud/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,11 @@ type PermissionScheme struct {
Permissions []Permission `json:"permissions" structs:"permissions,omitempty"`
}

// GetList gets all projects form Jira
// GetAll returns all projects form Jira with optional query params, like &GetQueryOptions{Expand: "issueTypes"} to get
// a list of all projects and their supported issuetypes.
//
// Jira API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/project-getAllProjects
func (s *ProjectService) GetList(ctx context.Context) (*ProjectList, *Response, error) {
return s.ListWithOptions(ctx, &GetQueryOptions{})
}

// ListWithOptions gets all projects form Jira with optional query params, like &GetQueryOptions{Expand: "issueTypes"} to get
// a list of all projects and their supported issuetypes
//
// Jira API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/project-getAllProjects
func (s *ProjectService) ListWithOptions(ctx context.Context, options *GetQueryOptions) (*ProjectList, *Response, error) {
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-projects/#api-rest-api-2-project-get
func (s *ProjectService) GetAll(ctx context.Context, options *GetQueryOptions) (*ProjectList, *Response, error) {
apiEndpoint := "rest/api/2/project"
req, err := s.client.NewRequest(ctx, http.MethodGet, apiEndpoint, nil)
if err != nil {
Expand Down
28 changes: 2 additions & 26 deletions cloud/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,7 @@ import (
"testing"
)

func TestProjectService_GetList(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/rest/api/2/project"

raw, err := os.ReadFile("../testing/mock-data/all_projects.json")
if err != nil {
t.Error(err.Error())
}
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
testRequestURL(t, r, testAPIEdpoint)
fmt.Fprint(w, string(raw))
})

projects, _, err := testClient.Project.GetList(context.Background())
if projects == nil {
t.Error("Expected project list. Project list is nil")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}

func TestProjectService_ListWithOptions(t *testing.T) {
func TestProjectService_GetAll(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/rest/api/2/project"
Expand All @@ -47,7 +23,7 @@ func TestProjectService_ListWithOptions(t *testing.T) {
fmt.Fprint(w, string(raw))
})

projects, _, err := testClient.Project.ListWithOptions(context.Background(), &GetQueryOptions{Expand: "issueTypes"})
projects, _, err := testClient.Project.GetAll(context.Background(), &GetQueryOptions{Expand: "issueTypes"})
if projects == nil {
t.Error("Expected project list. Project list is nil")
}
Expand Down
15 changes: 4 additions & 11 deletions onpremise/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,11 @@ type PermissionScheme struct {
Permissions []Permission `json:"permissions" structs:"permissions,omitempty"`
}

// GetList gets all projects form Jira
// GetAll returns all projects form Jira with optional query params, like &GetQueryOptions{Expand: "issueTypes"} to get
// a list of all projects and their supported issuetypes.
//
// Jira API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/project-getAllProjects
func (s *ProjectService) GetList(ctx context.Context) (*ProjectList, *Response, error) {
return s.ListWithOptions(ctx, &GetQueryOptions{})
}

// ListWithOptions gets all projects form Jira with optional query params, like &GetQueryOptions{Expand: "issueTypes"} to get
// a list of all projects and their supported issuetypes
//
// Jira API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/project-getAllProjects
func (s *ProjectService) ListWithOptions(ctx context.Context, options *GetQueryOptions) (*ProjectList, *Response, error) {
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-projects/#api-rest-api-2-project-get
func (s *ProjectService) GetAll(ctx context.Context, options *GetQueryOptions) (*ProjectList, *Response, error) {
apiEndpoint := "rest/api/2/project"
req, err := s.client.NewRequest(ctx, http.MethodGet, apiEndpoint, nil)
if err != nil {
Expand Down
28 changes: 2 additions & 26 deletions onpremise/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,7 @@ import (
"testing"
)

func TestProjectService_GetList(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/rest/api/2/project"

raw, err := os.ReadFile("../testing/mock-data/all_projects.json")
if err != nil {
t.Error(err.Error())
}
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
testRequestURL(t, r, testAPIEdpoint)
fmt.Fprint(w, string(raw))
})

projects, _, err := testClient.Project.GetList(context.Background())
if projects == nil {
t.Error("Expected project list. Project list is nil")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}

func TestProjectService_ListWithOptions(t *testing.T) {
func TestProjectService_GetAll(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/rest/api/2/project"
Expand All @@ -47,7 +23,7 @@ func TestProjectService_ListWithOptions(t *testing.T) {
fmt.Fprint(w, string(raw))
})

projects, _, err := testClient.Project.ListWithOptions(context.Background(), &GetQueryOptions{Expand: "issueTypes"})
projects, _, err := testClient.Project.GetAll(context.Background(), &GetQueryOptions{Expand: "issueTypes"})
if projects == nil {
t.Error("Expected project list. Project list is nil")
}
Expand Down

0 comments on commit d2547bd

Please sign in to comment.