Skip to content

Commit

Permalink
Merge pull request #358 from manuelbcd/new-example-create-with-custom…
Browse files Browse the repository at this point in the history
…-fields

Added example "Create with custom fields"
  • Loading branch information
benjivesterby authored Mar 4, 2021
2 parents c77a7ee + 7e1d26c commit 0779eb2
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
74 changes: 74 additions & 0 deletions examples/createwithcustomfields/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package main

import (
"bufio"
"fmt"
"os"
"strings"
"syscall"

jira "github.com/andygrunwald/go-jira"
"github.com/trivago/tgo/tcontainer"
"golang.org/x/term"
)

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, _ := term.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)
os.Exit(1)
}

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, _, err := client.Issue.Create(&i)
if err != nil {
panic(err)
}

fmt.Printf("%s: %v\n", issue.Key, issue.Self)
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit 0779eb2

Please sign in to comment.