It goes into the repo or it gets the hose again.
This commit is contained in:
parent
96cadaf4df
commit
197e28024b
5 changed files with 143 additions and 21 deletions
|
|
@ -4,18 +4,19 @@ import (
|
|||
"bytes"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"fmt"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"otremblay.com/jkl"
|
||||
)
|
||||
|
||||
type CreateCmd struct {
|
||||
args []string
|
||||
project string
|
||||
file string
|
||||
args []string
|
||||
project string
|
||||
file string
|
||||
issuetype string
|
||||
}
|
||||
|
||||
|
|
@ -43,7 +44,7 @@ func (ccmd *CreateCmd) Create() error {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ccmd.project == "" {
|
||||
return ErrCcmdJiraProjectRequired
|
||||
}
|
||||
|
|
@ -55,13 +56,22 @@ func (ccmd *CreateCmd) Create() error {
|
|||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, fmt.Sprintf("Error getting the CreateMeta for project [%s] and issue types [%s]", ccmd.project, isstype), err)
|
||||
}
|
||||
|
||||
|
||||
if !readfile {
|
||||
createTemplate.Execute(b, cm)
|
||||
}
|
||||
var iss *jkl.JiraIssue
|
||||
// TODO: Evil badbad don't do this.
|
||||
em := &jkl.EditMeta{Fields: cm.Projects[0].IssueTypes[0].Fields}
|
||||
var isst = cm.Projects[0].IssueTypes[0].Fields
|
||||
for _, v := range cm.Projects[0].IssueTypes {
|
||||
if strings.ToLower(isstype) == strings.ToLower(v.Name) {
|
||||
isst = v.Fields
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
em := &jkl.EditMeta{Fields: isst}
|
||||
|
||||
if ccmd.file != "" {
|
||||
iss, err = GetIssueFromFile(ccmd.file, b, em)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
|
|
@ -22,16 +21,21 @@ import (
|
|||
// [System.get_env("EDITOR"), "nano", "vim", "vi"]
|
||||
// |> Enum.find(nil, fn (ed) -> System.find_executable(ed) != nil end)
|
||||
// end
|
||||
var editors = []string{os.Getenv("EDITOR"), "nano", "vim", "vi"}
|
||||
var editors = []string{"nano", "vim", "vi"}
|
||||
|
||||
// GetEditor returns the path to an editor, taking $EDITOR in account
|
||||
func GetEditor() string {
|
||||
if ed := os.Getenv("EDITOR"); ed != "" {
|
||||
return ed
|
||||
}
|
||||
if ed := os.Getenv("VISUAL"); ed != "" {
|
||||
return ed
|
||||
}
|
||||
for _, ed := range editors {
|
||||
if p, err := exec.LookPath(ed); err == nil {
|
||||
return p
|
||||
}
|
||||
}
|
||||
log.Fatal("No editor available; use flags.")
|
||||
return ""
|
||||
}
|
||||
|
||||
|
|
@ -105,7 +109,7 @@ func GetIssueFromFile(filename string, initial io.Reader, editMeta *jkl.EditMeta
|
|||
var spacex = regexp.MustCompile(`\s`)
|
||||
|
||||
func IssueFromReader(f io.Reader, editMeta *jkl.EditMeta) *jkl.JiraIssue {
|
||||
iss := &jkl.JiraIssue{Fields: &jkl.Fields{}}
|
||||
iss := &jkl.JiraIssue{Fields: &jkl.Fields{ExtraFields: map[string]interface{}{}}}
|
||||
riss := reflect.ValueOf(iss).Elem()
|
||||
fieldsField := riss.FieldByName("Fields").Elem()
|
||||
currentField := reflect.Value{}
|
||||
|
|
@ -157,6 +161,25 @@ func IssueFromReader(f io.Reader, editMeta *jkl.EditMeta) *jkl.JiraIssue {
|
|||
}
|
||||
} else if editMeta != nil {
|
||||
// If it's not valid, throw it at the createmeta. It will probably end up in ExtraFields.
|
||||
val := strings.TrimSpace(strings.Join(parts[1:], ":"))
|
||||
for fieldname, m := range editMeta.Fields {
|
||||
var something interface{} = val
|
||||
if strings.ToLower(m.Name) == strings.ToLower(potentialField) {
|
||||
name := fieldname
|
||||
for _, av := range m.AllowedValues {
|
||||
if strings.ToLower(av.Name) == strings.ToLower(val) {
|
||||
something = av
|
||||
break
|
||||
}
|
||||
}
|
||||
if m.Schema.CustomId > 0 {
|
||||
name = fmt.Sprintf("custom_%d", m.Schema.CustomId)
|
||||
}
|
||||
iss.Fields.ExtraFields[name] = something
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if currentField.IsValid() {
|
||||
|
|
@ -168,6 +191,8 @@ func IssueFromReader(f io.Reader, editMeta *jkl.EditMeta) *jkl.JiraIssue {
|
|||
currentField.SetString(newvalue)
|
||||
}
|
||||
}
|
||||
|
||||
iss.EditMeta = editMeta
|
||||
return iss
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,11 +19,11 @@ func (t *TaskCmd) Handle() error {
|
|||
return t.Get(t.args[0])
|
||||
}
|
||||
if c == 2 {
|
||||
fmt.Println(t.args)
|
||||
// fmt.Println(t.args)
|
||||
err := t.Transition(t.args[0], t.args[1])
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return t.Log(t.args[0], strings.Join(t.args[1:]," "))
|
||||
//fmt.Println(err)
|
||||
return t.Log(t.args[0], strings.Join(t.args[1:], " "))
|
||||
}
|
||||
}
|
||||
return ErrTaskSubCommandNotFound
|
||||
|
|
@ -45,7 +45,7 @@ func (t *TaskCmd) Transition(taskKey, transition string) error {
|
|||
}
|
||||
|
||||
func (t *TaskCmd) Log(taskKey, time string) error {
|
||||
return jkl.LogWork(taskKey, time)
|
||||
return jkl.LogWork(taskKey, time)
|
||||
}
|
||||
|
||||
func (t *TaskCmd) Run() error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue