Ejemplo n.º 1
0
func (cc *CreateCommand) Execute(args []string) error {
	jc := libgojira.NewJiraClient(options)
	if len(options.Projects) != 1 {
		if options.Verbose {
			log.Println(options.Projects)
		}
		return &CommandError{"gojira -j flag is required once and only once for this command."}
	}
	opts := &libgojira.NewTaskOptions{}
	opts.OriginalEstimate = cc.Estimate
	opts.Summary = strings.Join(args[1:], " ")
	opts.TaskType = args[0]
	opts.Description = cc.Description
	opts.Labels = cc.Labels
	if cc.Parent != "" {
		iss, err := jc.GetIssue(cc.Parent)
		opts.Parent = iss
		if err != nil {
			return err
		}
	}
	opts.Fields = cc.Fields
	opts.SelectFields = cc.SelectFields
	err := jc.CreateTask(options.Projects[0], opts)
	if err != nil {
		return err
	}

	if !(len(args) > 1) {
		return &CommandError{"Not enough arguments"}
	}
	return nil

}
Ejemplo n.º 2
0
func (dlc *DelLogCommand) Execute(args []string) error {
	jc := libgojira.NewJiraClient(options)
	if len(args) != 2 {
		return &CommandError{"Bad number of args. Usage: gojira del-log ISSUE-1234 6276413"}
	}
	return jc.DelWorkLog(args[0], args[1])
}
Ejemplo n.º 3
0
func (ec *CommentCommand) Execute(args []string) error {
	jc := libgojira.NewJiraClient(options)

	if !(len(args) > 0) {
		return &CommandError{"Not enough arguments"}
	}
	var comment string
	if len(args) == 1 {
		cmd := exec.Command("cat")
		var out bytes.Buffer
		cmd.Stdout = &out
		cmd.Stdin = os.Stdin
		cmd.Run()
		comment = out.String()
	} else {
		if args[1] == "-" {
			b, err := ioutil.ReadAll(os.Stdin)
			if err != nil {
				return err
			}
			comment = string(b)
		} else {
			comment = strings.Join(args[1:], " ")
		}
	}

	err := jc.AddComment(args[0], comment)
	if err != nil {
		return err
	}

	return nil

}
Ejemplo n.º 4
0
func (lc *LogCommand) Execute(args []string) error {
	jc := libgojira.NewJiraClient(options)
	lc.jc = jc
	n := time.Now()
	if d, err := time.Parse("2006-01-02", lc.Day); err == nil {
		d = time.Date(d.Year(), d.Month(), d.Day(), time.Now().Hour(), time.Now().Minute(), time.Now().Second(), time.Now().Nanosecond(), time.Local)
		n = d
	}
	if lc.MyLog || len(args) < 2 {
		author := ""
		if lc.MyLog {
			author = options.User
		}
		if lc.Author != "" {
			author = lc.Author
		}
		var issue *libgojira.Issue = nil
		if len(args) > 0 {
			issue = &libgojira.Issue{Key: args[0]}
		}

		beg := time.Date(n.Year(), n.Month(), n.Day()-int(n.Weekday()), 0, 0, 0, 0, n.Location())
		end := time.Date(n.Year(), n.Month(), n.Day()-int(n.Weekday())+6, 0, 0, 0, 0, n.Location())
		fmt.Println(fmt.Sprintf("Time sheet for week starting on %v and ending on %v", beg, end))
		err := lc.GetTimeLog(author, Period{beg, end}, issue)
		if err != nil {
			return err
		}
	} else {
		key := args[0]
		timeSpent := strings.Join(args[1:], " ")
		started := n
		if len(lc.Yesterday) > 0 {
			started = time.Unix(n.Unix()-(SECONDS_IN_A_DAY*int64(len(lc.Yesterday))), 0)
		}
		data := map[string]string{"timeSpent": timeSpent, "started": started.Format(libgojira.JIRA_TIME_FORMAT), "comment": lc.Comment}
		postdata, _ := json.Marshal(data)

		url := fmt.Sprintf("https://%s/rest/api/2/issue/%s/worklog", options.Server, key)
		resp, err := jc.Post(url, "application/json", bytes.NewBuffer(postdata))
		if err != nil {
			panic(err)
		}
		if resp.StatusCode == 201 {
			log.Println("Log successful")
		} else {
			if options.Verbose {
				log.Println(resp)
				s, _ := ioutil.ReadAll(resp.Body)
				log.Println(string(s))
			}
			log.Println("Log Failed!")
		}
	}
	return nil
}
Ejemplo n.º 5
0
func (atc *AddTagCommand) Execute(args []string) error {
	if len(args) != 2 {
		return &AddCommandError{"Usage: gojira add-tag ISSUE-1234 My-Label"}
	}

	jc := libgojira.NewJiraClient(options)
	err := jc.AddTags(args[0], args[1:])
	if err != nil {
		return err
	}
	return nil
}
Ejemplo n.º 6
0
func (ic *InfoCommand) Execute(args []string) error {
	jc := libgojira.NewJiraClient(options)
	if len(args) == 0 {

		return &CommandError{"Usage: gojira info ISSUE-1234"}
	}
	issue, err := jc.GetIssue(args[0])
	if err != nil {
		return err
	}
	fmt.Println(issue.PrettySprint())
	return nil
}
Ejemplo n.º 7
0
func (ec *DeleteCommentCommand) Execute(args []string) error {
	jc := libgojira.NewJiraClient(options)

	if !(len(args) == 2) {
		return &CommandError{"Not enough or too much arguments. Exactly 2 required (Ticket ID and comment ID)."}
	}
	err := jc.DelComment(args[0], args[1])

	if err != nil {
		return err
	}
	return nil
}
Ejemplo n.º 8
0
func (ac *AttachCommand) Execute(args []string) error {
	jc := libgojira.NewJiraClient(options)

	if !(len(args) > 1) {
		return &CommandError{"Not enough arguments"}
	}
	for _, file := range args[1:] {
		err := jc.Upload(args[0], file)
		if err != nil {
			return err
		}
	}
	return nil

}
Ejemplo n.º 9
0
func (lc *LinkCommand) Execute(args []string) error {
	if len(args) < 3 {
		return fmt.Errorf("Not enough arguments, exactly 3 expected after command name.")
	}
	jc := libgojira.NewJiraClient(options)
	var comment string = ""
	if len(args) > 3 {
		comment = strings.Join(args[3:], " ")
	}
	err := jc.Link(&libgojira.Link{args[0], args[1], args[2], comment})
	if err != nil {
		return err
	}
	return nil
}
Ejemplo n.º 10
0
func (tc *AssignCommand) Execute(args []string) error {
	if len(args) != 2 {
		fmt.Errorf("Wrong number of arguments. Usage: gojira assign TASK-1234 username")
	}
	jc := libgojira.NewJiraClient(options)
	iss, err := jc.GetIssue(args[0])
	if err != nil {
		return err
	}
	err = iss.Assign(args[1], jc)
	if err != nil {
		return err
	}
	return nil
}
Ejemplo n.º 11
0
func (rc *RankCommand) Execute(args []string) error {
	if len(args) < 3 {
		return fmt.Errorf("Need at least 3 arguments. Usage: %s", rc.Usage)
	}
	target := args[len(args)-1]
	before_or_after := strings.ToLower(args[len(args)-2])
	tasks := args[:len(args)-2]

	if before_or_after != "before" && before_or_after != "after" {
		return fmt.Errorf("second last parameter needs to be 'before' or 'after'")
	}

	fmt.Println("target", target)
	jc := libgojira.NewJiraClient(options)
	err := jc.ChangeRank(tasks, before_or_after, target)
	if err != nil {
		return err
	}
	return nil
}
Ejemplo n.º 12
0
func (tc *TaskCommand) Execute(args []string) error {
	jc := libgojira.NewJiraClient(options)
	iss, err := jc.GetIssue(args[0])
	if err != nil {
		return err
	}

	var m map[string]interface{} = nil

	if len(args) > 2 {
		m = map[string]interface{}{"resolution": map[string]interface{}{"name": capitalize(args[2:])}}
	}

	err = iss.TaskTransition(jc, args[1], m)
	if err != nil {
		return err
	}

	return nil
}
Ejemplo n.º 13
0
//Implements go-flags's Command interface
func (lc *ListCommand) Execute(args []string) error { //ListTasks(){//
	if options.Verbose {
		fmt.Println("In List Command")
	}
	jc := libgojira.NewJiraClient(options)
	if len(args) == 1 && (!lc.Open && !lc.CurrentSprint && lc.JQL == "") {
		lc.JQL = fmt.Sprintf("key = %s or parent = %s order by rank", args[0], args[0])
	}
	issues, err := jc.Search(&libgojira.SearchOptions{options.Projects, lc.CurrentSprint, lc.Open, lc.Issue, lc.JQL, lc.Type, lc.NotType, lc.Status, lc.NotStatus})
	if err != nil {
		return err
	}
	if lc.Print {
		var tmpl *mustache.Template
		if lc.PrintTmpl != "" {
			tmpl, err = mustache.ParseFile(lc.PrintTmpl)
			fmt.Fprintln(out, tmpl.Render(map[string]interface{}{"Issues": issues}))
		} else {
			html, _ := libgojira.PrintHtml(issues)
			fmt.Fprintln(out, string(html))
		}
	} else {
		if lc.TotalTime {
			fmt.Fprintln(out, "ID,Points,Type,Est.,Spent,Rem.,Desc.")
			for _, v := range issues {
				fmt.Fprintln(out, fmt.Sprintf("%s,%s,%s,%s,%s,%s,\"%s\"", v.Key, v.Points, v.Type, libgojira.PrettySeconds(int(v.OriginalEstimate)), libgojira.PrettySeconds(int(v.TimeSpent)), libgojira.PrettySeconds(int(v.RemainingEstimate)), v.Summary))
			}
		} else {
			for _, v := range issues {
				fmt.Fprintln(out, v)
			}
		}
	}

	return nil
}