Skip to content

Commit

Permalink
feat: Add GetMyFilters to FilterService
Browse files Browse the repository at this point in the history
  • Loading branch information
hirakiuc authored and ghostsquad committed Aug 26, 2019
1 parent fd698c5 commit ebae19d
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 0 deletions.
29 changes: 29 additions & 0 deletions filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ type Filter struct {
} `json:"subscriptions"`
}

// GetMyFiltersQueryOptions specifies the optional parameters for the Get My Filters method
type GetMyFiltersQueryOptions struct {
IncludeFavourites bool `url:"includeFavourites,omitempty"`
Expand string `url:"expand,omitempty"`
}

// GetList retrieves all filters from Jira
func (fs *FilterService) GetList() ([]*Filter, *Response, error) {

Expand Down Expand Up @@ -91,3 +97,26 @@ func (fs *FilterService) Get(filterID int) (*Filter, *Response, error) {

return filter, resp, err
}

// GetMyFilters retrieves the my Filters.
//
// https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-rest-api-3-filter-my-get
func (fs *FilterService) GetMyFilters(opts *GetMyFiltersQueryOptions) ([]*Filter, *Response, error) {
apiEndpoint := "rest/api/3/filter/my"
url, err := addOptions(apiEndpoint, opts)
if err != nil {
return nil, nil, err
}
req, err := fs.client.NewRequest("GET", url, nil)
if err != nil {
return nil, nil, err
}

filters := []*Filter{}
resp, err := fs.client.Do(req, &filters)
if err != nil {
jerr := NewJiraError(resp, err)
return nil, resp, jerr
}
return filters, resp, err
}
24 changes: 24 additions & 0 deletions filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,27 @@ func TestFilterService_GetFavouriteList(t *testing.T) {
t.Errorf("Error given: %s", err)
}
}

func TestFilterService_GetMyFilters(t *testing.T) {
setup()
defer teardown()
testAPIEndpoint := "/rest/api/3/filter/my"
raw, err := ioutil.ReadFile("./mocks/my_filters.json")
if err != nil {
t.Error(err.Error())
}
testMux.HandleFunc(testAPIEndpoint, func(writer http.ResponseWriter, request *http.Request) {
testMethod(t, request, "GET")
testRequestURL(t, request, testAPIEndpoint)
fmt.Fprint(writer, string(raw))
})

opts := GetMyFiltersQueryOptions{}
filters, _, err := testClient.Filter.GetMyFilters(&opts)
if err != nil {
t.Errorf("Error given: %s", err)
}
if filters == nil {
t.Errorf("Expected Filters, got nil")
}
}
97 changes: 97 additions & 0 deletions mocks/my_filters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
[
{
"self": "http://test.jira.org/rest/api/3/filter/10000",
"id": "10000",
"name": "All Open Bugs",
"description": "Lists all open bugs",
"owner": {
"self": "http://test.jira.org/rest/api/3/user?accountId=99:27935d01-92a7-4687-8272-a9b8d3b2ae2e",
"key": "",
"accountId": "99:27935d01-92a7-4687-8272-a9b8d3b2ae2e",
"name": "",
"avatarUrls": {
"48x48": "http://test.jira.org/secure/useravatar?size=large&ownerId=mia",
"24x24": "http://test.jira.org/secure/useravatar?size=small&ownerId=mia",
"16x16": "http://test.jira.org/secure/useravatar?size=xsmall&ownerId=mia",
"32x32": "http://test.jira.org/secure/useravatar?size=medium&ownerId=mia"
},
"displayName": "Mia Krystof",
"active": false
},
"jql": "type = Bug and resolution is empty",
"viewUrl": "http://test.jira.org/issues/?filter=10000",
"searchUrl": "http://test.jira.org/rest/api/3/search?jql=type%20%3D%20Bug%20and%20resolutino%20is%20empty",
"favourite": true,
"favouritedCount": 0,
"sharePermissions": [],
"subscriptions": {
"size": 0,
"items": [],
"max-results": 0,
"start-index": 0,
"end-index": 0
}
},
{
"self": "http://test.jira.org/rest/api/3/filter/10010",
"id": "10010",
"name": "My issues",
"description": "Issues assigned to me",
"owner": {
"self": "http://test.jira.org/rest/api/3/user?accountId=99:27935d01-92a7-4687-8272-a9b8d3b2ae2e",
"key": "",
"accountId": "99:27935d01-92a7-4687-8272-a9b8d3b2ae2e",
"name": "",
"avatarUrls": {
"48x48": "http://test.jira.org/secure/useravatar?size=large&ownerId=mia",
"24x24": "http://test.jira.org/secure/useravatar?size=small&ownerId=mia",
"16x16": "http://test.jira.org/secure/useravatar?size=xsmall&ownerId=mia",
"32x32": "http://test.jira.org/secure/useravatar?size=medium&ownerId=mia"
},
"displayName": "Mia Krystof",
"active": false
},
"jql": "assignee = currentUser() and resolution is empty",
"viewUrl": "http://test.jira.org/issues/?filter=10010",
"searchUrl": "http://test.jira.org/rest/api/3/search?jql=assignee+in+%28currentUser%28%29%29+and+resolution+is+empty",
"favourite": true,
"favouritedCount": 0,
"sharePermissions": [
{
"id": 10000,
"type": "global"
},
{
"id": 10010,
"type": "project",
"project": {
"self": "http://test.jira.org/rest/api/3/project/EX",
"id": "10000",
"key": "EX",
"name": "Example",
"avatarUrls": {
"48x48": "http://test.jira.org/secure/projectavatar?size=large&pid=10000",
"24x24": "http://test.jira.org/secure/projectavatar?size=small&pid=10000",
"16x16": "http://test.jira.org/secure/projectavatar?size=xsmall&pid=10000",
"32x32": "http://test.jira.org/secure/projectavatar?size=medium&pid=10000"
},
"projectCategory": {
"self": "http://test.jira.org/rest/api/3/projectCategory/10000",
"id": "10000",
"name": "FIRST",
"description": "First Project Category"
},
"simplified": false,
"style": "classic"
}
}
],
"subscriptions": {
"size": 0,
"items": [],
"max-results": 0,
"start-index": 0,
"end-index": 0
}
}
]

0 comments on commit ebae19d

Please sign in to comment.