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/flags"
|
|
|
|
"code.gitea.io/tea/cmd/milestones"
|
|
|
|
"code.gitea.io/tea/modules/config"
|
|
|
|
"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",
|
|
|
|
Aliases: []string{"ms", "mile"},
|
|
|
|
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-09-30 01:11:33 -04:00
|
|
|
Flags: flags.AllDefaultFlags,
|
2020-09-17 15:35:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func runMilestones(ctx *cli.Context) error {
|
|
|
|
if ctx.Args().Len() == 1 {
|
2020-09-30 01:11:33 -04:00
|
|
|
return runMilestoneDetail(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-09-30 01:11:33 -04:00
|
|
|
func runMilestoneDetail(name string) error {
|
|
|
|
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
2020-09-17 15:35:24 -04:00
|
|
|
client := login.Client()
|
|
|
|
|
|
|
|
milestone, _, err := client.GetMilestoneByName(owner, repo, name)
|
|
|
|
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
|
|
|
|
}
|