Skip to content

Commit

Permalink
added executable searchpages example
Browse files Browse the repository at this point in the history
  • Loading branch information
c2rad authored and andygrunwald committed Nov 18, 2018
1 parent 83c019a commit 5202530
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions examples/searchpages/main.go
@@ -0,0 +1,62 @@
package main

import (
"bufio"
"fmt"
jira "github.com/andygrunwald/go-jira"
"golang.org/x/crypto/ssh/terminal"
"log"
"os"
"strings"
"syscall"
"time"
)

func main() {
r := bufio.NewReader(os.Stdin)

fmt.Print("Jira URL: ")
jiraURL, _ := r.ReadString('\n')

fmt.Print("Jira Username: ")
username, _ := r.ReadString('\n')

fmt.Print("Jira Password: ")
bytePassword, _ := terminal.ReadPassword(int(syscall.Stdin))
password := string(bytePassword)

fmt.Print("\nJira Project Key: ") // e.g. TES or WOW
jiraPK, _ := r.ReadString('\n')

tp := jira.BasicAuthTransport{
Username: strings.TrimSpace(username),
Password: strings.TrimSpace(password),
}

client, err := jira.NewClient(tp.Client(), strings.TrimSpace(jiraURL))
if err != nil {
log.Fatal(err)
}

var issues []jira.Issue

// appendFunc will append jira issues to []jira.Issue
appendFunc := func(i jira.Issue) (err error) {
issues = append(issues, i)
return err
}

// SearchPages will page through results and pass each issue to appendFunc
// In this example, we'll search for all the issues in the target project
client.Issue.SearchPages(fmt.Sprintf(`project=%s`, strings.TrimSpace(jiraPK)), nil, appendFunc)

fmt.Printf("%d issues found.\n", len(issues))

for _, i := range issues {
t := time.Time(i.Fields.Created) // convert go-jira.Time to time.Time for manipulation
date := t.Format("2006-01-02")
clock := t.Format("15:04")
fmt.Printf("Creation Date: %s\nCreation Time: %s\nIssue Key: %s\nIssue Summary: %s\n\n", date, clock, i.Key, i.Fields.Summary)
}

}

0 comments on commit 5202530

Please sign in to comment.