add `tea issues [open|close]` commands (#99)

update to master

Merge branch 'master' into issue-openclose

adress code review

add issues [open|close]

Co-authored-by: Norwin Roosen <git@nroo.de>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/gitea/tea/pulls/99
Reviewed-by: 6543 <6543@noreply.gitea.io>
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
Norwin 2020-04-22 16:09:26 +00:00 committed by Lunny Xiao
parent 4cda7e0299
commit 1a4d8edf37
1 changed files with 46 additions and 0 deletions

View File

@ -19,10 +19,13 @@ var CmdIssues = cli.Command{
Name: "issues", Name: "issues",
Usage: "List and create issues", Usage: "List and create issues",
Description: `List and create issues`, Description: `List and create issues`,
ArgsUsage: "[<issue index>]",
Action: runIssues, Action: runIssues,
Subcommands: []*cli.Command{ Subcommands: []*cli.Command{
&CmdIssuesList, &CmdIssuesList,
&CmdIssuesCreate, &CmdIssuesCreate,
&CmdIssuesReopen,
&CmdIssuesClose,
}, },
Flags: AllDefaultFlags, Flags: AllDefaultFlags,
} }
@ -170,3 +173,46 @@ func runIssuesCreate(ctx *cli.Context) error {
return nil 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
}