mirror of
https://gitea.com/gitea/tea.git
synced 2024-11-25 03:51:36 +01:00
Allow batch operations on multiple entities (#512)
commands now accept multiple arguments where it makes sense. #### before ``` NAME: tea issues close - Change state of an issue to 'closed' USAGE: tea issues close [command options] <issue index> ``` #### after ``` NAME: tea issues close - Change state of one ore more issues to 'closed' USAGE: tea issues close [command options] <issue index> [<issue index>...] ``` Co-authored-by: Norwin <git@nroo.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/512 Reviewed-by: 6543 <6543@obermui.de> Reviewed-by: justusbunsi <justusbunsi@noreply.gitea.io> Co-authored-by: Norwin <noerw@noreply.gitea.io> Co-committed-by: Norwin <noerw@noreply.gitea.io>
This commit is contained in:
parent
6a4ba6a689
commit
4487213581
@ -19,9 +19,9 @@ import (
|
|||||||
// CmdIssuesClose represents a sub command of issues to close an issue
|
// CmdIssuesClose represents a sub command of issues to close an issue
|
||||||
var CmdIssuesClose = cli.Command{
|
var CmdIssuesClose = cli.Command{
|
||||||
Name: "close",
|
Name: "close",
|
||||||
Usage: "Change state of an issue to 'closed'",
|
Usage: "Change state of one ore more issues to 'closed'",
|
||||||
Description: `Change state of an issue to 'closed'`,
|
Description: `Change state of one ore more issues to 'closed'`,
|
||||||
ArgsUsage: "<issue index>",
|
ArgsUsage: "<issue index> [<issue index>...]",
|
||||||
Action: func(ctx *cli.Context) error {
|
Action: func(ctx *cli.Context) error {
|
||||||
var s = gitea.StateClosed
|
var s = gitea.StateClosed
|
||||||
return editIssueState(ctx, gitea.EditIssueOption{State: &s})
|
return editIssueState(ctx, gitea.EditIssueOption{State: &s})
|
||||||
@ -37,16 +37,23 @@ func editIssueState(cmd *cli.Context, opts gitea.EditIssueOption) error {
|
|||||||
return fmt.Errorf(ctx.Command.ArgsUsage)
|
return fmt.Errorf(ctx.Command.ArgsUsage)
|
||||||
}
|
}
|
||||||
|
|
||||||
index, err := utils.ArgToIndex(ctx.Args().First())
|
indices, err := utils.ArgsToIndices(ctx.Args().Slice())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
issue, _, err := ctx.Login.Client().EditIssue(ctx.Owner, ctx.Repo, index, opts)
|
client := ctx.Login.Client()
|
||||||
|
for _, index := range indices {
|
||||||
|
issue, _, err := client.EditIssue(ctx.Owner, ctx.Repo, index, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(indices) > 1 {
|
||||||
|
fmt.Println(issue.HTMLURL)
|
||||||
|
} else {
|
||||||
print.IssueDetails(issue, nil)
|
print.IssueDetails(issue, nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,9 @@ import (
|
|||||||
var CmdIssuesReopen = cli.Command{
|
var CmdIssuesReopen = cli.Command{
|
||||||
Name: "reopen",
|
Name: "reopen",
|
||||||
Aliases: []string{"open"},
|
Aliases: []string{"open"},
|
||||||
Usage: "Change state of an issue to 'open'",
|
Usage: "Change state of one or more issues to 'open'",
|
||||||
Description: `Change state of an issue to 'open'`,
|
Description: `Change state of one or more issues to 'open'`,
|
||||||
ArgsUsage: "<issue index>",
|
ArgsUsage: "<issue index> [<issue index>...]",
|
||||||
Action: func(ctx *cli.Context) error {
|
Action: func(ctx *cli.Context) error {
|
||||||
var s = gitea.StateOpen
|
var s = gitea.StateOpen
|
||||||
return editIssueState(ctx, gitea.EditIssueOption{State: &s})
|
return editIssueState(ctx, gitea.EditIssueOption{State: &s})
|
||||||
|
@ -13,9 +13,9 @@ import (
|
|||||||
// CmdMilestonesClose represents a sub command of milestones to close an milestone
|
// CmdMilestonesClose represents a sub command of milestones to close an milestone
|
||||||
var CmdMilestonesClose = cli.Command{
|
var CmdMilestonesClose = cli.Command{
|
||||||
Name: "close",
|
Name: "close",
|
||||||
Usage: "Change state of an milestone to 'closed'",
|
Usage: "Change state of one or more milestones to 'closed'",
|
||||||
Description: `Change state of an milestone to 'closed'`,
|
Description: `Change state of one or more milestones to 'closed'`,
|
||||||
ArgsUsage: "<milestone name>",
|
ArgsUsage: "<milestone name> [<milestone name>...]",
|
||||||
Action: func(ctx *cli.Context) error {
|
Action: func(ctx *cli.Context) error {
|
||||||
if ctx.Bool("force") {
|
if ctx.Bool("force") {
|
||||||
return deleteMilestone(ctx)
|
return deleteMilestone(ctx)
|
||||||
|
@ -5,8 +5,11 @@
|
|||||||
package milestones
|
package milestones
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"code.gitea.io/tea/cmd/flags"
|
"code.gitea.io/tea/cmd/flags"
|
||||||
"code.gitea.io/tea/modules/context"
|
"code.gitea.io/tea/modules/context"
|
||||||
|
"code.gitea.io/tea/modules/print"
|
||||||
|
|
||||||
"code.gitea.io/sdk/gitea"
|
"code.gitea.io/sdk/gitea"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
@ -16,9 +19,9 @@ import (
|
|||||||
var CmdMilestonesReopen = cli.Command{
|
var CmdMilestonesReopen = cli.Command{
|
||||||
Name: "reopen",
|
Name: "reopen",
|
||||||
Aliases: []string{"open"},
|
Aliases: []string{"open"},
|
||||||
Usage: "Change state of an milestone to 'open'",
|
Usage: "Change state of one or more milestones to 'open'",
|
||||||
Description: `Change state of an milestone to 'open'`,
|
Description: `Change state of one or more milestones to 'open'`,
|
||||||
ArgsUsage: "<milestone name>",
|
ArgsUsage: "<milestone name> [<milestone name> ...]",
|
||||||
Action: func(ctx *cli.Context) error {
|
Action: func(ctx *cli.Context) error {
|
||||||
return editMilestoneStatus(ctx, false)
|
return editMilestoneStatus(ctx, false)
|
||||||
},
|
},
|
||||||
@ -28,16 +31,31 @@ var CmdMilestonesReopen = cli.Command{
|
|||||||
func editMilestoneStatus(cmd *cli.Context, close bool) error {
|
func editMilestoneStatus(cmd *cli.Context, close bool) error {
|
||||||
ctx := context.InitCommand(cmd)
|
ctx := context.InitCommand(cmd)
|
||||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||||
client := ctx.Login.Client()
|
if ctx.Args().Len() == 0 {
|
||||||
|
return fmt.Errorf(ctx.Command.ArgsUsage)
|
||||||
|
}
|
||||||
|
|
||||||
state := gitea.StateOpen
|
state := gitea.StateOpen
|
||||||
if close {
|
if close {
|
||||||
state = gitea.StateClosed
|
state = gitea.StateClosed
|
||||||
}
|
}
|
||||||
_, _, err := client.EditMilestoneByName(ctx.Owner, ctx.Repo, ctx.Args().First(), gitea.EditMilestoneOption{
|
|
||||||
State: &state,
|
|
||||||
Title: ctx.Args().First(),
|
|
||||||
})
|
|
||||||
|
|
||||||
|
client := ctx.Login.Client()
|
||||||
|
for _, ms := range ctx.Args().Slice() {
|
||||||
|
opts := gitea.EditMilestoneOption{
|
||||||
|
State: &state,
|
||||||
|
Title: ms,
|
||||||
|
}
|
||||||
|
milestone, _, err := client.EditMilestoneByName(ctx.Owner, ctx.Repo, ms, opts)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ctx.Args().Len() > 1 {
|
||||||
|
fmt.Printf("%s/milestone/%d\n", ctx.GetRemoteRepoHTMLURL(), milestone.ID)
|
||||||
|
} else {
|
||||||
|
print.MilestoneDetails(milestone)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -74,6 +74,5 @@ func runOpen(cmd *cli.Context) error {
|
|||||||
suffix = number
|
suffix = number
|
||||||
}
|
}
|
||||||
|
|
||||||
u := path.Join(ctx.Login.URL, ctx.Owner, ctx.Repo, suffix)
|
return open.Run(path.Join(ctx.GetRemoteRepoHTMLURL(), suffix))
|
||||||
return open.Run(u)
|
|
||||||
}
|
}
|
||||||
|
@ -14,9 +14,9 @@ import (
|
|||||||
// CmdPullsClose closes a given open pull request
|
// CmdPullsClose closes a given open pull request
|
||||||
var CmdPullsClose = cli.Command{
|
var CmdPullsClose = cli.Command{
|
||||||
Name: "close",
|
Name: "close",
|
||||||
Usage: "Change state of a pull request to 'closed'",
|
Usage: "Change state of one or more pull requests to 'closed'",
|
||||||
Description: `Change state of a pull request to 'closed'`,
|
Description: `Change state of one or more pull requests to 'closed'`,
|
||||||
ArgsUsage: "<pull index>",
|
ArgsUsage: "<pull index> [<pull index>...]",
|
||||||
Action: func(ctx *cli.Context) error {
|
Action: func(ctx *cli.Context) error {
|
||||||
var s = gitea.StateClosed
|
var s = gitea.StateClosed
|
||||||
return editPullState(ctx, gitea.EditPullRequestOption{State: &s})
|
return editPullState(ctx, gitea.EditPullRequestOption{State: &s})
|
||||||
|
@ -23,16 +23,23 @@ func editPullState(cmd *cli.Context, opts gitea.EditPullRequestOption) error {
|
|||||||
return fmt.Errorf("Please provide a Pull Request index")
|
return fmt.Errorf("Please provide a Pull Request index")
|
||||||
}
|
}
|
||||||
|
|
||||||
index, err := utils.ArgToIndex(ctx.Args().First())
|
indices, err := utils.ArgsToIndices(ctx.Args().Slice())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
pr, _, err := ctx.Login.Client().EditPullRequest(ctx.Owner, ctx.Repo, index, opts)
|
client := ctx.Login.Client()
|
||||||
|
for _, index := range indices {
|
||||||
|
pr, _, err := client.EditPullRequest(ctx.Owner, ctx.Repo, index, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(indices) > 1 {
|
||||||
|
fmt.Println(pr.HTMLURL)
|
||||||
|
} else {
|
||||||
print.PullDetails(pr, nil, nil)
|
print.PullDetails(pr, nil, nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,9 @@ import (
|
|||||||
var CmdPullsReopen = cli.Command{
|
var CmdPullsReopen = cli.Command{
|
||||||
Name: "reopen",
|
Name: "reopen",
|
||||||
Aliases: []string{"open"},
|
Aliases: []string{"open"},
|
||||||
Usage: "Change state of a pull request to 'open'",
|
Usage: "Change state of one or more pull requests to 'open'",
|
||||||
Description: `Change state of a pull request to 'open'`,
|
Description: `Change state of one or more pull requests to 'open'`,
|
||||||
ArgsUsage: "<pull index>",
|
ArgsUsage: "<pull index> [<pull index>...]",
|
||||||
Action: func(ctx *cli.Context) error {
|
Action: func(ctx *cli.Context) error {
|
||||||
var s = gitea.StateOpen
|
var s = gitea.StateOpen
|
||||||
return editPullState(ctx, gitea.EditPullRequestOption{State: &s})
|
return editPullState(ctx, gitea.EditPullRequestOption{State: &s})
|
||||||
|
@ -17,9 +17,9 @@ import (
|
|||||||
var CmdReleaseDelete = cli.Command{
|
var CmdReleaseDelete = cli.Command{
|
||||||
Name: "delete",
|
Name: "delete",
|
||||||
Aliases: []string{"rm"},
|
Aliases: []string{"rm"},
|
||||||
Usage: "Delete a release",
|
Usage: "Delete one or more releases",
|
||||||
Description: `Delete a release`,
|
Description: `Delete one or more releases`,
|
||||||
ArgsUsage: "<release tag>",
|
ArgsUsage: "<release tag> [<release tag>...]",
|
||||||
Action: runReleaseDelete,
|
Action: runReleaseDelete,
|
||||||
Flags: append([]cli.Flag{
|
Flags: append([]cli.Flag{
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
@ -39,9 +39,8 @@ func runReleaseDelete(cmd *cli.Context) error {
|
|||||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||||
client := ctx.Login.Client()
|
client := ctx.Login.Client()
|
||||||
|
|
||||||
tag := ctx.Args().First()
|
if !ctx.Args().Present() {
|
||||||
if len(tag) == 0 {
|
fmt.Println("Release tag needed to edit")
|
||||||
fmt.Println("Release tag needed to delete")
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,6 +49,7 @@ func runReleaseDelete(cmd *cli.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, tag := range ctx.Args().Slice() {
|
||||||
release, err := getReleaseByTag(ctx.Owner, ctx.Repo, tag, client)
|
release, err := getReleaseByTag(ctx.Owner, ctx.Repo, tag, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -63,6 +63,7 @@ func runReleaseDelete(cmd *cli.Context) error {
|
|||||||
_, err = client.DeleteTag(ctx.Owner, ctx.Repo, tag)
|
_, err = client.DeleteTag(ctx.Owner, ctx.Repo, tag)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,9 @@ import (
|
|||||||
var CmdReleaseEdit = cli.Command{
|
var CmdReleaseEdit = cli.Command{
|
||||||
Name: "edit",
|
Name: "edit",
|
||||||
Aliases: []string{"e"},
|
Aliases: []string{"e"},
|
||||||
Usage: "Edit a release",
|
Usage: "Edit one or more releases",
|
||||||
Description: `Edit a release`,
|
Description: `Edit one or more releases`,
|
||||||
ArgsUsage: "<release tag>",
|
ArgsUsage: "<release tag> [<release tag>...]",
|
||||||
Action: runReleaseEdit,
|
Action: runReleaseEdit,
|
||||||
Flags: append([]cli.Flag{
|
Flags: append([]cli.Flag{
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
@ -62,16 +62,6 @@ func runReleaseEdit(cmd *cli.Context) error {
|
|||||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||||
client := ctx.Login.Client()
|
client := ctx.Login.Client()
|
||||||
|
|
||||||
tag := ctx.Args().First()
|
|
||||||
if len(tag) == 0 {
|
|
||||||
fmt.Println("Release tag needed to edit")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
release, err := getReleaseByTag(ctx.Owner, ctx.Repo, tag, client)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var isDraft, isPre *bool
|
var isDraft, isPre *bool
|
||||||
if ctx.IsSet("draft") {
|
if ctx.IsSet("draft") {
|
||||||
isDraft = gitea.OptionalBool(strings.ToLower(ctx.String("draft"))[:1] == "t")
|
isDraft = gitea.OptionalBool(strings.ToLower(ctx.String("draft"))[:1] == "t")
|
||||||
@ -80,6 +70,17 @@ func runReleaseEdit(cmd *cli.Context) error {
|
|||||||
isPre = gitea.OptionalBool(strings.ToLower(ctx.String("prerelease"))[:1] == "t")
|
isPre = gitea.OptionalBool(strings.ToLower(ctx.String("prerelease"))[:1] == "t")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !ctx.Args().Present() {
|
||||||
|
fmt.Println("Release tag needed to edit")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tag := range ctx.Args().Slice() {
|
||||||
|
release, err := getReleaseByTag(ctx.Owner, ctx.Repo, tag, client)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
_, _, err = client.EditRelease(ctx.Owner, ctx.Repo, release.ID, gitea.EditReleaseOption{
|
_, _, err = client.EditRelease(ctx.Owner, ctx.Repo, release.ID, gitea.EditReleaseOption{
|
||||||
TagName: ctx.String("tag"),
|
TagName: ctx.String("tag"),
|
||||||
Target: ctx.String("target"),
|
Target: ctx.String("target"),
|
||||||
@ -88,5 +89,9 @@ func runReleaseEdit(cmd *cli.Context) error {
|
|||||||
IsDraft: isDraft,
|
IsDraft: isDraft,
|
||||||
IsPrerelease: isPre,
|
IsPrerelease: isPre,
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"code.gitea.io/sdk/gitea"
|
"code.gitea.io/sdk/gitea"
|
||||||
@ -51,6 +52,13 @@ func (ctx *TeaContext) GetListOptions() gitea.ListOptions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetRemoteRepoHTMLURL returns the web-ui url of the remote repo,
|
||||||
|
// after ensuring a remote repo is present in the context.
|
||||||
|
func (ctx *TeaContext) GetRemoteRepoHTMLURL() string {
|
||||||
|
ctx.Ensure(CtxRequirement{RemoteRepo: true})
|
||||||
|
return path.Join(ctx.Login.URL, ctx.Owner, ctx.Repo)
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure checks if requirements on the context are set, and terminates otherwise.
|
// Ensure checks if requirements on the context are set, and terminates otherwise.
|
||||||
func (ctx *TeaContext) Ensure(req CtxRequirement) {
|
func (ctx *TeaContext) Ensure(req CtxRequirement) {
|
||||||
if req.LocalRepo && ctx.LocalRepo == nil {
|
if req.LocalRepo && ctx.LocalRepo == nil {
|
||||||
|
@ -10,6 +10,18 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ArgsToIndices take issue/pull index as string and returns int64s
|
||||||
|
func ArgsToIndices(args []string) ([]int64, error) {
|
||||||
|
indices := make([]int64, len(args))
|
||||||
|
for i, arg := range args {
|
||||||
|
var err error
|
||||||
|
if indices[i], err = ArgToIndex(arg); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return indices, nil
|
||||||
|
}
|
||||||
|
|
||||||
// ArgToIndex take issue/pull index as string and return int64
|
// ArgToIndex take issue/pull index as string and return int64
|
||||||
func ArgToIndex(arg string) (int64, error) {
|
func ArgToIndex(arg string) (int64, error) {
|
||||||
if strings.HasPrefix(arg, "#") {
|
if strings.HasPrefix(arg, "#") {
|
||||||
|
Loading…
Reference in New Issue
Block a user