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