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

Added more visibility if jira command get html #468

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
111 changes: 103 additions & 8 deletions issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"mime/multipart"
"net/url"
"strings"
Expand Down Expand Up @@ -69,8 +70,32 @@ func GetIssue(ua HttpClient, endpoint string, issue string, iqg IssueQueryProvid

if resp.StatusCode == 200 {
results := &jiradata.Issue{}
return results, json.NewDecoder(resp.Body).Decode(results)
json_error := json.NewDecoder(resp.Body).Decode(results)
if json_error != nil {

log.Print("status Code: ", resp.Status, ", URL: ", uri)

bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
bodyString := string(bodyBytes)
log.Fatalf(bodyString)

}
return results, json_error
} else {

log.Print("status Code: ", resp.Status, ", URL: ", uri)
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
bodyString := string(bodyBytes)
log.Fatalf(bodyString)

}

return nil, responseError(resp)
}

Expand All @@ -95,14 +120,33 @@ func GetIssueWorklog(ua HttpClient, endpoint string, issue string) (*jiradata.Wo

if resp.StatusCode == 200 {
results := &jiradata.WorklogWithPagination{}
err := json.NewDecoder(resp.Body).Decode(results)
if err != nil {
return nil, err
json_error := json.NewDecoder(resp.Body).Decode(results)
if json_error != nil {

log.Print("status Code: ", resp.Status, ", URL: ", uri)

bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
bodyString := string(bodyBytes)
log.Fatalf(bodyString)

return nil, json_error

}
startAt = startAt + maxResults
total = results.Total
worklogs = append(worklogs, results.Worklogs...)
} else {
log.Print("status Code: ", resp.Status, ", URL: ", uri)
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
bodyString := string(bodyBytes)
log.Fatalf(bodyString)

return nil, responseError(resp)
}
}
Expand Down Expand Up @@ -130,14 +174,32 @@ func GetIssueComment(ua HttpClient, endpoint string, issue string) (*jiradata.Co

if resp.StatusCode == 200 {
results := &jiradata.CommentsWithPagination{}
err := json.NewDecoder(resp.Body).Decode(results)
if err != nil {
return nil, err
json_error := json.NewDecoder(resp.Body).Decode(results)
if json_error != nil {

log.Print("status Code: ", resp.Status, ", URL: ", uri)

bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
bodyString := string(bodyBytes)
log.Fatalf(bodyString)

return nil, json_error

}
startAt = startAt + maxResults
total = results.Total
comments = append(comments, results.Comments...)
} else {
log.Print("status Code: ", resp.Status, ", URL: ", uri)
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
bodyString := string(bodyBytes)
log.Fatalf(bodyString)
return nil, responseError(resp)
}
}
Expand Down Expand Up @@ -373,11 +435,20 @@ func TransitionIssue(ua HttpClient, endpoint string, issue string, iup IssueUpda
uri := URLJoin(endpoint, "rest/api/2/issue", issue, "transitions")
resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil {

log.Print("status Code: ", resp.Status, ", URL: ", uri)
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
bodyString := string(bodyBytes)
log.Fatalf(bodyString)
return err
}
defer resp.Body.Close()

if resp.StatusCode == 204 {

return nil
}
return responseError(resp)
Expand Down Expand Up @@ -530,13 +601,37 @@ func IssueAddComment(ua HttpClient, endpoint string, issue string, cp CommentPro
uri := URLJoin(endpoint, "rest/api/2/issue", issue, "comment")
resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil {

return nil, err
}
defer resp.Body.Close()

if resp.StatusCode == 201 {
results := jiradata.Comment{}
return &results, json.NewDecoder(resp.Body).Decode(&results)
json_error := json.NewDecoder(resp.Body).Decode(&results)
if json_error != nil {

log.Print("status Code: ", resp.Status, ", URL: ", uri)

bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
bodyString := string(bodyBytes)
log.Fatalf(bodyString)

}
return &results, json_error
} else {

log.Print("status Code: ", resp.Status, ", URL: ", uri)
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
bodyString := string(bodyBytes)
log.Fatalf(bodyString)

}
return nil, responseError(resp)
}
Expand Down