mirror of
https://github.com/Threnklyn/jira.git
synced 2026-05-18 20:23:28 +02:00
add issuetypes command
This commit is contained in:
+4
-4
@@ -237,6 +237,10 @@ func main() {
|
||||
Command: "components",
|
||||
Entry: cli.CmdComponentsRegistry(),
|
||||
},
|
||||
jiracli.CommandRegistry{
|
||||
Command: "issuetypes",
|
||||
Entry: cli.CmdIssueTypesRegistry(),
|
||||
},
|
||||
}
|
||||
|
||||
cli.Register(app, registry)
|
||||
@@ -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]
|
||||
@@ -304,7 +307,6 @@ func main() {
|
||||
// }
|
||||
|
||||
// jiraCommands := map[string]string{
|
||||
// "issuetypes": "issuetypes",
|
||||
// "export-templates": "export-templates",
|
||||
// "browse": "browse",
|
||||
// "req": "request",
|
||||
@@ -454,8 +456,6 @@ func main() {
|
||||
|
||||
// var err error
|
||||
// switch command {
|
||||
// case "issuetypes":
|
||||
// err = c.CmdIssueTypes()
|
||||
// case "browse":
|
||||
// requireArgs(1)
|
||||
// opts["browse"] = true
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user