1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2025-02-09 13:36:58 +02:00

Merge pull request #139 from sleeper/renderedfields

Renderedfields support
This commit is contained in:
rbriski 2018-06-04 13:54:41 -07:00 committed by GitHub
commit 98ede9f81c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 121 additions and 6 deletions

View File

@ -0,0 +1,66 @@
package main
import (
"bufio"
"fmt"
"net/http"
"os"
"strings"
"syscall"
jira "github.com/andygrunwald/go-jira"
"golang.org/x/crypto/ssh/terminal"
)
func main() {
r := bufio.NewReader(os.Stdin)
fmt.Print("Jira URL: ")
jiraURL, _ := r.ReadString('\n')
fmt.Print("Jira Issue key: ")
key, _ := r.ReadString('\n')
key = strings.TrimSpace(key)
fmt.Print("Jira Username: ")
username, _ := r.ReadString('\n')
fmt.Print("Jira Password: ")
bytePassword, _ := terminal.ReadPassword(int(syscall.Stdin))
password := string(bytePassword)
var tp *http.Client
if strings.TrimSpace(username) == "" {
tp = nil
} else {
ba := jira.BasicAuthTransport{
Username: strings.TrimSpace(username),
Password: strings.TrimSpace(password),
}
tp = ba.Client()
}
client, err := jira.NewClient(tp, strings.TrimSpace(jiraURL))
if err != nil {
fmt.Printf("\nerror: %v\n", err)
return
}
fmt.Printf("Targetting %s for issue %s\n", strings.TrimSpace(jiraURL), key)
options := &jira.GetQueryOptions{Expand: "renderedFields"}
u, _, err := client.Issue.Get(key, options)
if err != nil {
fmt.Printf("\n==> error: %v\n", err)
return
}
fmt.Printf("RenderedFields: %+v\n", *u.RenderedFields)
for _, c := range u.RenderedFields.Comments.Comments {
fmt.Printf(" %+v\n", c)
}
}

View File

@ -31,12 +31,13 @@ type IssueService struct {
// Issue represents a JIRA issue.
type Issue struct {
Expand string `json:"expand,omitempty" structs:"expand,omitempty"`
ID string `json:"id,omitempty" structs:"id,omitempty"`
Self string `json:"self,omitempty" structs:"self,omitempty"`
Key string `json:"key,omitempty" structs:"key,omitempty"`
Fields *IssueFields `json:"fields,omitempty" structs:"fields,omitempty"`
Changelog *Changelog `json:"changelog,omitempty" structs:"changelog,omitempty"`
Expand string `json:"expand,omitempty" structs:"expand,omitempty"`
ID string `json:"id,omitempty" structs:"id,omitempty"`
Self string `json:"self,omitempty" structs:"self,omitempty"`
Key string `json:"key,omitempty" structs:"key,omitempty"`
Fields *IssueFields `json:"fields,omitempty" structs:"fields,omitempty"`
RenderedFields *IssueRenderedFields `json:"renderedFields,omitempty" structs:"renderedFields,omitempty"`
Changelog *Changelog `json:"changelog,omitempty" structs:"changelog,omitempty"`
}
// ChangelogItems reflects one single changelog item of a history item
@ -196,6 +197,23 @@ func (i *IssueFields) UnmarshalJSON(data []byte) error {
}
// IssueRenderedFields represents rendered fields of a JIRA issue.
// Not all IssueFields are rendered.
type IssueRenderedFields struct {
// TODO Missing fields
// * "aggregatetimespent": null,
// * "workratio": -1,
// * "lastViewed": null,
// * "aggregatetimeoriginalestimate": null,
// * "aggregatetimeestimate": null,
// * "environment": null,
Resolutiondate string `json:"resolutiondate,omitempty" structs:"resolutiondate,omitempty"`
Created string `json:"created,omitempty" structs:"created,omitempty"`
Duedate string `json:"duedate,omitempty" structs:"duedate,omitempty"`
Updated string `json:"updated,omitempty" structs:"updated,omitempty"`
Comments *Comments `json:"comment,omitempty" structs:"comment,omitempty"`
}
// IssueType represents a type of a JIRA issue.
// Typical types are "Request", "Bug", "Story", ...
type IssueType struct {

File diff suppressed because one or more lines are too long