Skip to content

Commit

Permalink
add issuetypes command
Browse files Browse the repository at this point in the history
  • Loading branch information
coryb committed Aug 20, 2017
1 parent 0bd3ca2 commit da39323
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 48 deletions.
8 changes: 4 additions & 4 deletions cmd/jira/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ func main() {
Command: "components",
Entry: cli.CmdComponentsRegistry(),
},
jiracli.CommandRegistry{
Command: "issuetypes",
Entry: cli.CmdIssueTypesRegistry(),
},
}

cli.Register(app, registry)
Expand All @@ -255,7 +259,6 @@ func main() {
}

// Usage:
// jira issuetypes [-p PROJECT]
// jira export-templates [-d DIR] [-t template]
// jira (b|browse) ISSUE
// jira request [-M METHOD] URI [DATA]
Expand Down Expand Up @@ -304,7 +307,6 @@ func main() {
// }

// jiraCommands := map[string]string{
// "issuetypes": "issuetypes",
// "export-templates": "export-templates",
// "browse": "browse",
// "req": "request",
Expand Down Expand Up @@ -454,8 +456,6 @@ func main() {

// var err error
// switch command {
// case "issuetypes":
// err = c.CmdIssueTypes()
// case "browse":
// requireArgs(1)
// opts["browse"] = true
Expand Down
42 changes: 0 additions & 42 deletions jiracli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,48 +63,6 @@ func (jc *JiraCli) Register(app *kingpin.Application, reg []CommandRegistry) {
}
}

// // CmdIssueTypes will send issue 'create' metadata to the 'issuetypes'
// func (c *Cli) CmdIssueTypes() error {
// project := c.opts["project"].(string)
// log.Debugf("issueTypes called")
// uri := fmt.Sprintf("%s/rest/api/2/issue/createmeta?projectKeys=%s", c.endpoint, project)
// data, err := responseToJSON(c.get(uri))
// if err != nil {
// return err
// }

// return runTemplate(c.getTemplate("issuetypes"), data, nil)
// }

// func (c *Cli) defaultIssueType() string {
// project := c.opts["project"].(string)
// uri := fmt.Sprintf("%s/rest/api/2/issue/createmeta?projectKeys=%s", c.endpoint, project)
// data, _ := responseToJSON(c.get(uri))
// issueTypeNames := make(map[string]bool)

// if data, ok := data.(map[string]interface{}); ok {
// if projects, ok := data["projects"].([]interface{}); ok {
// for _, project := range projects {
// if project, ok := project.(map[string]interface{}); ok {
// if issuetypes, ok := project["issuetypes"].([]interface{}); ok {
// if len(issuetypes) > 0 {
// for _, issuetype := range issuetypes {
// issueTypeNames[issuetype.(map[string]interface{})["name"].(string)] = true
// }
// }
// }
// }
// }
// }
// }
// if _, ok := issueTypeNames["Bug"]; ok {
// return "Bug"
// } else if _, ok := issueTypeNames["Task"]; ok {
// return "Task"
// }
// return ""
// }

// // CmdExportTemplates will export the default templates to the template directory.
// func (c *Cli) CmdExportTemplates() error {
// dir := c.opts["directory"].(string)
Expand Down
52 changes: 52 additions & 0 deletions jiracli/issuetypes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package jiracli

import (
"fmt"

kingpin "gopkg.in/alecthomas/kingpin.v2"
)

type IssueTypesOptions struct {
GlobalOptions
Project string
}

func (jc *JiraCli) CmdIssueTypesRegistry() *CommandRegistryEntry {
opts := IssueTypesOptions{
GlobalOptions: GlobalOptions{
Template: "issuetypes",
},
}

return &CommandRegistryEntry{
"Show issue types for a project",
func() error {
return jc.CmdIssueTypes(&opts)
},
func(cmd *kingpin.CmdClause) error {
return jc.CmdIssueTypesUsage(cmd, &opts)
},
}
}

func (jc *JiraCli) CmdIssueTypesUsage(cmd *kingpin.CmdClause, opts *IssueTypesOptions) error {
if err := jc.GlobalUsage(cmd, &opts.GlobalOptions); err != nil {
return err
}
jc.TemplateUsage(cmd, &opts.GlobalOptions)
cmd.Flag("project", "project to list issueTypes").Short('p').StringVar(&opts.Project)

return nil
}

// CmdIssueTypes will get available issueTypes for project and send to the "issueTypes" template
func (jc *JiraCli) CmdIssueTypes(opts *IssueTypesOptions) error {
if opts.Project == "" {
return fmt.Errorf("Project Required.")
}
data, err := jc.GetIssueCreateMetaProject(opts.Project)
if err != nil {
return err
}
return jc.runTemplate(opts.Template, data, nil)
}
5 changes: 3 additions & 2 deletions jiracli/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,9 @@ description: {{or .description ""}}
leadUserName: {{or .leadUserName ""}}
`

const defaultIssuetypesTemplate = `{{ range .projects }}{{ range .issuetypes }}{{color "+bh"}}{{.name | append ":" | printf "%-13s" }}{{color "reset"}} {{.description}}
{{end}}{{end}}`
const defaultIssuetypesTemplate = `{{/* issuetypes template */ -}}
{{ range .issuetypes }}{{color "+bh"}}{{.name | append ":" | printf "%-13s" }}{{color "reset"}} {{.description}}
{{end}}`

const defaultCreateTemplate = `{{/* create template */ -}}
fields:
Expand Down

0 comments on commit da39323

Please sign in to comment.