2020-09-17 19:35:24 +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 cmd
|
|
|
|
|
|
|
|
import (
|
2020-09-30 05:11:33 +00:00
|
|
|
"code.gitea.io/tea/cmd/milestones"
|
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/print"
|
2020-09-17 19:35:24 +00:00
|
|
|
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CmdMilestones represents to operate repositories milestones.
|
|
|
|
var CmdMilestones = cli.Command{
|
|
|
|
Name: "milestones",
|
2020-10-02 15:46:51 +00:00
|
|
|
Aliases: []string{"milestone", "ms"},
|
2020-12-21 13:37:20 +00:00
|
|
|
Category: catEntities,
|
2020-09-17 19:35:24 +00:00
|
|
|
Usage: "List and create milestones",
|
|
|
|
Description: `List and create milestones`,
|
|
|
|
ArgsUsage: "[<milestone name>]",
|
|
|
|
Action: runMilestones,
|
|
|
|
Subcommands: []*cli.Command{
|
2020-09-30 05:11:33 +00:00
|
|
|
&milestones.CmdMilestonesList,
|
|
|
|
&milestones.CmdMilestonesCreate,
|
|
|
|
&milestones.CmdMilestonesClose,
|
|
|
|
&milestones.CmdMilestonesDelete,
|
|
|
|
&milestones.CmdMilestonesReopen,
|
|
|
|
&milestones.CmdMilestonesIssues,
|
2020-09-17 19:35:24 +00:00
|
|
|
},
|
2020-12-21 15:41:07 +00:00
|
|
|
Flags: milestones.CmdMilestonesList.Flags,
|
2020-09-17 19:35:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func runMilestones(ctx *cli.Context) error {
|
|
|
|
if ctx.Args().Len() == 1 {
|
2020-12-15 17:38:22 +00:00
|
|
|
return runMilestoneDetail(ctx, ctx.Args().First())
|
2020-09-17 19:35:24 +00:00
|
|
|
}
|
2020-09-30 05:11:33 +00:00
|
|
|
return milestones.RunMilestonesList(ctx)
|
2020-09-17 19:35:24 +00:00
|
|
|
}
|
|
|
|
|
2020-12-15 17:38:22 +00:00
|
|
|
func runMilestoneDetail(cmd *cli.Context, name string) error {
|
|
|
|
ctx := context.InitCommand(cmd)
|
|
|
|
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
|
|
|
client := ctx.Login.Client()
|
2020-09-17 19:35:24 +00:00
|
|
|
|
2020-12-15 17:38:22 +00:00
|
|
|
milestone, _, err := client.GetMilestoneByName(ctx.Owner, ctx.Repo, name)
|
2020-09-17 19:35:24 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-09-30 05:11:33 +00:00
|
|
|
print.MilestoneDetails(milestone)
|
2020-09-17 19:35:24 +00:00
|
|
|
return nil
|
|
|
|
}
|