Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WTF-1070 Read response body data before closing #1071

Merged
merged 1 commit into from
Mar 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions modules/jira/client.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package jira

import (
"bytes"
"crypto/tls"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strings"

"github.com/wtfutil/wtf/utils"
)

// IssuesFor returns a collection of issues for a given collection of projects.
// If username is provided, it scopes the issues to that person
func (widget *Widget) IssuesFor(username string, projects []string, jql string) (*SearchResult, error) {
query := []string{}

Expand Down Expand Up @@ -38,7 +42,7 @@ func (widget *Widget) IssuesFor(username string, projects []string, jql string)
}

searchResult := &SearchResult{}
err = utils.ParseJSON(searchResult, resp.Body)
err = utils.ParseJSON(searchResult, bytes.NewReader(resp))
if err != nil {
return nil, err
}
Expand All @@ -52,7 +56,7 @@ func buildJql(key string, value string) string {

/* -------------------- Unexported Functions -------------------- */

func (widget *Widget) jiraRequest(path string) (*http.Response, error) {
func (widget *Widget) jiraRequest(path string) ([]byte, error) {
url := fmt.Sprintf("%s%s", widget.settings.domain, path)

req, err := http.NewRequest("GET", url, nil)
Expand All @@ -61,13 +65,15 @@ func (widget *Widget) jiraRequest(path string) (*http.Response, error) {
}
req.SetBasicAuth(widget.settings.email, widget.settings.apiKey)

httpClient := &http.Client{Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: !widget.settings.verifyServerCertificate,
httpClient := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: !widget.settings.verifyServerCertificate,
},
Proxy: http.ProxyFromEnvironment,
},
Proxy: http.ProxyFromEnvironment,
},
}

resp, err := httpClient.Do(req)
if err != nil {
return nil, err
Expand All @@ -78,7 +84,12 @@ func (widget *Widget) jiraRequest(path string) (*http.Response, error) {
return nil, fmt.Errorf(resp.Status)
}

return resp, nil
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}

return body, nil
}

func getProjectQuery(projects []string) string {
Expand Down