mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-02-03 13:11:49 +02:00
fix(issue): IssueService.Search() with a not empty JQL triggers 400 bad request (#292)
The JQL search term is escaped twice. closes issue #291
This commit is contained in:
parent
4b91cf2b13
commit
8b64c7f005
42
examples/jql/main.go
Normal file
42
examples/jql/main.go
Normal file
@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
jira "github.com/andygrunwald/go-jira"
|
||||
)
|
||||
|
||||
func main() {
|
||||
jiraClient, _ := jira.NewClient(nil, "https://issues.apache.org/jira/")
|
||||
|
||||
// Running JQL query
|
||||
|
||||
jql := "project = Mesos and type = Bug and Status NOT IN (Resolved)"
|
||||
fmt.Printf("Usecase: Running a JQL query '%s'\n", jql)
|
||||
issues, resp, err := jiraClient.Issue.Search(jql, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
outputResponse(issues, resp)
|
||||
|
||||
fmt.Println("")
|
||||
fmt.Println("")
|
||||
|
||||
// Running an empty JQL query to get all tickets
|
||||
jql = ""
|
||||
fmt.Printf("Usecase: Running an empty JQL query to get all tickets\n")
|
||||
issues, resp, err = jiraClient.Issue.Search(jql, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
outputResponse(issues, resp)
|
||||
}
|
||||
|
||||
func outputResponse(issues []jira.Issue, resp *jira.Response) {
|
||||
fmt.Printf("Call to %s\n", resp.Request.URL)
|
||||
fmt.Printf("Response Code: %d\n", resp.StatusCode)
|
||||
fmt.Println("==================================")
|
||||
for _, i := range issues {
|
||||
fmt.Printf("%s (%s/%s): %+v\n", i.Key, i.Fields.Type.Name, i.Fields.Priority.Name, i.Fields.Summary)
|
||||
}
|
||||
}
|
2
issue.go
2
issue.go
@ -963,7 +963,7 @@ func (s *IssueService) Search(jql string, options *SearchOptions) ([]Issue, *Res
|
||||
}
|
||||
uv := url.Values{}
|
||||
if jql != "" {
|
||||
uv.Add("jql", url.QueryEscape(jql))
|
||||
uv.Add("jql", jql)
|
||||
}
|
||||
|
||||
if options != nil {
|
||||
|
@ -598,13 +598,13 @@ func TestIssueService_Search(t *testing.T) {
|
||||
defer teardown()
|
||||
testMux.HandleFunc("/rest/api/2/search", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, "GET")
|
||||
testRequestURL(t, r, "/rest/api/2/search?expand=foo&jql=something&maxResults=40&startAt=1")
|
||||
testRequestURL(t, r, "/rest/api/2/search?expand=foo&jql=type+%3D+Bug+and+Status+NOT+IN+%28Resolved%29&maxResults=40&startAt=1")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprint(w, `{"expand": "schema,names","startAt": 1,"maxResults": 40,"total": 6,"issues": [{"expand": "html","id": "10230","self": "http://kelpie9:8081/rest/api/2/issue/BULK-62","key": "BULK-62","fields": {"summary": "testing","timetracking": null,"issuetype": {"self": "http://kelpie9:8081/rest/api/2/issuetype/5","id": "5","description": "The sub-task of the issue","iconUrl": "http://kelpie9:8081/images/icons/issue_subtask.gif","name": "Sub-task","subtask": true},"customfield_10071": null}},{"expand": "html","id": "10004","self": "http://kelpie9:8081/rest/api/2/issue/BULK-47","key": "BULK-47","fields": {"summary": "Cheese v1 2.0 issue","timetracking": null,"issuetype": {"self": "http://kelpie9:8081/rest/api/2/issuetype/3","id": "3","description": "A task that needs to be done.","iconUrl": "http://kelpie9:8081/images/icons/task.gif","name": "Task","subtask": false}}}]}`)
|
||||
})
|
||||
|
||||
opt := &SearchOptions{StartAt: 1, MaxResults: 40, Expand: "foo"}
|
||||
_, resp, err := testClient.Issue.Search("something", opt)
|
||||
_, resp, err := testClient.Issue.Search("type = Bug and Status NOT IN (Resolved)", opt)
|
||||
|
||||
if resp == nil {
|
||||
t.Errorf("Response given: %+v", resp)
|
||||
|
Loading…
x
Reference in New Issue
Block a user