diff --git a/api/todo.go b/api/todo.go new file mode 100644 index 0000000000000000000000000000000000000000..1ca7b8cdb99c23c03fa43e598c51554d4debcc08 --- /dev/null +++ b/api/todo.go @@ -0,0 +1,33 @@ +package api + +import ( + "github.com/xanzy/go-gitlab" +) + +var ListTodos = func(client *gitlab.Client, opts *gitlab.ListTodosOptions, all bool) ([]*gitlab.Todo, error) { + var todos []*gitlab.Todo + var err error + if client == nil { + client = apiClient.Lab() + } + if opts.PerPage == 0 { + opts.PerPage = DefaultListLimit + } + if all { + todos_part, resp, _ := client.Todos.ListTodos(opts) + todos = append(todos, todos_part...) + var myopt gitlab.ListTodosOptions = *opts + for resp.NextPage != 0 { + myopt.Page = resp.NextPage + todos_part, resp, err = client.Todos.ListTodos(&myopt) + todos = append(todos, todos_part...) + } + } else { + todos, _, err = client.Todos.ListTodos(opts) + } + if err != nil { + return nil, err + } + + return todos, nil +} diff --git a/commands/root.go b/commands/root.go index 51a4f616404de8bf95f509c2e59b4669c9db9d3e..bdbf927fe06e72053394977dc9d157a821b4fada 100644 --- a/commands/root.go +++ b/commands/root.go @@ -23,6 +23,7 @@ import ( scheduleCmd "gitlab.com/gitlab-org/cli/commands/schedule" snippetCmd "gitlab.com/gitlab-org/cli/commands/snippet" sshCmd "gitlab.com/gitlab-org/cli/commands/ssh-key" + todoCmd "gitlab.com/gitlab-org/cli/commands/todo" updateCmd "gitlab.com/gitlab-org/cli/commands/update" userCmd "gitlab.com/gitlab-org/cli/commands/user" variableCmd "gitlab.com/gitlab-org/cli/commands/variable" @@ -120,6 +121,7 @@ func NewCmdRoot(f *cmdutils.Factory, version, buildDate string) *cobra.Command { rootCmd.AddCommand(apiCmd.NewCmdApi(f, nil)) rootCmd.AddCommand(scheduleCmd.NewCmdSchedule(f)) rootCmd.AddCommand(snippetCmd.NewCmdSnippet(f)) + rootCmd.AddCommand(todoCmd.NewCmdTodo(f)) rootCmd.Flags().BoolP("version", "v", false, "show glab version information") return rootCmd diff --git a/commands/todo/list/list.go b/commands/todo/list/list.go new file mode 100644 index 0000000000000000000000000000000000000000..71401f84bc26a48e4a7cdf733ee391722c975fec --- /dev/null +++ b/commands/todo/list/list.go @@ -0,0 +1,91 @@ +package list + +import ( + "encoding/json" + "fmt" + + "gitlab.com/gitlab-org/cli/api" + "gitlab.com/gitlab-org/cli/commands/cmdutils" + + "github.com/MakeNowJust/heredoc" + "github.com/spf13/cobra" + "github.com/xanzy/go-gitlab" +) + +func NewCmdList(f *cmdutils.Factory) *cobra.Command { + todoListCmd := &cobra.Command{ + Use: "list [flags]", + Short: `Get the list of TODO items`, + Example: heredoc.Doc(` + glab ci list + glab ci list --format=json + `), + Long: ``, + Args: cobra.ExactArgs(0), + RunE: func(cmd *cobra.Command, args []string) error { + var err error + var all bool + all = true + + apiClient, err := f.HttpClient() + if err != nil { + return err + } + + l := &gitlab.ListTodosOptions{} + + if m, _ := cmd.Flags().GetString("state"); m != "" { + l.State = gitlab.String(m) + } + if m, _ := cmd.Flags().GetString("type"); m != "" { + l.Type = gitlab.String(m) + } + if m, _ := cmd.Flags().GetBool("global"); !m { + repo, err := f.BaseRepo() + if err != nil { + return err + } + project, _ := repo.Project(apiClient) + l.ProjectID = &project.ID + } + if p, _ := cmd.Flags().GetInt("page"); p != 0 { + l.Page = p + all = false + } + if p, _ := cmd.Flags().GetInt("per-page"); p != 0 { + l.PerPage = p + all = false + } + + todos, err := api.ListTodos(apiClient, l, all) + if err != nil { + return err + } + + if m, _ := cmd.Flags().GetString("output-format"); m == "text" { + for _, t := range todos { + var milestone string + if t.Target.Milestone != nil { + milestone = t.Target.Milestone.Title + } else { + milestone = "nil" + } + fmt.Fprintf(f.IO.StdOut, "%s\t%s\t%s\t%s\t%s\n", t.Target.UpdatedAt, milestone, t.TargetType, t.Target.Title, t.Target.WebURL) + } + // fmt.Fprintf(f.IO.StdOut, "%s\n", todos) + } else { + todoListJSON, _ := json.Marshal(todos) + fmt.Fprintln(f.IO.StdOut, string(todoListJSON)) + } + return nil + }, + } + todoListCmd.Flags().StringP("output-format", "F", "text", "Format output as: text, json") + todoListCmd.Flags().BoolP("global", "g", false, "Global list of TODO") + todoListCmd.Flags().StringP("state", "s", "pending", "State of TODO. One of: pending, done") + todoListCmd.Flags().StringP("type", "t", "", "Type of TODO. One of: MergeRequest, Commit, Epic, DesignManagement::Design or AlertManagement::Alert") + // TODO todoListCmd.Flags().StringP("author", "a", "text", "Author of TODO") + // TODO todoListCmd.Flags().StringP("group", "g", "text", "Group of TODO") + + return todoListCmd +} diff --git a/commands/todo/todo.go b/commands/todo/todo.go new file mode 100644 index 0000000000000000000000000000000000000000..69aa5657ac11523c20ecdce4f514ba61cbbb6046 --- /dev/null +++ b/commands/todo/todo.go @@ -0,0 +1,25 @@ +package todo + +import ( + "github.com/MakeNowJust/heredoc" + "gitlab.com/gitlab-org/cli/commands/cmdutils" + + "github.com/spf13/cobra" + todoListCmd "gitlab.com/gitlab-org/cli/commands/todo/list" +) + +func NewCmdTodo(f *cmdutils.Factory) *cobra.Command { + issueCmd := &cobra.Command{ + Use: "todo [command] [flags]", + Short: `Work with GitLab todo`, + Long: ``, + Example: heredoc.Doc(` + glab todo list + `), + } + + cmdutils.EnableRepoOverride(issueCmd, f) + + issueCmd.AddCommand(todoListCmd.NewCmdList(f)) + return issueCmd +} diff --git a/docs/source/todo/help.md b/docs/source/todo/help.md new file mode 100644 index 0000000000000000000000000000000000000000..2e9ef308dd2010204984b061a72cf7486a530340 --- /dev/null +++ b/docs/source/todo/help.md @@ -0,0 +1,25 @@ +--- +stage: Create +group: Code Review +info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments +--- + + + +# `glab todo help` + +Help about any command + +```plaintext +glab todo help [command] [flags] +``` + +## Options inherited from parent commands + +```plaintext + --help Show help for command + -R, --repo OWNER/REPO Select another repository using the OWNER/REPO or `GROUP/NAMESPACE/REPO` format or full URL or git URL +``` diff --git a/docs/source/todo/index.md b/docs/source/todo/index.md new file mode 100755 index 0000000000000000000000000000000000000000..bdd4ebdd6181815004ca395045379bb437e40ff9 --- /dev/null +++ b/docs/source/todo/index.md @@ -0,0 +1,37 @@ +--- +stage: Create +group: Code Review +info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments +--- + + + +# `glab todo` + +Work with GitLab todo + +## Examples + +```plaintext +glab todo list + +``` + +## Options + +```plaintext + -R, --repo OWNER/REPO Select another repository using the OWNER/REPO or `GROUP/NAMESPACE/REPO` format or full URL or git URL +``` + +## Options inherited from parent commands + +```plaintext + --help Show help for command +``` + +## Subcommands + +- [list](list.md) diff --git a/docs/source/todo/list.md b/docs/source/todo/list.md new file mode 100644 index 0000000000000000000000000000000000000000..c8f2c95022ad2ffa7678df39df10e32627192e69 --- /dev/null +++ b/docs/source/todo/list.md @@ -0,0 +1,42 @@ +--- +stage: Create +group: Code Review +info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments +--- + + + +# `glab todo list` + +Get the list of TODO items + +```plaintext +glab todo list [flags] +``` + +## Examples + +```plaintext +glab ci list +glab ci list --format=json + +``` + +## Options + +```plaintext + -g, --global Global list of TODO + -F, --output-format string Format output as: text, json (default "text") + -s, --state string State of TODO. One of: pending, done (default "pending") + -t, --type string Type of TODO. One of: MergeRequest, Commit, Epic, DesignManagement::Design or AlertManagement::Alert +``` + +## Options inherited from parent commands + +```plaintext + --help Show help for command + -R, --repo OWNER/REPO Select another repository using the OWNER/REPO or `GROUP/NAMESPACE/REPO` format or full URL or git URL +```