mirror of
https://github.com/interviewstreet/go-jira.git
synced 2024-12-12 10:13:40 +02:00
67 lines
1.3 KiB
Go
67 lines
1.3 KiB
Go
|
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)
|
||
|
}
|
||
|
}
|