Improve tea time
#319
|
@ -63,45 +63,46 @@ func RunTimesList(cmd *cli.Context) error {
|
||||||
|
|
||||||
var times []*gitea.TrackedTime
|
var times []*gitea.TrackedTime
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
user := ctx.Args().First()
|
|
||||||
if ctx.Bool("mine") {
|
|
||||||
times, _, err = client.GetMyTrackedTimes()
|
|
||||||
} else if user == "" {
|
|
||||||
// get all tracked times on the repo
|
|
||||||
times, _, err = client.ListRepoTrackedTimes(ctx.Owner, ctx.Repo, gitea.ListTrackedTimesOptions{})
|
|
||||||
} else if strings.HasPrefix(user, "#") {
|
|
||||||
// get all tracked times on the specified issue
|
|
||||||
issue, err := utils.ArgToIndex(user)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
times, _, err = client.ListIssueTrackedTimes(ctx.Owner, ctx.Repo, issue, gitea.ListTrackedTimesOptions{})
|
|
||||||
} else {
|
|
||||||
// get all tracked times by the specified user
|
|
||||||
times, _, err = client.ListRepoTrackedTimes(ctx.Owner, ctx.Repo, gitea.ListTrackedTimesOptions{
|
|
||||||
User: user,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var from, until time.Time
|
var from, until time.Time
|
||||||
if ctx.String("from") != "" {
|
|
||||||
|
if ctx.IsSet("from") {
|
||||||
from, err = dateparse.ParseLocal(ctx.String("from"))
|
from, err = dateparse.ParseLocal(ctx.String("from"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ctx.String("until") != "" {
|
if ctx.IsSet("until") {
|
||||||
until, err = dateparse.ParseLocal(ctx.String("until"))
|
until, err = dateparse.ParseLocal(ctx.String("until"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print.TrackedTimesList(times, ctx.Output, from, until, ctx.Bool("total"))
|
opts := gitea.ListTrackedTimesOptions{Since: from, Before: until}
|
||||||
|
|
||||||
|
user := ctx.Args().First()
|
||||||
|
if ctx.Bool("mine") {
|
||||||
|
times, _, err = client.GetMyTrackedTimes()
|
||||||
|
} else if user == "" {
|
||||||
|
// get all tracked times on the repo
|
||||||
|
times, _, err = client.ListRepoTrackedTimes(ctx.Owner, ctx.Repo, opts)
|
||||||
|
} else if strings.HasPrefix(user, "#") {
|
||||||
|
// get all tracked times on the specified issue
|
||||||
|
issue, err := utils.ArgToIndex(user)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
times, _, err = client.ListIssueTrackedTimes(ctx.Owner, ctx.Repo, issue, opts)
|
||||||
|
} else {
|
||||||
|
// get all tracked times by the specified user
|
||||||
noerw marked this conversation as resolved
|
|||||||
|
opts.User = user
|
||||||
|
times, _, err = client.ListRepoTrackedTimes(ctx.Owner, ctx.Repo, opts)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
print.TrackedTimesList(times, ctx.Output, ctx.Bool("total"))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,12 @@ package print
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
|
||||||
|
|
||||||
"code.gitea.io/sdk/gitea"
|
"code.gitea.io/sdk/gitea"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TrackedTimesList print list of tracked times to stdout
|
// TrackedTimesList print list of tracked times to stdout
|
||||||
func TrackedTimesList(times []*gitea.TrackedTime, outputType string, from, until time.Time, printTotal bool) {
|
func TrackedTimesList(times []*gitea.TrackedTime, outputType string, printTotal bool) {
|
||||||
tab := tableWithHeader(
|
tab := tableWithHeader(
|
||||||
"Created",
|
"Created",
|
||||||
"Issue",
|
"Issue",
|
||||||
|
@ -22,13 +21,6 @@ func TrackedTimesList(times []*gitea.TrackedTime, outputType string, from, until
|
||||||
var totalDuration int64
|
var totalDuration int64
|
||||||
|
|
||||||
for _, t := range times {
|
for _, t := range times {
|
||||||
if !from.IsZero() && from.After(t.Created) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if !until.IsZero() && until.Before(t.Created) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
totalDuration += t.Time
|
totalDuration += t.Time
|
||||||
tab.addRow(
|
tab.addRow(
|
||||||
FormatTime(t.Created),
|
FormatTime(t.Created),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user
add
fields = []string{"created", "repo", "issue", "user", "duration"}
?