2020-09-30 05:11:33 +00:00
|
|
|
// 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 times
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"code.gitea.io/tea/cmd/flags"
|
2020-12-15 17:38:22 +00:00
|
|
|
"code.gitea.io/tea/modules/context"
|
2020-09-30 05:11:33 +00:00
|
|
|
"code.gitea.io/tea/modules/utils"
|
|
|
|
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CmdTrackedTimesReset is a subcommand of CmdTrackedTimes, and
|
|
|
|
// clears all tracked times on an issue.
|
|
|
|
var CmdTrackedTimesReset = cli.Command{
|
|
|
|
Name: "reset",
|
|
|
|
Usage: "Reset tracked time on an issue",
|
|
|
|
UsageText: "tea times reset <issue>",
|
|
|
|
Action: runTrackedTimesReset,
|
|
|
|
Flags: flags.LoginRepoFlags,
|
|
|
|
}
|
|
|
|
|
2020-12-15 17:38:22 +00:00
|
|
|
func runTrackedTimesReset(cmd *cli.Context) error {
|
|
|
|
ctx := context.InitCommand(cmd)
|
|
|
|
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
|
|
|
client := ctx.Login.Client()
|
2020-09-30 05:11:33 +00:00
|
|
|
|
|
|
|
if ctx.Args().Len() != 1 {
|
|
|
|
return fmt.Errorf("No issue specified.\nUsage:\t%s", ctx.Command.UsageText)
|
|
|
|
}
|
|
|
|
|
|
|
|
issue, err := utils.ArgToIndex(ctx.Args().First())
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-12-15 17:38:22 +00:00
|
|
|
_, err = client.ResetIssueTime(ctx.Owner, ctx.Repo, issue)
|
2020-09-30 05:11:33 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|