From bcc9b06ac4a610dce8a7b191286cec18cfdcbaec Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Wed, 29 Aug 2018 18:17:00 -0400 Subject: [PATCH] Specifying Jira Issuetype in config.yaml (#53) * Jira integration documentation improved. Added ability to specify what type of issue to create in Jira * Apparently, Go doesn't like http/https in front of package name in --- README.md | 18 +++++++++++++++++- example/comply.yml.example | 8 ++++++++ internal/jira/jira.go | 10 ++++++++-- internal/model/plugin.go | 5 ++++- 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d7d0dfc..d08d20c 100644 --- a/README.md +++ b/README.md @@ -82,12 +82,28 @@ COMMANDS: - Github - Gitlab +## Configuring Jira +When comply creates a ticket (through `proc`, for instance), it sets the following fields. + +- assignee +- description +- issuetype +- labels +- project key +- reporter +- summary + +Please make sure that the default *Create Screen* has all of those fields enabled. Additionally, make sure that there are no other required fields for the issue type you choose. + + + + ## Forking and local development > Assumes installation of golang and configuration of GOPATH in .bash_profile, .zshrc, etc > Inspiration: http://code.openark.org/blog/development/forking-golang-repositories-on-github-and-managing-the-import-path ``` -$ go get http://github.com/strongdm/comply +$ go get github.com/strongdm/comply $ cd $GOPATH/src/github.com/strongdm/comply ; go get ./... $ make $ cd example diff --git a/example/comply.yml.example b/example/comply.yml.example index f2e2cbb..e037a62 100644 --- a/example/comply.yml.example +++ b/example/comply.yml.example @@ -5,6 +5,14 @@ tickets: token: XXX username: strongdm repo: comply + # jira: + # username: xxxx # This is the username you log in to Jira's UI with. Probably your email address. + # password: xxxx # If you don't have a "managed account", use your password in this field. But if your organization + # # uses SAML or OAuth, or Jira's built-in multi-factor authentication, you need to use + # # an API token. Learn more here: https://confluence.atlassian.com/cloud/api-tokens-938839638.html + # project: comply + # url: https://yourjira + # taskType: Task # This must be an Issue, not a sub-task # gitlab: # domain: https://gitlab.example.com:443/ # or https://gitlab.com/ # token: token-here diff --git a/internal/jira/jira.go b/internal/jira/jira.go index b68bb3e..7c9aba4 100644 --- a/internal/jira/jira.go +++ b/internal/jira/jira.go @@ -16,6 +16,7 @@ const ( cfgPassword = "password" cfgURL = "url" cfgProject = "project" + cfgTaskType = "taskType" ) var prompts = map[string]string{ @@ -23,6 +24,7 @@ var prompts = map[string]string{ cfgPassword: "Jira Password", cfgURL: "Jira URL", cfgProject: "Jira Project Code", + cfgTaskType: "Jira Task Type", } // Prompts are human-readable configuration element names @@ -40,6 +42,7 @@ type jiraPlugin struct { password string url string project string + taskType string clientMu sync.Mutex client *jira.Client @@ -66,7 +69,7 @@ func (j *jiraPlugin) Get(ID string) (*model.Ticket, error) { } func (j *jiraPlugin) Configured() bool { - return j.username != "" && j.password != "" && j.url != "" && j.project != "" + return j.username != "" && j.password != "" && j.url != "" && j.project != "" && j.taskType != "" } func (j *jiraPlugin) Links() model.TicketLinks { @@ -93,6 +96,9 @@ func (j *jiraPlugin) Configure(cfg map[string]interface{}) error { if j.project, err = getCfg(cfg, cfgProject); err != nil { return err } + if j.taskType, err = getCfg(cfg, cfgTaskType); err != nil { + return err + } return nil } @@ -134,7 +140,7 @@ func (j *jiraPlugin) Create(ticket *model.Ticket, labels []string) error { i := jira.Issue{ Fields: &jira.IssueFields{ Type: jira.IssueType{ - Name: "Task", + Name: j.taskType, }, Project: jira.Project{ Key: j.project, diff --git a/internal/model/plugin.go b/internal/model/plugin.go index 24a7535..9a879a3 100644 --- a/internal/model/plugin.go +++ b/internal/model/plugin.go @@ -87,7 +87,10 @@ func GetPlugin(ts TicketSystem) TicketPlugin { } cfgStringed[kS] = v } - tp.Configure(cfgStringed) + err := tp.Configure(cfgStringed) + if( err != nil) { + panic(fmt.Sprintf("Configuration error `%s` in project YAML", err)) + } } }) }