Add gitea-vet #121

Merged
zeripath merged 10 commits from 6543/tea:add-gitea-vet into master 2020-04-28 13:02:28 +00:00
Showing only changes of commit 8112e345f6 - Show all commits

View File

@ -19,10 +19,13 @@ var CmdIssues = cli.Command{
Name: "issues",
Usage: "List and create issues",
Description: `List and create issues`,
ArgsUsage: "[<issue index>]",
Action: runIssues,
Subcommands: []*cli.Command{
&CmdIssuesList,
&CmdIssuesCreate,
&CmdIssuesReopen,
&CmdIssuesClose,
},
Flags: AllDefaultFlags,
}
@ -170,3 +173,46 @@ func runIssuesCreate(ctx *cli.Context) error {
return nil
}
// CmdIssuesReopen represents a sub command of issues to open an issue
var CmdIssuesReopen = cli.Command{
Name: "reopen",
Aliases: []string{"open"},
Usage: "Change state of an issue to 'open'",
Description: `Change state of an issue to 'open'`,
ArgsUsage: "<issue index>",
Action: func(ctx *cli.Context) error {
var s = string(gitea.StateOpen)
return editIssueState(ctx, gitea.EditIssueOption{State: &s})
},
Flags: AllDefaultFlags,
}
// CmdIssuesClose represents a sub command of issues to close an issue
var CmdIssuesClose = cli.Command{
Name: "close",
Usage: "Change state of an issue to 'closed'",
Description: `Change state of an issue to 'closed'`,
ArgsUsage: "<issue index>",
Action: func(ctx *cli.Context) error {
var s = string(gitea.StateClosed)
return editIssueState(ctx, gitea.EditIssueOption{State: &s})
},
Flags: AllDefaultFlags,
}
// editIssueState abstracts the arg parsing to edit the given issue
func editIssueState(ctx *cli.Context, opts gitea.EditIssueOption) error {
login, owner, repo := initCommand()
if ctx.Args().Len() == 0 {
log.Fatal(ctx.Command.ArgsUsage)
}
index, err := argToIndex(ctx.Args().First())
if err != nil {
return err
}
_, err = login.Client().EditIssue(owner, repo, index, opts)
return err
}