コード例 #1
0
ファイル: logcommand.go プロジェクト: otremblay/gojira
func (lc *LogCommand) GetTimeLog(targetAuthor string, period Period, issue *libgojira.Issue) error {
	issuestring := ""
	if issue != nil {
		issuestring = fmt.Sprintf(" AND key = '%s'", issue.Key)
	}
	issues, err := lc.jc.Search(&libgojira.SearchOptions{JQL: fmt.Sprintf("timespent > 0 AND updated >= '%s' and project in ('%s')%s", period.Begin.Format("2006-01-02"), strings.Join(options.Projects, "','"), issuestring)})
	if err != nil {
		return err
	}

	logs_for_times := libgojira.TimeLogMap{}
	logchan := make(chan libgojira.TimeLogMap)
	for _, issue := range issues {
		go func(issue *libgojira.Issue) {
			logs_for_times := libgojira.TimeLogMap{}
			for moment, timeloglist := range issue.TimeLog {
				for _, timelog := range timeloglist {
					if (moment.After(period.Begin) && moment.Before(period.End)) && (timelog.Author == targetAuthor || targetAuthor == "") {
						if _, ok := logs_for_times[moment]; !ok {
							logs_for_times[moment] = []libgojira.TimeLog{}
						}
						logs_for_times[moment] = append(logs_for_times[moment], timelog)
					}
				}
			}
			logchan <- logs_for_times
		}(issue)
	}

	for _, _ = range issues {
		tlm := <-logchan
		for k, v := range tlm {
			logs_for_times[k] = append(logs_for_times[k], v...)
		}
		fmt.Print(".")
	}
	fmt.Print("\n")
	logformat := lc.WorklogFormat
	if logformat == "" {
		logformat = "{{.PrettySeconds}}\t{{.Key}}\t({{.Issue.Type}}): ({{.Percentage}} PTS) {{.Issue.Summary}}"
	}
	for _, l := range logs_for_times.GetSortedKeys() {
		fmt.Println(l)
		for _, singlelog := range logs_for_times[l] {
			//TODO: Either abstract the template or don't, but expose it to be a parameter.

			str, err := singlelog.Sprintf(logformat)
			if err != nil {
				fmt.Println(err)
			}
			fmt.Println(str)
		}
		fmt.Println(fmt.Sprintf("Total for day: %s\n", libgojira.PrettySeconds(logs_for_times.SumForKey(l))))
	}
	fmt.Println(fmt.Sprintf("Total for period: %s", libgojira.PrettySeconds(logs_for_times.SumForMap())))
	return nil
}
コード例 #2
0
ファイル: listcommand.go プロジェクト: otremblay/gojira
//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
}