Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Netflix-Skunkworks/go-jira
Browse files Browse the repository at this point in the history
  • Loading branch information
coryb committed Jan 29, 2016
2 parents 382bf4f + 20b32c2 commit 9e90376
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"net/url"
"os"
"os/exec"
"path"
"runtime"
"strings"
"time"
Expand Down Expand Up @@ -87,6 +88,7 @@ func (c *Cli) saveCookies(cookies []*http.Cookie) {
}
jsonWrite(c.cookieFile, mergedCookies)
} else {
mkdir(path.Dir(c.cookieFile))
jsonWrite(c.cookieFile, cookies)
}
}
Expand Down
54 changes: 54 additions & 0 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package jira

import (
"bytes"
"errors"
"fmt"
"golang.org/x/crypto/ssh/terminal"
"net/http"
Expand Down Expand Up @@ -200,6 +201,16 @@ func (c *Cli) CmdCreateMeta() error {
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 {
log.Debug("Transitions called")
c.Browse(issue)
Expand Down Expand Up @@ -606,6 +617,49 @@ func (c *Cli) CmdComment(issue string) error {
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 {
log.Debug("label called")

Expand Down
21 changes: 21 additions & 0 deletions main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ Usage:
jira issuelinktypes
jira transmeta ISSUE
jira editmeta ISSUE
jira add component [-p PROJECT] NAME DESCRIPTION LEAD
jira components [-p PROJECT]
jira issuetypes [-p PROJECT]
jira createmeta [-p PROJECT] [-i ISSUETYPE]
jira transitions ISSUE
Expand Down Expand Up @@ -141,6 +143,8 @@ Command Options:
"comment": "comment",
"label": "labels",
"labels": "labels",
"component": "component",
"components": "components",
"take": "take",
"assign": "assign",
"give": "assign",
Expand Down Expand Up @@ -395,6 +399,23 @@ Command Options:
issue := args[1]
labels := args[2:]
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":
requireArgs(1)
err = c.CmdAssign(args[0], opts["user"].(string))
Expand Down
4 changes: 4 additions & 0 deletions templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var all_templates = map[string]string{
"view": default_view_template,
"edit": default_edit_template,
"transitions": default_transitions_template,
"components": default_components_template,
"issuetypes": default_issuetypes_template,
"create": default_create_template,
"comment": default_comment_template,
Expand Down Expand Up @@ -82,6 +83,9 @@ fields:
const default_transitions_template = `{{ range .transitions }}{{.id }}: {{.name}}
{{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}}
{{end}}{{end}}`

Expand Down

0 comments on commit 9e90376

Please sign in to comment.