2020-09-17 21:35:24 +02: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 07:11:33 +02: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 21:35:24 +02:00
|
|
|
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CmdMilestones represents to operate repositories milestones.
|
|
|
|
var CmdMilestones = cli.Command{
|
|
|
|
Name: "milestones",
|
2020-10-02 17:46:51 +02:00
|
|
|
Aliases: []string{"milestone", "ms"},
|
2020-09-17 21:35:24 +02:00
|
|
|
Usage: "List and create milestones",
|
|
|
|
Description: `List and create milestones`,
|
|
|
|
ArgsUsage: "[<milestone name>]",
|
|
|
|
Action: runMilestones,
|
|
|
|
Subcommands: []*cli.Command{
|
2020-09-30 07:11:33 +02:00
|
|
|
&milestones.CmdMilestonesList,
|
|
|
|
&milestones.CmdMilestonesCreate,
|
|
|
|
&milestones.CmdMilestonesClose,
|
|
|
|
&milestones.CmdMilestonesDelete,
|
|
|
|
&milestones.CmdMilestonesReopen,
|
|
|
|
&milestones.CmdMilestonesIssues,
|
2020-09-17 21:35:24 +02:00
|
|
|
},
|
2020-09-30 07:11:33 +02:00
|
|
|
Flags: flags.AllDefaultFlags,
|
2020-09-17 21:35:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func runMilestones(ctx *cli.Context) error {
|
|
|
|
if ctx.Args().Len() == 1 {
|
2020-09-30 07:11:33 +02:00
|
|
|
return runMilestoneDetail(ctx.Args().First())
|
2020-09-17 21:35:24 +02:00
|
|
|
}
|
2020-09-30 07:11:33 +02:00
|
|
|
return milestones.RunMilestonesList(ctx)
|
2020-09-17 21:35:24 +02:00
|
|
|
}
|
|
|
|
|
2020-09-30 07:11:33 +02:00
|
|
|
func runMilestoneDetail(name string) error {
|
|
|
|
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
2020-09-17 21:35:24 +02:00
|
|
|
client := login.Client()
|
|
|
|
|
|
|
|
milestone, _, err := client.GetMilestoneByName(owner, repo, name)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-09-30 07:11:33 +02:00
|
|
|
print.MilestoneDetails(milestone)
|
2020-09-17 21:35:24 +02:00
|
|
|
return nil
|
|
|
|
}
|