mirror of
https://github.com/Threnklyn/jira.git
synced 2026-06-06 04:58:30 +02:00
Merge pull request #31 from mikepea/component_mgmt
Add component/components support: add and list for now.
This commit is contained in:
+54
@@ -2,6 +2,7 @@ package jira
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"golang.org/x/crypto/ssh/terminal"
|
"golang.org/x/crypto/ssh/terminal"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -200,6 +201,16 @@ func (c *Cli) CmdCreateMeta() error {
|
|||||||
return runTemplate(c.getTemplate("createmeta"), data, nil)
|
return runTemplate(c.getTemplate("createmeta"), data, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Cli) CmdComponents(project string) error {
|
||||||
|
log.Debug("Components called")
|
||||||
|
uri := fmt.Sprintf("%s/rest/api/2/project/%s/components", c.endpoint, project)
|
||||||
|
data, err := responseToJson(c.get(uri))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return runTemplate(c.getTemplate("components"), data, nil)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Cli) CmdTransitions(issue string) error {
|
func (c *Cli) CmdTransitions(issue string) error {
|
||||||
log.Debug("Transitions called")
|
log.Debug("Transitions called")
|
||||||
c.Browse(issue)
|
c.Browse(issue)
|
||||||
@@ -606,6 +617,49 @@ func (c *Cli) CmdComment(issue string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Cli) CmdComponent(action string, project string, name string, desc string, lead string) error {
|
||||||
|
log.Debug("component called")
|
||||||
|
|
||||||
|
switch action {
|
||||||
|
case "add":
|
||||||
|
default:
|
||||||
|
return errors.New(fmt.Sprintf("CmdComponent: %q is not a valid action", action))
|
||||||
|
}
|
||||||
|
|
||||||
|
json, err := jsonEncode(map[string]interface{}{
|
||||||
|
"name": name,
|
||||||
|
"description": desc,
|
||||||
|
"leadUserName": lead,
|
||||||
|
"project": project,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
uri := fmt.Sprintf("%s/rest/api/2/component", c.endpoint)
|
||||||
|
if c.getOptBool("dryrun", false) {
|
||||||
|
log.Debug("POST: %s", json)
|
||||||
|
log.Debug("Dryrun mode, skipping POST")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
resp, err := c.post(uri, json)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if resp.StatusCode == 201 {
|
||||||
|
if !c.opts["quiet"].(bool) {
|
||||||
|
fmt.Printf("OK %s %s\n", project, name)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logBuffer := bytes.NewBuffer(make([]byte, 0))
|
||||||
|
resp.Write(logBuffer)
|
||||||
|
err := fmt.Errorf("Unexpected Response From POST")
|
||||||
|
log.Error("%s:\n%s", err, logBuffer)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Cli) CmdLabels(action string, issue string, labels []string) error {
|
func (c *Cli) CmdLabels(action string, issue string, labels []string) error {
|
||||||
log.Debug("label called")
|
log.Debug("label called")
|
||||||
|
|
||||||
|
|||||||
@@ -73,6 +73,8 @@ Usage:
|
|||||||
jira issuelinktypes
|
jira issuelinktypes
|
||||||
jira transmeta ISSUE
|
jira transmeta ISSUE
|
||||||
jira editmeta ISSUE
|
jira editmeta ISSUE
|
||||||
|
jira add component [-p PROJECT] NAME DESCRIPTION LEAD
|
||||||
|
jira components [-p PROJECT]
|
||||||
jira issuetypes [-p PROJECT]
|
jira issuetypes [-p PROJECT]
|
||||||
jira createmeta [-p PROJECT] [-i ISSUETYPE]
|
jira createmeta [-p PROJECT] [-i ISSUETYPE]
|
||||||
jira transitions ISSUE
|
jira transitions ISSUE
|
||||||
@@ -141,6 +143,8 @@ Command Options:
|
|||||||
"comment": "comment",
|
"comment": "comment",
|
||||||
"label": "labels",
|
"label": "labels",
|
||||||
"labels": "labels",
|
"labels": "labels",
|
||||||
|
"component": "component",
|
||||||
|
"components": "components",
|
||||||
"take": "take",
|
"take": "take",
|
||||||
"assign": "assign",
|
"assign": "assign",
|
||||||
"give": "assign",
|
"give": "assign",
|
||||||
@@ -395,6 +399,23 @@ Command Options:
|
|||||||
issue := args[1]
|
issue := args[1]
|
||||||
labels := args[2:]
|
labels := args[2:]
|
||||||
err = c.CmdLabels(action, issue, labels)
|
err = c.CmdLabels(action, issue, labels)
|
||||||
|
case "component":
|
||||||
|
requireArgs(2)
|
||||||
|
action := args[0]
|
||||||
|
project := opts["project"].(string)
|
||||||
|
name := args[1]
|
||||||
|
var lead string
|
||||||
|
var description string
|
||||||
|
if len(args) > 2 {
|
||||||
|
description = args[2]
|
||||||
|
}
|
||||||
|
if len(args) > 3 {
|
||||||
|
lead = args[2]
|
||||||
|
}
|
||||||
|
err = c.CmdComponent(action, project, name, description, lead)
|
||||||
|
case "components":
|
||||||
|
project := opts["project"].(string)
|
||||||
|
err = c.CmdComponents(project)
|
||||||
case "take":
|
case "take":
|
||||||
requireArgs(1)
|
requireArgs(1)
|
||||||
err = c.CmdAssign(args[0], opts["user"].(string))
|
err = c.CmdAssign(args[0], opts["user"].(string))
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ var all_templates = map[string]string{
|
|||||||
"view": default_view_template,
|
"view": default_view_template,
|
||||||
"edit": default_edit_template,
|
"edit": default_edit_template,
|
||||||
"transitions": default_transitions_template,
|
"transitions": default_transitions_template,
|
||||||
|
"components": default_components_template,
|
||||||
"issuetypes": default_issuetypes_template,
|
"issuetypes": default_issuetypes_template,
|
||||||
"create": default_create_template,
|
"create": default_create_template,
|
||||||
"comment": default_comment_template,
|
"comment": default_comment_template,
|
||||||
@@ -82,6 +83,9 @@ fields:
|
|||||||
const default_transitions_template = `{{ range .transitions }}{{.id }}: {{.name}}
|
const default_transitions_template = `{{ range .transitions }}{{.id }}: {{.name}}
|
||||||
{{end}}`
|
{{end}}`
|
||||||
|
|
||||||
|
const default_components_template = `{{ range . }}{{.id }}: {{.name}}
|
||||||
|
{{end}}`
|
||||||
|
|
||||||
const default_issuetypes_template = `{{ range .projects }}{{ range .issuetypes }}{{color "+bh"}}{{.name | append ":" | printf "%-13s" }}{{color "reset"}} {{.description}}
|
const default_issuetypes_template = `{{ range .projects }}{{ range .issuetypes }}{{color "+bh"}}{{.name | append ":" | printf "%-13s" }}{{color "reset"}} {{.description}}
|
||||||
{{end}}{{end}}`
|
{{end}}{{end}}`
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user