1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2025-05-31 22:49:43 +02:00

Added support for the 'expand:renderfields' option

A couple of fields can be rendered server side, especially the ones
related to dates (that can become string like "2 hours ago"), and the
comments body that can be expanded from JIRA wiki markup into HTML.
A new type IssueRenderedFields has been introduced with a couple of
fields that can be expanded.
This commit is contained in:
Frederick Ros 2018-06-03 23:42:41 +02:00
parent 05574a46ff
commit 6b32ea13a0
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