Skip to content

Instantly share code, notes, and snippets.

@lesnuages
Created September 28, 2022 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lesnuages/7bc36b744d1b96f4176473f2401e0bc5 to your computer and use it in GitHub Desktop.
Save lesnuages/7bc36b744d1b96f4176473f2401e0bc5 to your computer and use it in GitHub Desktop.
jira-client
package main
import (
"fmt"
"strings"
"time"
"github.com/andygrunwald/go-jira"
)
func printIssue(i jira.Issue) {
header := fmt.Sprintf("[%s] [%s] -- [%v] -- %s\n", i.Fields.Status.Name, i.Key, time.Time(i.Fields.Created).String(), i.Fields.Summary)
fmt.Print(header)
fmt.Println(strings.Repeat("=", len(header)))
fmt.Println(i.Fields.Description)
comments := i.Fields.Comments
if comments != nil {
fmt.Println("Comments:")
fmt.Println(strings.Repeat("~", len("Comments:")))
for _, c := range i.Fields.Comments.Comments {
if c != nil {
fmt.Println("--------------------------------------")
fmt.Println("Author:", c.Author.DisplayName)
fmt.Println("Date:", c.Created)
fmt.Println(c.Body)
}
}
}
}
func getRecent(client jira.Client, project string) {
opts := &jira.SearchOptions{
StartAt: 0,
MaxResults: 200,
Expand: "comments",
Fields: []string{"*all"},
}
issues, _, err := client.Issue.Search(fmt.Sprintf(`project = %s`, project), opts)
if err != nil {
panic(err)
}
for _, i := range issues {
printIssue(i)
fmt.Println()
fmt.Println()
}
}
func main() {
tp := jira.BasicAuthTransport{
Username: "CHANGEME",
Password: "CHANGEME",
}
client, err := jira.NewClient(tp.Client(), "https://CHANGEME")
if err != nil {
panic(err)
}
getRecent(*client, "TODO")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment