Skip to content

Commit

Permalink
default issuetype to "Bug" for project that have Bug, otherwise try "…
Browse files Browse the repository at this point in the history
…Task"
  • Loading branch information
coryb committed Aug 3, 2016
1 parent 8238fe8 commit 0c807b4
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,41 @@ func (c *Cli) CmdIssueTypes() error {
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 ""
}

func (c *Cli) CmdCreateMeta() error {
project := c.opts["project"].(string)
issuetype := c.getOptString("issuetype", "Bug")
issuetype := c.getOptString("issuetype", "")
if issuetype == "" {
issuetype = c.defaultIssueType()
}

log.Debugf("createMeta called")
uri := fmt.Sprintf("%s/rest/api/2/issue/createmeta?projectKeys=%s&issuetypeNames=%s&expand=projects.issuetypes.fields", c.endpoint, project, url.QueryEscape(issuetype))
Expand Down Expand Up @@ -241,9 +273,12 @@ func (c *Cli) CmdTransitions(issue string) error {
}

func (c *Cli) CmdCreate() error {
project := c.opts["project"].(string)
issuetype := c.getOptString("issuetype", "Bug")
log.Debugf("create called")
project := c.opts["project"].(string)
issuetype := c.getOptString("issuetype", "")
if issuetype == "" {
issuetype = c.defaultIssueType()
}

uri := fmt.Sprintf("%s/rest/api/2/issue/createmeta?projectKeys=%s&issuetypeNames=%s&expand=projects.issuetypes.fields", c.endpoint, project, url.QueryEscape(issuetype))
data, err := responseToJson(c.get(uri))
Expand Down

0 comments on commit 0c807b4

Please sign in to comment.