Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added executable searchpages example
- Loading branch information
1 parent
83c019a
commit 5202530
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
|
||
} |