mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-01-22 03:10:10 +02:00
added executable searchpages example
This commit is contained in:
parent
83c019a2fa
commit
5202530abe
62
examples/searchpages/main.go
Normal file
62
examples/searchpages/main.go
Normal file
@ -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)
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user