Skip to content

Commit

Permalink
fix(#109): use appropriate filters api url for Jira Cloud instances
Browse files Browse the repository at this point in the history
  • Loading branch information
mk-5 committed Feb 6, 2024
1 parent 3fb0df0 commit be8a154
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ fjira jql

## My Jira Filters

You can search using your stored Jira Filters:
You can search using your stored (favourites) Jira Filters:

```shell
fjira filters
Expand Down
11 changes: 8 additions & 3 deletions internal/jira/jira_filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ type Filter struct {
}

const (
FilterUrl = "/rest/api/2/filter/%s"
MyFilterUrl = "/rest/api/2/filter/my"
FilterUrl = "/rest/api/2/filter/%s"
MyFilterUrl = "/rest/api/2/filter/my"
MyFilterUrlJiraServer = "/rest/api/2/filter/favourite"
)

func (api *httpApi) GetFilter(filterId string) (*Filter, error) {
Expand All @@ -31,7 +32,11 @@ func (api *httpApi) GetFilter(filterId string) (*Filter, error) {
}

func (api *httpApi) GetMyFilters() ([]Filter, error) {
resultBytes, err := api.jiraRequest("GET", MyFilterUrl, &nilParams{}, nil)
url := MyFilterUrl
if api.IsJiraServer() {
url = MyFilterUrlJiraServer
}
resultBytes, err := api.jiraRequest("GET", url, &nilParams{}, nil)
if err != nil {
return nil, err
}
Expand Down
14 changes: 8 additions & 6 deletions internal/jira/jira_filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import (

func Test_httpApi_GetFilter(t *testing.T) {
tests := []struct {
name string
want *Filter
wantErr bool
name string
want *Filter
tokenType JiraTokenType
wantErr bool
}{
{"should get filter", &Filter{Name: "Filter for FJIR board"}, false},
{"should get filter", &Filter{Name: "Filter for FJIR board"}, ApiToken, false},
{"should get filter", &Filter{Name: "Filter for FJIR board"}, PersonalToken, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
api := NewJiraApiMock(func(w http.ResponseWriter, r *http.Request) {
api := NewJiraApiMockWithTokenType(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
body := `
{
Expand Down Expand Up @@ -85,7 +87,7 @@ func Test_httpApi_GetFilter(t *testing.T) {
}
`
w.Write([]byte(body)) //nolint:errcheck
})
}, tt.tokenType)
got, err := api.GetFilter("10006")
if (err != nil) != tt.wantErr {
t.Errorf("GetFilter() error = %v, wantErr %v", err, tt.wantErr)
Expand Down

0 comments on commit be8a154

Please sign in to comment.