From 1a4d8edf37563e69b59e96b159a9caf0373ec72e Mon Sep 17 00:00:00 2001 From: Norwin Date: Wed, 22 Apr 2020 16:09:26 +0000 Subject: [PATCH] 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 Co-authored-by: Lunny Xiao Reviewed-on: https://gitea.com/gitea/tea/pulls/99 Reviewed-by: 6543 <6543@noreply.gitea.io> Reviewed-by: Lunny Xiao Reviewed-by: Andrew Thornton --- cmd/issues.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/cmd/issues.go b/cmd/issues.go index 09844d3..b57f219 100644 --- a/cmd/issues.go +++ b/cmd/issues.go @@ -19,10 +19,13 @@ var CmdIssues = cli.Command{ Name: "issues", Usage: "List and create issues", Description: `List and create issues`, + ArgsUsage: "[]", 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: "", + 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: "", + 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 +}