Lots of stuff
This commit is contained in:
parent
fbcc875846
commit
a37c44ff37
8 changed files with 518 additions and 45 deletions
|
|
@ -6,6 +6,8 @@ import (
|
|||
"flag"
|
||||
"io"
|
||||
"os"
|
||||
"fmt"
|
||||
"text/template"
|
||||
|
||||
"otremblay.com/jkl"
|
||||
)
|
||||
|
|
@ -14,6 +16,7 @@ type CreateCmd struct {
|
|||
args []string
|
||||
project string
|
||||
file string
|
||||
issuetype string
|
||||
}
|
||||
|
||||
func NewCreateCmd(args []string) (*CreateCmd, error) {
|
||||
|
|
@ -22,6 +25,7 @@ func NewCreateCmd(args []string) (*CreateCmd, error) {
|
|||
f.StringVar(&ccmd.project, "p", "", "Jira project key")
|
||||
f.StringVar(&ccmd.file, "f", "", "File to get issue description from")
|
||||
f.Parse(args)
|
||||
ccmd.args = f.Args()
|
||||
return ccmd, nil
|
||||
}
|
||||
|
||||
|
|
@ -39,18 +43,32 @@ func (ccmd *CreateCmd) Create() error {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
if ccmd.project == "" {
|
||||
return ErrCcmdJiraProjectRequired
|
||||
}
|
||||
isstype := ""
|
||||
if len(ccmd.args) > 0 {
|
||||
isstype = ccmd.args[0]
|
||||
}
|
||||
cm, err := jkl.GetCreateMeta(ccmd.project, isstype)
|
||||
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 {
|
||||
b.WriteString(CREATE_TEMPLATE)
|
||||
createTemplate.Execute(b, cm)
|
||||
}
|
||||
var iss *jkl.JiraIssue
|
||||
var err error
|
||||
// TODO: Evil badbad don't do this.
|
||||
em := &jkl.EditMeta{Fields: cm.Projects[0].IssueTypes[0].Fields}
|
||||
if ccmd.file != "" {
|
||||
iss, err = GetIssueFromFile(ccmd.file, b)
|
||||
iss, err = GetIssueFromFile(ccmd.file, b, em)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
iss, err = GetIssueFromTmpFile(b)
|
||||
iss, err = GetIssueFromTmpFile(b, em)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -60,13 +78,24 @@ func (ccmd *CreateCmd) Create() error {
|
|||
(iss.Fields.Project == nil || iss.Fields.Project.Key == "") {
|
||||
iss.Fields.Project = &jkl.Project{Key: ccmd.project}
|
||||
}
|
||||
return jkl.Create(iss)
|
||||
iss, err = jkl.Create(iss)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(iss.Key)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ccmd *CreateCmd) Run() error {
|
||||
return ccmd.Create()
|
||||
}
|
||||
|
||||
const CREATE_TEMPLATE = `Issue Type:
|
||||
var createTemplate = template.Must(template.New("createissue").Parse(`{{range .Projects -}}
|
||||
Project: {{.Key}}
|
||||
{{range .IssueTypes -}}
|
||||
Issue Type: {{.Name}}
|
||||
Summary:
|
||||
Description:`
|
||||
Description:
|
||||
{{.RangeFieldSpecs}}
|
||||
{{end}}
|
||||
{{end}}`))
|
||||
|
|
|
|||
|
|
@ -39,13 +39,13 @@ func (ecmd *EditCmd) Edit() error {
|
|||
}
|
||||
|
||||
if ecmd.file != "" {
|
||||
iss, err = GetIssueFromFile(ecmd.file, b)
|
||||
iss, err = GetIssueFromFile(ecmd.file, b, iss.EditMeta)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
iss, err = GetIssueFromTmpFile(b)
|
||||
iss, err = GetIssueFromTmpFile(b, iss.EditMeta)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,28 +1,72 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"bytes"
|
||||
"flag"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
"otremblay.com/jkl"
|
||||
)
|
||||
|
||||
type EditCommentCmd struct {
|
||||
args []string
|
||||
file string
|
||||
issueKey string
|
||||
args []string
|
||||
file string
|
||||
issueKey string
|
||||
commentId string
|
||||
}
|
||||
|
||||
func NewEditCommentCmd(args []string) (*EditCommentCmd, error) {
|
||||
ccmd := &EditCommentCmd{}
|
||||
f := flag.NewFlagSet("comments", flag.ExitOnError)
|
||||
f := flag.NewFlagSet("editcomments", flag.ExitOnError)
|
||||
f.StringVar(&ccmd.file, "f", "", "File to get issue comment from")
|
||||
f.Parse(args)
|
||||
if len(f.Args()) < 1 {
|
||||
return nil, ErrNotEnoughArgs
|
||||
}
|
||||
ccmd.issueKey = f.Arg(0)
|
||||
ids := strings.Split(f.Arg(0), jkl.CommentIdSeparator)
|
||||
ccmd.issueKey = ids[0]
|
||||
if len(ids) < 2 {
|
||||
if len(f.Args()) == 2 {
|
||||
ccmd.commentId = f.Args()[1]
|
||||
} else {
|
||||
return nil, ErrNotEnoughArgs
|
||||
}
|
||||
} else {
|
||||
ccmd.commentId = ids[1]
|
||||
}
|
||||
return ccmd, nil
|
||||
}
|
||||
|
||||
func (e *EditCommentCmd) Run() error {
|
||||
return errors.New("Not implemented")
|
||||
}
|
||||
|
||||
|
||||
// Get Comment
|
||||
comm, err := jkl.GetComment(e.issueKey, e.commentId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b := bytes.NewBufferString(comm.Body)
|
||||
var rdr io.Reader
|
||||
if e.file != "" {
|
||||
rdr, err = GetTextFromSpecifiedFile(e.file, b)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
rdr, err = GetTextFromTmpFile(b)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
btxt, err := ioutil.ReadAll(rdr)
|
||||
txt := strings.TrimSpace(string(btxt))
|
||||
if txt == "" || txt == strings.TrimSpace(comm.Body) {
|
||||
// Nothing to do
|
||||
return nil
|
||||
}
|
||||
comm.Body = txt
|
||||
return jkl.EditComment(e.issueKey, e.commentId, comm)
|
||||
}
|
||||
|
|
@ -17,7 +17,6 @@ import (
|
|||
|
||||
"otremblay.com/jkl"
|
||||
)
|
||||
|
||||
// def get_editor do
|
||||
// [System.get_env("EDITOR"), "nano", "vim", "vi"]
|
||||
// |> Enum.find(nil, fn (ed) -> System.find_executable(ed) != nil end)
|
||||
|
|
@ -40,7 +39,7 @@ func copyInitial(dst io.WriteSeeker, initial io.Reader) {
|
|||
dst.Seek(0, 0)
|
||||
}
|
||||
|
||||
func GetIssueFromTmpFile(initial io.Reader) (*jkl.JiraIssue, error) {
|
||||
func GetIssueFromTmpFile(initial io.Reader, editMeta *jkl.EditMeta) (*jkl.JiraIssue, error) {
|
||||
f, err := ioutil.TempFile(os.TempDir(), "jkl")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -50,7 +49,7 @@ func GetIssueFromTmpFile(initial io.Reader) (*jkl.JiraIssue, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return IssueFromReader(f2), nil
|
||||
return IssueFromReader(f2, editMeta), nil
|
||||
}
|
||||
|
||||
func GetTextFromTmpFile(initial io.Reader) (io.Reader, error) {
|
||||
|
|
@ -87,7 +86,7 @@ func GetTextFromFile(file *os.File) (io.Reader, error) {
|
|||
return file, err
|
||||
}
|
||||
|
||||
func GetIssueFromFile(filename string, initial io.Reader) (*jkl.JiraIssue, error) {
|
||||
func GetIssueFromFile(filename string, initial io.Reader, editMeta *jkl.EditMeta) (*jkl.JiraIssue, error) {
|
||||
f, err := os.Open(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -99,12 +98,12 @@ func GetIssueFromFile(filename string, initial io.Reader) (*jkl.JiraIssue, error
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return IssueFromReader(f2), nil
|
||||
return IssueFromReader(f2, editMeta), nil
|
||||
}
|
||||
|
||||
var spacex = regexp.MustCompile(`\s`)
|
||||
|
||||
func IssueFromReader(f io.Reader) *jkl.JiraIssue {
|
||||
func IssueFromReader(f io.Reader, editMeta *jkl.EditMeta) *jkl.JiraIssue {
|
||||
iss := &jkl.JiraIssue{Fields: &jkl.Fields{}}
|
||||
riss := reflect.ValueOf(iss).Elem()
|
||||
fieldsField := riss.FieldByName("Fields").Elem()
|
||||
|
|
@ -155,6 +154,9 @@ func IssueFromReader(f io.Reader) *jkl.JiraIssue {
|
|||
} else {
|
||||
currentField = newfield
|
||||
}
|
||||
} else if editMeta != nil {
|
||||
// If it's not valid, throw it at the createmeta. It will probably end up in ExtraFields.
|
||||
|
||||
}
|
||||
if currentField.IsValid() {
|
||||
currentField.SetString(strings.TrimSpace(currentField.String() + "\n" + strings.Join(parts, ":")))
|
||||
|
|
@ -163,6 +165,6 @@ func IssueFromReader(f io.Reader) *jkl.JiraIssue {
|
|||
return iss
|
||||
}
|
||||
|
||||
func IssueFromList(list []string) *jkl.JiraIssue {
|
||||
return IssueFromReader(bytes.NewBufferString(strings.Join(list, "\n")))
|
||||
func IssueFromList(list []string, editMeta *jkl.EditMeta) *jkl.JiraIssue {
|
||||
return IssueFromReader(bytes.NewBufferString(strings.Join(list, "\n")), editMeta)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"sort"
|
||||
|
||||
"strings"
|
||||
|
||||
|
|
@ -54,6 +55,9 @@ func getCmd(args []string, depth int) (Runner, error) {
|
|||
case "edit":
|
||||
return NewEditCmd(args[1:])
|
||||
case "comment":
|
||||
if strings.Contains(strings.Join(args,""),jkl.CommentIdSeparator){
|
||||
return NewEditCommentCmd(args[1:])
|
||||
}
|
||||
return NewCommentCmd(args[1:])
|
||||
case "edit-comment":
|
||||
return NewEditCommentCmd(args[1:])
|
||||
|
|
@ -67,6 +71,13 @@ func getCmd(args []string, depth int) (Runner, error) {
|
|||
|
||||
if depth == 0 {
|
||||
// Assume args[0] is a task key
|
||||
if len(args) == 1 {
|
||||
// Default to task info
|
||||
args = append(args, "task")
|
||||
}
|
||||
if verbs[sort.SearchStrings(verbs, args[1])] != args[1] {
|
||||
return &TaskCmd{args}, nil
|
||||
}
|
||||
args[0], args[1] = args[1], args[0]
|
||||
return getCmd(args, depth+1)
|
||||
} else {
|
||||
|
|
@ -81,6 +92,11 @@ func getCmd(args []string, depth int) (Runner, error) {
|
|||
return nil, ErrTaskSubCommandNotFound
|
||||
}
|
||||
|
||||
var verbs = []string{"list", "create", "task", "edit", "comment","edit-comment"}
|
||||
func init(){
|
||||
sort.Strings(verbs)
|
||||
}
|
||||
|
||||
const usage = `Usage:
|
||||
jkl [options] <command> [args]
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"otremblay.com/jkl"
|
||||
)
|
||||
|
|
@ -18,7 +19,12 @@ func (t *TaskCmd) Handle() error {
|
|||
return t.Get(t.args[0])
|
||||
}
|
||||
if c == 2 {
|
||||
return t.Transition(t.args[0], t.args[1])
|
||||
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:]," "))
|
||||
}
|
||||
}
|
||||
return ErrTaskSubCommandNotFound
|
||||
}
|
||||
|
|
@ -35,7 +41,11 @@ func (t *TaskCmd) Get(taskKey string) error {
|
|||
}
|
||||
|
||||
func (t *TaskCmd) Transition(taskKey, transition string) error {
|
||||
return nil
|
||||
return jkl.DoTransition(taskKey, transition)
|
||||
}
|
||||
|
||||
func (t *TaskCmd) Log(taskKey, time string) error {
|
||||
return jkl.LogWork(taskKey, time)
|
||||
}
|
||||
|
||||
func (t *TaskCmd) Run() error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue