diff --git a/.gitignore b/.gitignore index cd633f9..2ce1f1c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ src/github.com/mgutz/ src/github.com/op/ src/gopkg.in/ jira -jira.exe \ No newline at end of file +jira.exe +schemas/*.json \ No newline at end of file diff --git a/README.md b/README.md index 8a549da..a6e57db 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Join the chat at https://gitter.im/go-jira-cli/Lobby](https://badges.gitter.im/go-jira-cli/Lobby.svg)](https://gitter.im/go-jira-cli/Lobby?utm_source=badge&utm_medium=badge&utm_content=badge) +[![Join the chat at https://gitter.im/go-jira-cli/help](https://badges.gitter.im/go-jira-cli/help.svg)](https://gitter.im/go-jira-cli/help?utm_source=badge&utm_medium=badge&utm_content=badge) # go-jira simple command line client for Atlassian's Jira service written in Go diff --git a/commands.go b/commands.go index fb18045..32e3fe2 100644 --- a/commands.go +++ b/commands.go @@ -2,9 +2,12 @@ package jira import ( "bytes" + "encoding/json" "errors" "fmt" "github.com/howeyc/gopass" + "github.com/Netflix-Skunkworks/go-jira/data" + "io/ioutil" "net/http" "net/url" "os" @@ -261,8 +264,29 @@ func (c *Cli) CmdComponents(project string) error { return runTemplate(c.getTemplate("components"), data, nil) } +func (c *Cli) ValidTransitions(issue string) (jiradata.Transitions,error) { + uri := fmt.Sprintf("%s/rest/api/2/issue/%s/transitions?expand=transitions.fields", c.endpoint, issue) + resp, err := c.get(uri) + if err != nil { + return nil, err + } + + transMeta := &jiradata.TransitionsMeta{} + content, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, err + } + err = json.Unmarshal(content, transMeta) + if err != nil { + return nil, err + } + + return transMeta.Transitions, nil +} + func (c *Cli) CmdTransitions(issue string) error { log.Debugf("Transitions called") + // FIXME this should just call ValidTransitions then pass that data to templates c.Browse(issue) uri := fmt.Sprintf("%s/rest/api/2/issue/%s/transitions", c.endpoint, issue) data, err := responseToJson(c.get(uri)) @@ -565,7 +589,7 @@ func (c *Cli) CmdTransition(issue string, trans string) error { } if transId == "" { err := fmt.Errorf("Invalid Transition '%s', Available: %s", trans, strings.Join(found, ", ")) - log.Errorf("%s", err) + log.Debugf("%s", err) return err } diff --git a/main/main.go b/main/main.go index 51affca..22a871a 100644 --- a/main/main.go +++ b/main/main.go @@ -371,7 +371,18 @@ Command Options: requireArgs(2) if err = c.CmdDups(args[0], args[1]); err == nil { opts["resolution"] = "Duplicate" - err = c.CmdTransition(args[0], "close") + trans, err := c.ValidTransitions(args[0]) + if err == nil { + close := trans.Find("close") + if close != nil { + err = c.CmdTransition(args[0], "close") + } else { + // for now just assume if there is no "close", then + // there is a "done" state + err = c.CmdTransition(args[0], "done") + } + } + } case "watch": requireArgs(1) diff --git a/schemas/fetch-schemas.py b/schemas/fetch-schemas.py new file mode 100755 index 0000000..e27a1f0 --- /dev/null +++ b/schemas/fetch-schemas.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +from lxml import html +import requests +import json + +page = requests.get('https://docs.atlassian.com/jira/REST/cloud') +tree = html.fromstring(page.content) + +schemas = tree.xpath("//div[@class='representation-doc-block']//code/text()") + +for schema in schemas: + try: + data = json.loads(schema) + if "title" in data: + title = data["title"].replace(" ", "") + print "Writing {}.json".format(title) + with open("{}.json".format(title), 'w') as f: + f.write(schema) + except: + True + diff --git a/t/000setup.t b/t/000setup.t index 6fdb5e8..c1bb38c 100755 --- a/t/000setup.t +++ b/t/000setup.t @@ -3,7 +3,7 @@ eval "$(curl -q -s https://raw.githubusercontent.com/coryb/osht/master/osht.sh)" cd $(dirname $0) jira="../jira --user admin" -PLAN 13 +PLAN 14 # clean out any old containers RUNS sh -c "docker rm -f go-jira-test || true" @@ -42,3 +42,7 @@ RUNS $jira req -M POST /rest/api/2/project '{"key":"PROCESS","name":"Process","p RUNS $jira req -M POST /rest/api/2/project '{"key":"TASK","name":"Task","projectTypeKey":"business","projectTemplateKey":"com.atlassian.jira-core-project-templates:jira-core-task-management","lead":"gojira"}' RUNS $jira logout + +# export new templates so we are always using whatever is latest +# and not whatever is in the test-runners homedir +RUNS $jira export-templates -d .jira.d/templates