From c2a046111c39652faae1045787ca6f2490a19646 Mon Sep 17 00:00:00 2001 From: manuelbcd Date: Wed, 3 Mar 2021 23:09:30 +0000 Subject: [PATCH 1/2] Added example --- examples/createwithcustomfields/main.go | 76 +++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 examples/createwithcustomfields/main.go diff --git a/examples/createwithcustomfields/main.go b/examples/createwithcustomfields/main.go new file mode 100644 index 00000000..365b1518 --- /dev/null +++ b/examples/createwithcustomfields/main.go @@ -0,0 +1,76 @@ +package main + +import ( + "bufio" + "fmt" + "io/ioutil" + "os" + "strings" + "syscall" + + jira "github.com/andygrunwald/go-jira" + "github.com/trivago/tgo/tcontainer" + "golang.org/x/crypto/ssh/terminal" +) + +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("Custom field name (i.e. customfield_10220): ") + customFieldName, _ := r.ReadString('\n') + + fmt.Print("Custom field value: ") + customFieldValue, _ := 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 { + fmt.Printf("\nerror: %v\n", err) + return + } + + unknowns := tcontainer.NewMarshalMap() + unknowns[customFieldName] = customFieldValue + + i := jira.Issue{ + Fields: &jira.IssueFields{ + Assignee: &jira.User{ + Name: "myuser", + }, + Reporter: &jira.User{ + Name: "youruser", + }, + Description: "Test Issue", + Type: jira.IssueType{ + Name: "Bug", + }, + Project: jira.Project{ + Key: "PROJ1", + }, + Summary: "Just a demo issue", + Unknowns: unknowns, + }, + } + + issue, resp, err := client.Issue.Create(&i) + if err != nil { + _, err := ioutil.ReadAll(resp.Body) + panic(err) + } + + fmt.Printf("%s: %v\n", issue.Key, issue.Self) +} From 7e1d26c27b33d3a96a505809b90ada6bde821d26 Mon Sep 17 00:00:00 2001 From: manuelbcd Date: Thu, 4 Mar 2021 10:58:08 +0000 Subject: [PATCH 2/2] PR 358 - x/term.ReadPassword and os.Exit --- examples/createwithcustomfields/main.go | 10 ++++------ go.mod | 1 + 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/examples/createwithcustomfields/main.go b/examples/createwithcustomfields/main.go index 365b1518..2a6922a3 100644 --- a/examples/createwithcustomfields/main.go +++ b/examples/createwithcustomfields/main.go @@ -3,14 +3,13 @@ package main import ( "bufio" "fmt" - "io/ioutil" "os" "strings" "syscall" jira "github.com/andygrunwald/go-jira" "github.com/trivago/tgo/tcontainer" - "golang.org/x/crypto/ssh/terminal" + "golang.org/x/term" ) func main() { @@ -23,7 +22,7 @@ func main() { username, _ := r.ReadString('\n') fmt.Print("Jira Password: ") - bytePassword, _ := terminal.ReadPassword(int(syscall.Stdin)) + bytePassword, _ := term.ReadPassword(int(syscall.Stdin)) password := string(bytePassword) fmt.Print("Custom field name (i.e. customfield_10220): ") @@ -40,7 +39,7 @@ func main() { client, err := jira.NewClient(tp.Client(), strings.TrimSpace(jiraURL)) if err != nil { fmt.Printf("\nerror: %v\n", err) - return + os.Exit(1) } unknowns := tcontainer.NewMarshalMap() @@ -66,9 +65,8 @@ func main() { }, } - issue, resp, err := client.Issue.Create(&i) + issue, _, err := client.Issue.Create(&i) if err != nil { - _, err := ioutil.ReadAll(resp.Body) panic(err) } diff --git a/go.mod b/go.mod index d393dfa9..c53c23c1 100644 --- a/go.mod +++ b/go.mod @@ -10,4 +10,5 @@ require ( github.com/pkg/errors v0.9.1 github.com/trivago/tgo v1.0.7 golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734 + golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d )