2020-09-30 07:11:33 +02:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2023-09-08 03:40:02 +02:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-09-30 07:11:33 +02:00
|
|
|
|
|
|
|
package times
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"code.gitea.io/tea/cmd/flags"
|
2020-12-15 18:38:22 +01:00
|
|
|
"code.gitea.io/tea/modules/context"
|
2020-09-30 07:11:33 +02: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 18:38:22 +01:00
|
|
|
func runTrackedTimesReset(cmd *cli.Context) error {
|
|
|
|
ctx := context.InitCommand(cmd)
|
|
|
|
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
|
|
|
client := ctx.Login.Client()
|
2020-09-30 07:11:33 +02: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 {
|
2020-12-16 17:18:10 +01:00
|
|
|
return err
|
2020-09-30 07:11:33 +02:00
|
|
|
}
|
|
|
|
|
2020-12-15 18:38:22 +01:00
|
|
|
_, err = client.ResetIssueTime(ctx.Owner, ctx.Repo, issue)
|
2020-12-16 17:18:10 +01:00
|
|
|
return err
|
2020-09-30 07:11:33 +02:00
|
|
|
}
|