mirror of
https://gitea.com/gitea/tea.git
synced 2024-11-22 10:31:37 +01:00
f445ac7521
fix lint fix lint Move print TrackedTimesList to print package Move AbsPathWithExpansion to utils/path.go rename module intern to config Move Subcomands into it's own Packages Split times subcomands into own sourcefiles Split repos subcomands into own sourcefiles Split releases subcomands into own sourcefiles Split pulls subcomands into own sourcefiles Split milestones subcomands into own sourcefiles Split login subcomands into own sourcefiles Split labels subcomands into own sourcefiles split issues subcomands into own sourcefiles mv Move Interactive Login Creation to interact package Move Add Login function to intern/login.go apply from review lint: add description to exported func smal nits Move DetailViews stdout print func to print package Refactor: * Move Config & Login routines into intern package * rename global var in cmd * Move help func to utils Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/206 Reviewed-by: Norwin <noerw@noreply.gitea.io> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
106 lines
2.7 KiB
Go
106 lines
2.7 KiB
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"code.gitea.io/tea/cmd/flags"
|
|
"code.gitea.io/tea/cmd/times"
|
|
"code.gitea.io/tea/modules/config"
|
|
"code.gitea.io/tea/modules/print"
|
|
"code.gitea.io/tea/modules/utils"
|
|
|
|
"code.gitea.io/sdk/gitea"
|
|
"github.com/araddon/dateparse"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
// CmdTrackedTimes represents the command to operate repositories' times.
|
|
var CmdTrackedTimes = cli.Command{
|
|
Name: "times",
|
|
Aliases: []string{"time"},
|
|
Usage: "Operate on tracked times of a repository's issues & pulls",
|
|
Description: `Operate on tracked times of a repository's issues & pulls.
|
|
Depending on your permissions on the repository, only your own tracked
|
|
times might be listed.`,
|
|
ArgsUsage: "[username | #issue]",
|
|
Action: runTrackedTimes,
|
|
Subcommands: []*cli.Command{
|
|
×.CmdTrackedTimesAdd,
|
|
×.CmdTrackedTimesDelete,
|
|
×.CmdTrackedTimesReset,
|
|
},
|
|
Flags: append([]cli.Flag{
|
|
&cli.StringFlag{
|
|
Name: "from",
|
|
Aliases: []string{"f"},
|
|
Usage: "Show only times tracked after this date",
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "until",
|
|
Aliases: []string{"u"},
|
|
Usage: "Show only times tracked before this date",
|
|
},
|
|
&cli.BoolFlag{
|
|
Name: "total",
|
|
Aliases: []string{"t"},
|
|
Usage: "Print the total duration at the end",
|
|
},
|
|
}, flags.AllDefaultFlags...),
|
|
}
|
|
|
|
func runTrackedTimes(ctx *cli.Context) error {
|
|
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
|
client := login.Client()
|
|
|
|
if err := client.CheckServerVersionConstraint(">= 1.11"); err != nil {
|
|
return err
|
|
}
|
|
|
|
var times []*gitea.TrackedTime
|
|
var err error
|
|
|
|
user := ctx.Args().First()
|
|
fmt.Println(ctx.Command.ArgsUsage)
|
|
if user == "" {
|
|
// get all tracked times on the repo
|
|
times, _, err = client.GetRepoTrackedTimes(owner, repo)
|
|
} 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.ListTrackedTimes(owner, repo, issue, gitea.ListTrackedTimesOptions{})
|
|
} else {
|
|
// get all tracked times by the specified user
|
|
times, _, err = client.GetUserTrackedTimes(owner, repo, user)
|
|
}
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var from, until time.Time
|
|
if ctx.String("from") != "" {
|
|
from, err = dateparse.ParseLocal(ctx.String("from"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
if ctx.String("until") != "" {
|
|
until, err = dateparse.ParseLocal(ctx.String("until"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
print.TrackedTimesList(times, flags.GlobalOutputValue, from, until, ctx.Bool("total"))
|
|
return nil
|
|
}
|