├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE.md ├── Makefile ├── README.md ├── README.tpl.md ├── cli ├── cmd │ ├── add_alias_cmd.go │ ├── add_cmd.go │ ├── add_cmd_test.go │ ├── add_group_cmd.go │ ├── add_group_epic_note_cmd.go │ ├── add_group_var_cmd.go │ ├── add_project_badge_cmd.go │ ├── add_project_branch_cmd.go │ ├── add_project_cmd.go │ ├── add_project_environment_cmd.go │ ├── add_project_hook_cmd.go │ ├── add_project_issue_note_cmd.go │ ├── add_project_merge_request_note_cmd.go │ ├── add_project_protected_branch_cmd.go │ ├── add_project_snippet_note_cmd.go │ ├── add_project_star_cmd.go │ ├── add_project_var_cmd.go │ ├── ci_info_cmd.go │ ├── cmd_test.go │ ├── completion_cmd.go │ ├── config.go │ ├── doc.go │ ├── doc_cmd.go │ ├── get_cmd.go │ ├── get_cmd_test.go │ ├── get_current_user_cmd.go │ ├── get_group_cmd.go │ ├── get_group_var_cmd.go │ ├── get_namespace_cmd.go │ ├── get_project_badge_cmd.go │ ├── get_project_branch_cmd.go │ ├── get_project_cmd.go │ ├── get_project_hook_cmd.go │ ├── get_project_job_cancel_cmd.go │ ├── get_project_job_cmd.go │ ├── get_project_job_retry_cmd.go │ ├── get_project_job_trace_cmd.go │ ├── get_project_merge_request_cmd.go │ ├── get_project_merge_request_cmd_test.go │ ├── get_project_merge_request_note_cmd.go │ ├── get_project_pipeline_cmd.go │ ├── get_project_var_cmd.go │ ├── get_runner_cmd.go │ ├── get_user_cmd.go │ ├── get_user_cmd_test.go │ ├── init_cmd.go │ ├── list_aliases_cmd.go │ ├── list_cmd.go │ ├── list_cmd_test.go │ ├── list_group_epic_notes_cmd.go │ ├── list_group_merge_requests_cmd.go │ ├── list_group_merge_requests_cmd_test.go │ ├── list_group_variables_cmd.go │ ├── list_groups_cmd.go │ ├── list_groups_cmd_test.go │ ├── list_merge_requests_cmd.go │ ├── list_merge_requests_cmd_test.go │ ├── list_namespaces_cmd.go │ ├── list_namespaces_cmd_test.go │ ├── list_project_badges_cmd.go │ ├── list_project_branches_cmd.go │ ├── list_project_commits.go │ ├── list_project_environments_cmd.go │ ├── list_project_environments_cmd_test.go │ ├── list_project_hooks_cmd.go │ ├── list_project_issue_notes_cmd.go │ ├── list_project_issue_notes_cmd_test.go │ ├── list_project_jobs_cmd.go │ ├── list_project_members_cmd.go │ ├── list_project_merge_request_commits_cmd.go │ ├── list_project_merge_request_notes_cmd.go │ ├── list_project_merge_request_notes_cmd_test.go │ ├── list_project_merge_requests_cmd.go │ ├── list_project_merge_requests_cmd_test.go │ ├── list_project_pipeline_jobs_cmd.go │ ├── list_project_pipelines_cmd.go │ ├── list_project_protected_branches_cmd.go │ ├── list_project_snippet_notes_cmd.go │ ├── list_project_snippet_notes_cmd_test.go │ ├── list_project_variables_cmd.go │ ├── list_projects_cmd.go │ ├── list_projects_cmd_test.go │ ├── list_runners_cmd.go │ ├── list_runners_cmd_test.go │ ├── list_ssh_keys_cmd.go │ ├── list_ssh_keys_cmd_test.go │ ├── list_user_ssh_keys_cmd.go │ ├── list_user_ssh_keys_cmd_test.go │ ├── list_users_cmd.go │ ├── list_users_cmd_test.go │ ├── output.go │ ├── output_config.go │ ├── prompt.go │ ├── prompt_vars.go │ ├── related.go │ ├── resources.go │ ├── rm_alias_cmd.go │ ├── rm_cmd.go │ ├── rm_cmd_test.go │ ├── rm_group_cmd.go │ ├── rm_group_epic_note_cmd.go │ ├── rm_group_var_cmd.go │ ├── rm_project_badge_cmd.go │ ├── rm_project_branch_cmd.go │ ├── rm_project_cmd.go │ ├── rm_project_environment_cmd.go │ ├── rm_project_hook_cmd.go │ ├── rm_project_issue_note_cmd.go │ ├── rm_project_merge_request_note_cmd.go │ ├── rm_project_merged_branches_cmd.go │ ├── rm_project_protected_branch_cmd.go │ ├── rm_project_snippet_note_cmd.go │ ├── rm_project_star_cmd.go │ ├── rm_project_var_cmd.go │ ├── root_cmd.go │ ├── root_cmd_test.go │ └── version_cmd.go ├── main.go └── output │ ├── badges.go │ ├── branches.go │ ├── commits.go │ ├── environments.go │ ├── groups.go │ ├── hooks.go │ ├── jobs.go │ ├── members.go │ ├── merge_requests.go │ ├── namespaces.go │ ├── notes.go │ ├── output.go │ ├── pipelines.go │ ├── projects.go │ ├── runners.go │ ├── ssh_keys.go │ ├── users.go │ └── variables.go ├── gitlab ├── badges.go ├── badges_test.go ├── branches.go ├── branches_test.go ├── builds.go ├── ci_info.go ├── ci_info_test.go ├── commits.go ├── commits_test.go ├── deploy_keys.go ├── environments.go ├── environments_test.go ├── events.go ├── gitlab.go ├── gitlab_test.go ├── groups.go ├── groups_test.go ├── helper_test.go ├── hook_payload.go ├── hooks.go ├── issues.go ├── jobs.go ├── members.go ├── members_test.go ├── merge_requests.go ├── merge_requests_test.go ├── milestones.go ├── namespaces.go ├── namespaces_test.go ├── notes.go ├── notes_test.go ├── pipelines.go ├── projects.go ├── projects_test.go ├── protected_branches.go ├── render.go ├── repositories.go ├── runners.go ├── runners_test.go ├── ssh_keys.go ├── ssh_keys_test.go ├── users.go ├── users_test.go └── variables.go ├── mocks ├── files │ ├── badges │ │ ├── badge_1.json │ │ └── badges.json │ ├── branches │ │ └── branches.json │ ├── commits │ │ ├── commit.json │ │ ├── commit_diff.json │ │ ├── commit_refs.json │ │ ├── commit_statuses.json │ │ ├── commits.json │ │ └── merge_request_commits.json │ ├── environments │ │ └── environments.json │ ├── groups │ │ └── groups.json │ ├── members │ │ └── members.json │ ├── merge_requests │ │ ├── merge_request.json │ │ └── merge_requests.json │ ├── namespaces │ │ ├── namespaces.json │ │ └── namespaces_search.json │ ├── notes │ │ ├── issue_notes.json │ │ ├── merge_request_notes.json │ │ └── snippet_notes.json │ ├── projects │ │ └── projects.json │ ├── runners │ │ └── runners.json │ ├── ssh_keys │ │ └── ssh_keys.json │ └── users │ │ ├── user_1.json │ │ └── users.json └── mappings │ ├── badges │ ├── project_1_badge_1.json │ └── project_1_badges.json │ ├── branches │ └── project_1_branches.json │ ├── commits │ ├── project_1_commit_6104942438c14ec7bd21c6cd5bd995272b3faff6.json │ ├── project_1_commits.json │ └── project_1_merge_request_1_commits.json │ ├── environments │ └── project_1_environments.json │ ├── groups │ └── groups.json │ ├── members │ ├── group_1_members.json │ └── project_1_members.json │ ├── merge_requests │ ├── group_merge_requests.json │ ├── merge_requests.json │ ├── project_1_merge_request_1.json │ └── project_merge_requests.json │ ├── namespaces │ ├── namespaces.json │ └── namespaces_search.json │ ├── notes │ ├── project_1_issue_5_notes.json │ ├── project_1_merge_request_3_notes.json │ └── project_1_snippet_7_notes.json │ ├── projects │ └── projects.json │ ├── runners │ └── runners.json │ ├── ssh_keys │ ├── current_user_ssh_keys.json │ └── user_1_ssh_keys.json │ └── users │ ├── user_1.json │ └── users.json ├── snapshots ├── add_help.snap ├── get_help.snap ├── get_project_merge_request.snap ├── get_project_merge_request_help.snap ├── get_project_merge_request_json.snap ├── get_project_merge_request_no_arg.snap ├── get_project_merge_request_no_merge_request_iid.snap ├── get_project_merge_request_verbose.snap ├── get_project_merge_request_yaml.snap ├── get_user.snap ├── get_user_help.snap ├── get_user_json.snap ├── get_user_no_arg.snap ├── get_user_verbose.snap ├── get_user_yaml.snap ├── help.snap ├── list_group_merge_requests.snap ├── list_group_merge_requests_help.snap ├── list_group_merge_requests_json.snap ├── list_group_merge_requests_yaml.snap ├── list_groups.snap ├── list_groups_help.snap ├── list_groups_json.snap ├── list_groups_yaml.snap ├── list_help.snap ├── list_merge_requests.snap ├── list_merge_requests_help.snap ├── list_merge_requests_json.snap ├── list_merge_requests_yaml.snap ├── list_namespaces.snap ├── list_namespaces_help.snap ├── list_namespaces_json.snap ├── list_namespaces_search.snap ├── list_namespaces_yaml.snap ├── list_project_environments.snap ├── list_project_environments_help.snap ├── list_project_environments_json.snap ├── list_project_environments_yaml.snap ├── list_project_issue_notes.snap ├── list_project_issue_notes_help.snap ├── list_project_issue_notes_json.snap ├── list_project_issue_notes_no_issue_iid.snap ├── list_project_issue_notes_no_project_id.snap ├── list_project_issue_notes_yaml.snap ├── list_project_merge_request_notes.snap ├── list_project_merge_request_notes_help.snap ├── list_project_merge_request_notes_json.snap ├── list_project_merge_request_notes_no_issue_iid.snap ├── list_project_merge_request_notes_no_merge_request_iid.snap ├── list_project_merge_request_notes_no_project_id.snap ├── list_project_merge_request_notes_yaml.snap ├── list_project_merge_requests.snap ├── list_project_merge_requests_help.snap ├── list_project_merge_requests_json.snap ├── list_project_merge_requests_yaml.snap ├── list_project_snippet_notes.snap ├── list_project_snippet_notes_help.snap ├── list_project_snippet_notes_json.snap ├── list_project_snippet_notes_no_project_id.snap ├── list_project_snippet_notes_no_snippet_id.snap ├── list_project_snippet_notes_yaml.snap ├── list_projects.snap ├── list_projects_help.snap ├── list_projects_json.snap ├── list_projects_yaml.snap ├── list_runners.snap ├── list_runners_help.snap ├── list_runners_json.snap ├── list_runners_yaml.snap ├── list_ssh_keys.snap ├── list_ssh_keys_help.snap ├── list_ssh_keys_json.snap ├── list_ssh_keys_yaml.snap ├── list_user_ssh_keys.snap ├── list_user_ssh_keys_help.snap ├── list_user_ssh_keys_json.snap ├── list_user_ssh_keys_yaml.snap ├── list_users.snap ├── list_users_help.snap ├── list_users_json.snap ├── list_users_yaml.snap └── rm_help.snap └── test ├── cli.go ├── cli_config.go ├── config.go ├── server.go └── utils.go /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea 3 | /data 4 | /bin 5 | /auto 6 | .glc* 7 | cli/glc 8 | cli/build -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - "1.x" 5 | - "1.9" 6 | - "1.10.x" 7 | - master 8 | 9 | go_import_path: github.com/plouc/go-gitlab-client 10 | 11 | sudo: required 12 | 13 | services: 14 | - docker 15 | 16 | before_install: 17 | - docker pull golang:1.9-alpine 18 | 19 | script: 20 | - make install --no-print-directory 21 | - make test --no-print-directory 22 | - make cli_build_all --no-print-directory 23 | - make cli_checksums --no-print-directory 24 | 25 | deploy: 26 | provider: releases 27 | api_key: 28 | secure: UXQgBNdZdK+Y8GFB/qgS4KclcfH7fWSsh6Wy1gGCEEKvGpJ1JXd3zng9FWDfYIII00Oe6c9rS2wEeJIE+5w1cPr+KXic8OcYoAA6gGZ26tibsz6zkKHV5++Qako5t714R54+7Icjm50RcIe3+BG0Ze0n4m6qfFGgEracpZxEjjI= 29 | file: 30 | - cli/build/darwin-amd64-glc 31 | - cli/build/linux-amd64-glc 32 | - cli/build/linux-386-glc 33 | - cli/build/linux-arm-glc 34 | - cli/build/linux-arm64-glc 35 | - cli/build/alpine-amd64-glc 36 | - cli/build/checksums.txt 37 | on: 38 | repo: plouc/go-gitlab-client 39 | tags: true 40 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to go-gitlab-client 2 | 3 | - [Setup](#setting-up-working-environment) 4 | - [Build](#building-cli-binary) 5 | 6 | ## Setting up working environment 7 | 8 | Please run: 9 | 10 | ``` 11 | make install 12 | ``` 13 | 14 | ## Building CLI binary 15 | 16 | The following command will generate CLI binary for various platforms: 17 | 18 | ``` 19 | make cli_build_all 20 | ``` 21 | 22 | You'll find generated files in `cli/build`. 23 | You can use one of the generated build in `cli/build` according to your platform. 24 | 25 | You can also generate checksums for the binaries: 26 | 27 | ``` 28 | make cli_checksums 29 | ``` 30 | 31 | Which will then be available in `cli/build/checksums.txt`. 32 | 33 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) Raphaël Benitte 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /cli/cmd/add_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/spf13/cobra" 5 | ) 6 | 7 | func init() { 8 | RootCmd.AddCommand(addCmd) 9 | } 10 | 11 | var addCmd = &cobra.Command{ 12 | Use: "add", 13 | Short: "Add resource", 14 | } 15 | -------------------------------------------------------------------------------- /cli/cmd/add_cmd_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | ) 8 | 9 | func TestAddCmd(t *testing.T) { 10 | test.RunCommandTestCases(t, "users", []*test.CommandTestCase{ 11 | { 12 | []string{"add"}, 13 | nil, 14 | //configs["default"], 15 | "add_help", 16 | false, 17 | nil, 18 | }, 19 | { 20 | []string{"add", "--help"}, 21 | nil, 22 | //configs["default"], 23 | "add_help", 24 | false, 25 | nil, 26 | }, 27 | }) 28 | } 29 | -------------------------------------------------------------------------------- /cli/cmd/add_group_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | "github.com/manifoldco/promptui" 8 | out "github.com/plouc/go-gitlab-client/cli/output" 9 | "github.com/plouc/go-gitlab-client/gitlab" 10 | "github.com/spf13/cobra" 11 | ) 12 | 13 | func init() { 14 | addCmd.AddCommand(addGroupCmd) 15 | } 16 | 17 | var addGroupCmd = &cobra.Command{ 18 | Use: "group", 19 | Aliases: []string{"g"}, 20 | Short: "Create a new group", 21 | Run: func(cmd *cobra.Command, args []string) { 22 | color.Yellow("Creating group…") 23 | 24 | group := gitlab.GroupAddPayload{} 25 | 26 | prompt := promptui.Prompt{ 27 | Label: "Name", 28 | } 29 | name, err := prompt.Run() 30 | if err != nil { 31 | fmt.Printf("Prompt failed %v\n", err) 32 | return 33 | } 34 | group.Name = name 35 | 36 | prompt = promptui.Prompt{ 37 | Label: "Path", 38 | } 39 | path, err := prompt.Run() 40 | if err != nil { 41 | fmt.Printf("Prompt failed %v\n", err) 42 | return 43 | } 44 | group.Path = path 45 | 46 | loader.Start() 47 | createdGroup, meta, err := client.AddGroup(&group) 48 | loader.Stop() 49 | 50 | out.Group(output, outputFormat, createdGroup) 51 | 52 | printMeta(meta, false) 53 | }, 54 | } 55 | -------------------------------------------------------------------------------- /cli/cmd/add_group_epic_note_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/fatih/color" 7 | "github.com/manifoldco/promptui" 8 | out "github.com/plouc/go-gitlab-client/cli/output" 9 | "github.com/plouc/go-gitlab-client/gitlab" 10 | "github.com/spf13/cobra" 11 | ) 12 | 13 | func init() { 14 | addCmd.AddCommand(addGroupEpicNoteCmd) 15 | } 16 | 17 | var addGroupEpicNoteCmd = &cobra.Command{ 18 | Use: resourceCmd("group-epic-note", "group-epic"), 19 | Aliases: []string{"epic-note"}, 20 | Short: "Add group epic note", 21 | RunE: func(cmd *cobra.Command, args []string) error { 22 | ids, err := config.aliasIdsOrArgs(currentAlias, "group-epic", args) 23 | if err != nil { 24 | return err 25 | } 26 | 27 | epicId, err := strconv.Atoi(ids["epic_id"]) 28 | if err != nil { 29 | return err 30 | } 31 | 32 | color.Yellow("Creating note for group epic (group id: %s, epic id: %d)…", ids["project_id"], epicId) 33 | 34 | note := new(gitlab.NoteAddPayload) 35 | 36 | prompt := promptui.Prompt{ 37 | Label: "Body", 38 | } 39 | body, err := prompt.Run() 40 | if err != nil { 41 | return err 42 | } 43 | note.Body = body 44 | 45 | loader.Start() 46 | createdNote, meta, err := client.AddGroupEpicNote(ids["project_id"], epicId, note) 47 | loader.Stop() 48 | if err != nil { 49 | return err 50 | } 51 | 52 | out.Note(output, outputFormat, createdNote) 53 | 54 | printMeta(meta, false) 55 | 56 | return nil 57 | }, 58 | } 59 | -------------------------------------------------------------------------------- /cli/cmd/add_group_var_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/fatih/color" 5 | out "github.com/plouc/go-gitlab-client/cli/output" 6 | "github.com/spf13/cobra" 7 | ) 8 | 9 | func init() { 10 | addCmd.AddCommand(addGroupVarCmd) 11 | } 12 | 13 | var addGroupVarCmd = &cobra.Command{ 14 | Use: resourceCmd("group-var", "group"), 15 | Aliases: []string{"gv"}, 16 | Short: "Create a new group variable", 17 | RunE: func(cmd *cobra.Command, args []string) error { 18 | ids, err := config.aliasIdsOrArgs(currentAlias, "group", args) 19 | if err != nil { 20 | return err 21 | } 22 | 23 | color.Yellow("Creating variable for group (group id: %s)…", ids["group_id"]) 24 | 25 | variable, err := promptVariable() 26 | if err != nil { 27 | return err 28 | } 29 | 30 | loader.Start() 31 | createdVariable, meta, err := client.AddGroupVariable(ids["group_id"], variable) 32 | loader.Stop() 33 | if err != nil { 34 | return err 35 | } 36 | 37 | out.Variable(output, outputFormat, createdVariable) 38 | 39 | printMeta(meta, false) 40 | 41 | return nil 42 | }, 43 | } 44 | -------------------------------------------------------------------------------- /cli/cmd/add_project_badge_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/fatih/color" 5 | "github.com/manifoldco/promptui" 6 | out "github.com/plouc/go-gitlab-client/cli/output" 7 | "github.com/plouc/go-gitlab-client/gitlab" 8 | "github.com/spf13/cobra" 9 | ) 10 | 11 | func init() { 12 | addCmd.AddCommand(addProjectBadgeCmd) 13 | } 14 | 15 | var addProjectBadgeCmd = &cobra.Command{ 16 | Use: resourceCmd("project-badge", "project"), 17 | Aliases: []string{"pbdg"}, 18 | Short: "Create project badge", 19 | RunE: func(cmd *cobra.Command, args []string) error { 20 | ids, err := config.aliasIdsOrArgs(currentAlias, "project", args) 21 | if err != nil { 22 | return err 23 | } 24 | 25 | color.Yellow("Creating project's badge (project id: %s)…", ids["project_id"]) 26 | 27 | badge := new(gitlab.Badge) 28 | 29 | prompt := promptui.Prompt{ 30 | Label: "LinkUrl", 31 | } 32 | linkUrl, err := prompt.Run() 33 | if err != nil { 34 | return err 35 | } 36 | badge.LinkUrl = linkUrl 37 | 38 | prompt = promptui.Prompt{ 39 | Label: "ImageUrl", 40 | } 41 | imageUrl, err := prompt.Run() 42 | if err != nil { 43 | return err 44 | } 45 | badge.ImageUrl = imageUrl 46 | 47 | loader.Start() 48 | createdBadge, meta, err := client.AddProjectBadge(ids["project_id"], badge) 49 | loader.Stop() 50 | if err != nil { 51 | return err 52 | } 53 | 54 | out.Badge(output, outputFormat, createdBadge) 55 | 56 | printMeta(meta, false) 57 | 58 | return nil 59 | }, 60 | } 61 | -------------------------------------------------------------------------------- /cli/cmd/add_project_branch_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/fatih/color" 5 | out "github.com/plouc/go-gitlab-client/cli/output" 6 | "github.com/spf13/cobra" 7 | ) 8 | 9 | var branchName, ref string 10 | 11 | func init() { 12 | addCmd.AddCommand(addProjectBranchCmd) 13 | 14 | addProjectBranchCmd.Flags().StringVarP(&branchName, "branch", "b", "", "Name of the branch") 15 | addProjectBranchCmd.Flags().StringVarP(&ref, "ref", "r", "", " The branch name or commit SHA to create branch from") 16 | } 17 | 18 | var addProjectBranchCmd = &cobra.Command{ 19 | Use: resourceCmd("project-branch", "project"), 20 | Aliases: []string{"pb"}, 21 | Short: "Create project branch", 22 | RunE: func(cmd *cobra.Command, args []string) error { 23 | ids, err := config.aliasIdsOrArgs(currentAlias, "project", args) 24 | if err != nil { 25 | return err 26 | } 27 | 28 | color.Yellow("Creating project's branch %s from %s (project id: %s)…", branchName, ref, ids["project_id"]) 29 | 30 | loader.Start() 31 | createdBranch, meta, err := client.AddProjectBranch(ids["project_id"], branchName, ref) 32 | loader.Stop() 33 | if err != nil { 34 | return err 35 | } 36 | 37 | out.Branch(output, outputFormat, createdBranch) 38 | 39 | printMeta(meta, false) 40 | 41 | return nil 42 | }, 43 | } 44 | -------------------------------------------------------------------------------- /cli/cmd/add_project_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | "github.com/manifoldco/promptui" 8 | out "github.com/plouc/go-gitlab-client/cli/output" 9 | "github.com/plouc/go-gitlab-client/gitlab" 10 | "github.com/spf13/cobra" 11 | ) 12 | 13 | func init() { 14 | addCmd.AddCommand(addProjectCmd) 15 | } 16 | 17 | var addProjectCmd = &cobra.Command{ 18 | Use: "project", 19 | Aliases: []string{"p"}, 20 | Short: "Create a new project", 21 | Run: func(cmd *cobra.Command, args []string) { 22 | color.Yellow("Creating project…") 23 | 24 | project := gitlab.ProjectAddPayload{} 25 | 26 | prompt := promptui.Prompt{ 27 | Label: "Name", 28 | } 29 | name, err := prompt.Run() 30 | if err != nil { 31 | fmt.Printf("Prompt failed %v\n", err) 32 | return 33 | } 34 | project.Name = name 35 | 36 | prompt = promptui.Prompt{ 37 | Label: "Path", 38 | } 39 | path, err := prompt.Run() 40 | if err != nil { 41 | fmt.Printf("Prompt failed %v\n", err) 42 | return 43 | } 44 | project.Path = path 45 | 46 | loader.Start() 47 | createdProject, meta, err := client.AddProject(&project) 48 | loader.Stop() 49 | 50 | out.Project(output, outputFormat, createdProject, false) 51 | 52 | printMeta(meta, false) 53 | }, 54 | } 55 | -------------------------------------------------------------------------------- /cli/cmd/add_project_issue_note_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/fatih/color" 7 | "github.com/manifoldco/promptui" 8 | out "github.com/plouc/go-gitlab-client/cli/output" 9 | "github.com/plouc/go-gitlab-client/gitlab" 10 | "github.com/spf13/cobra" 11 | ) 12 | 13 | func init() { 14 | addCmd.AddCommand(addProjectIssueNoteCmd) 15 | } 16 | 17 | var addProjectIssueNoteCmd = &cobra.Command{ 18 | Use: resourceCmd("project-issue-note", "project-issue"), 19 | Aliases: []string{"issue-note"}, 20 | Short: "Add project issue note", 21 | RunE: func(cmd *cobra.Command, args []string) error { 22 | ids, err := config.aliasIdsOrArgs(currentAlias, "project-issue", args) 23 | if err != nil { 24 | return err 25 | } 26 | 27 | issueIid, err := strconv.Atoi(ids["issue_iid"]) 28 | if err != nil { 29 | return err 30 | } 31 | 32 | color.Yellow("Creating note for project issue (project id: %s, issue iid: %d)…", ids["project_id"], issueIid) 33 | 34 | note := new(gitlab.NoteAddPayload) 35 | 36 | prompt := promptui.Prompt{ 37 | Label: "Body", 38 | } 39 | body, err := prompt.Run() 40 | if err != nil { 41 | return err 42 | } 43 | note.Body = body 44 | 45 | loader.Start() 46 | createdNote, meta, err := client.AddProjectIssueNote(ids["project_id"], issueIid, note) 47 | loader.Stop() 48 | if err != nil { 49 | return err 50 | } 51 | 52 | out.Note(output, outputFormat, createdNote) 53 | 54 | printMeta(meta, false) 55 | 56 | return nil 57 | }, 58 | } 59 | -------------------------------------------------------------------------------- /cli/cmd/add_project_merge_request_note_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/fatih/color" 7 | "github.com/manifoldco/promptui" 8 | out "github.com/plouc/go-gitlab-client/cli/output" 9 | "github.com/plouc/go-gitlab-client/gitlab" 10 | "github.com/spf13/cobra" 11 | ) 12 | 13 | func init() { 14 | addCmd.AddCommand(addProjectMergeRequestNoteCmd) 15 | } 16 | 17 | var addProjectMergeRequestNoteCmd = &cobra.Command{ 18 | Use: resourceCmd("project-merge-request-note", "project-merge-request"), 19 | Aliases: []string{"merge-request-note", "mr-note"}, 20 | Short: "Add project issue note", 21 | RunE: func(cmd *cobra.Command, args []string) error { 22 | ids, err := config.aliasIdsOrArgs(currentAlias, "project-merge-request", args) 23 | if err != nil { 24 | return err 25 | } 26 | 27 | mergeRequestIid, err := strconv.Atoi(ids["merge_request_iid"]) 28 | if err != nil { 29 | return err 30 | } 31 | 32 | color.Yellow("Creating note for project merge request (project id: %s, merge request iid: %d)…", ids["project_id"], mergeRequestIid) 33 | 34 | note := new(gitlab.NoteAddPayload) 35 | 36 | prompt := promptui.Prompt{ 37 | Label: "Body", 38 | } 39 | body, err := prompt.Run() 40 | if err != nil { 41 | return err 42 | } 43 | note.Body = body 44 | 45 | loader.Start() 46 | createdNote, meta, err := client.AddProjectMergeRequestNote(ids["project_id"], mergeRequestIid, note) 47 | loader.Stop() 48 | if err != nil { 49 | return err 50 | } 51 | 52 | out.Note(output, outputFormat, createdNote) 53 | 54 | printMeta(meta, false) 55 | 56 | return nil 57 | }, 58 | } 59 | -------------------------------------------------------------------------------- /cli/cmd/add_project_protected_branch_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/fatih/color" 5 | "github.com/spf13/cobra" 6 | ) 7 | 8 | func init() { 9 | addCmd.AddCommand(addProjectProtectedBranchCmd) 10 | } 11 | 12 | var addProjectProtectedBranchCmd = &cobra.Command{ 13 | Use: resourceCmd("project-protected-branch", "project-branch"), 14 | Aliases: []string{"ppb"}, 15 | Short: "Protect project branch", 16 | RunE: func(cmd *cobra.Command, args []string) error { 17 | ids, err := config.aliasIdsOrArgs(currentAlias, "project-branch", args) 18 | if err != nil { 19 | return err 20 | } 21 | 22 | color.Yellow("Protecting project branch (project id: %s, branch name: %s)…", ids["project_id"], ids["branch_name"]) 23 | 24 | loader.Start() 25 | meta, err := client.ProtectBranch(ids["project_id"], ids["branch_name"]) 26 | loader.Stop() 27 | if err != nil { 28 | return err 29 | } 30 | 31 | printMeta(meta, false) 32 | 33 | return nil 34 | }, 35 | } 36 | -------------------------------------------------------------------------------- /cli/cmd/add_project_snippet_note_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/fatih/color" 7 | "github.com/manifoldco/promptui" 8 | out "github.com/plouc/go-gitlab-client/cli/output" 9 | "github.com/plouc/go-gitlab-client/gitlab" 10 | "github.com/spf13/cobra" 11 | ) 12 | 13 | func init() { 14 | addCmd.AddCommand(addProjectSnippetNoteCmd) 15 | } 16 | 17 | var addProjectSnippetNoteCmd = &cobra.Command{ 18 | Use: resourceCmd("project-snippet-note", "project-snippet"), 19 | Aliases: []string{"snippet-note"}, 20 | Short: "Add project snippet note", 21 | RunE: func(cmd *cobra.Command, args []string) error { 22 | ids, err := config.aliasIdsOrArgs(currentAlias, "project-snippet", args) 23 | if err != nil { 24 | return err 25 | } 26 | 27 | snippetId, err := strconv.Atoi(ids["snippet_id"]) 28 | if err != nil { 29 | return err 30 | } 31 | 32 | color.Yellow("Creating note for project snippet (project id: %s, snippet id: %d)…", ids["project_id"], snippetId) 33 | 34 | note := new(gitlab.NoteAddPayload) 35 | 36 | prompt := promptui.Prompt{ 37 | Label: "Body", 38 | } 39 | body, err := prompt.Run() 40 | if err != nil { 41 | return err 42 | } 43 | note.Body = body 44 | 45 | loader.Start() 46 | createdNote, meta, err := client.AddProjectSnippetNote(ids["project_id"], snippetId, note) 47 | loader.Stop() 48 | if err != nil { 49 | return err 50 | } 51 | 52 | out.Note(output, outputFormat, createdNote) 53 | 54 | printMeta(meta, false) 55 | 56 | return nil 57 | }, 58 | } 59 | -------------------------------------------------------------------------------- /cli/cmd/add_project_star_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/fatih/color" 5 | out "github.com/plouc/go-gitlab-client/cli/output" 6 | "github.com/spf13/cobra" 7 | ) 8 | 9 | func init() { 10 | addCmd.AddCommand(addProjectStarCmd) 11 | } 12 | 13 | var addProjectStarCmd = &cobra.Command{ 14 | Use: resourceCmd("project-star", "project"), 15 | Aliases: []string{"ps"}, 16 | Short: "Stars a given project", 17 | RunE: func(cmd *cobra.Command, args []string) error { 18 | ids, err := config.aliasIdsOrArgs(currentAlias, "project", args) 19 | if err != nil { 20 | return err 21 | } 22 | 23 | color.Yellow("Staring project (project id: %s)…", ids["project_id"]) 24 | 25 | loader.Start() 26 | project, meta, err := client.StarProject(ids["project_id"]) 27 | loader.Stop() 28 | if err != nil { 29 | return err 30 | } 31 | 32 | if meta.StatusCode == 304 { 33 | color.Red("\n You already stared project %s!", ids["project_id"]) 34 | } 35 | 36 | if project != nil { 37 | out.Project(output, outputFormat, project, false) 38 | } 39 | 40 | printMeta(meta, false) 41 | 42 | return nil 43 | }, 44 | } 45 | -------------------------------------------------------------------------------- /cli/cmd/add_project_var_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/fatih/color" 5 | out "github.com/plouc/go-gitlab-client/cli/output" 6 | "github.com/spf13/cobra" 7 | ) 8 | 9 | func init() { 10 | addCmd.AddCommand(addProjectVarCmd) 11 | } 12 | 13 | var addProjectVarCmd = &cobra.Command{ 14 | Use: resourceCmd("project-var", "project"), 15 | Aliases: []string{"pv"}, 16 | Short: "Create a new project variable", 17 | RunE: func(cmd *cobra.Command, args []string) error { 18 | ids, err := config.aliasIdsOrArgs(currentAlias, "project", args) 19 | if err != nil { 20 | return err 21 | } 22 | 23 | color.Yellow("Creating variable for project (project id: %s)…", ids["project_id"]) 24 | 25 | variable, err := promptVariable() 26 | if err != nil { 27 | return err 28 | } 29 | 30 | loader.Start() 31 | createdVariable, meta, err := client.AddProjectVariable(ids["project_id"], variable) 32 | loader.Stop() 33 | if err != nil { 34 | return err 35 | } 36 | 37 | out.Variable(output, outputFormat, createdVariable) 38 | 39 | printMeta(meta, false) 40 | 41 | return nil 42 | }, 43 | } 44 | -------------------------------------------------------------------------------- /cli/cmd/ci_info_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/plouc/go-gitlab-client/gitlab" 5 | "github.com/spf13/cobra" 6 | "os" 7 | ) 8 | 9 | func init() { 10 | RootCmd.AddCommand(ciInfoCmd) 11 | } 12 | 13 | var ciInfoCmd = &cobra.Command{ 14 | Use: "ci-info", 15 | Aliases: []string{"ci"}, 16 | Short: "Print information about CI environment", 17 | Run: func(cmd *cobra.Command, args []string) { 18 | i, err := gitlab.GetCiInfo() 19 | if err != nil { 20 | panic(err) 21 | } 22 | 23 | i.RenderJson(os.Stdout) 24 | }, 25 | } 26 | -------------------------------------------------------------------------------- /cli/cmd/cmd_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "os" 5 | "testing" 6 | 7 | "github.com/plouc/go-gitlab-client/test" 8 | ) 9 | 10 | func TestMain(m *testing.M) { 11 | test.BuildCli() 12 | 13 | os.Exit(m.Run()) 14 | } 15 | -------------------------------------------------------------------------------- /cli/cmd/completion_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "github.com/spf13/cobra" 6 | ) 7 | 8 | func init() { 9 | RootCmd.AddCommand(completionCmd) 10 | } 11 | 12 | var completionCmd = &cobra.Command{ 13 | Use: "completion [shell]", 14 | Aliases: []string{"c"}, 15 | Short: "Output shell completion code for the specified shell (bash or zsh)", 16 | Long: `Output shell completion code for the specified shell (bash or zsh). 17 | The shell code must be evaluated to provide interactive 18 | completion of glc commands. 19 | This can be done by sourcing it from the .bash_profile or .zshrc. 20 | For bash you can run: 21 | 22 | echo "source <(kubectl completion bash)" >> ~/.bashrc 23 | `, 24 | Args: func(cmd *cobra.Command, args []string) error { 25 | if len(args) < 1 { 26 | return fmt.Errorf("you must specify a shell") 27 | } 28 | 29 | return nil 30 | }, 31 | Run: func(cmd *cobra.Command, args []string) { 32 | shell := args[0] 33 | 34 | if shell == "bash" { 35 | RootCmd.GenBashCompletion(output) 36 | } else if shell == "zsh" { 37 | RootCmd.GenZshCompletion(output) 38 | } 39 | }, 40 | } 41 | -------------------------------------------------------------------------------- /cli/cmd/doc_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "bytes" 5 | "os" 6 | 7 | "github.com/spf13/cobra" 8 | ) 9 | 10 | func init() { 11 | RootCmd.AddCommand(docCmd) 12 | } 13 | 14 | var docCmd = &cobra.Command{ 15 | Use: "doc", 16 | Short: "Generate CLI documentation in markdown format", 17 | Run: func(cmd *cobra.Command, args []string) { 18 | navBuf := new(bytes.Buffer) 19 | treeBuf := new(bytes.Buffer) 20 | 21 | navBuf.WriteString("\n\n") 22 | genCommandDoc(navBuf, treeBuf, RootCmd) 23 | navBuf.WriteString("\n\n\n") 24 | 25 | navBuf.WriteTo(os.Stdout) 26 | treeBuf.WriteTo(os.Stdout) 27 | }, 28 | } 29 | -------------------------------------------------------------------------------- /cli/cmd/get_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/spf13/cobra" 5 | ) 6 | 7 | func init() { 8 | RootCmd.AddCommand(getCmd) 9 | } 10 | 11 | var getCmd = &cobra.Command{ 12 | Use: "get", 13 | Short: "Get resource details", 14 | } 15 | -------------------------------------------------------------------------------- /cli/cmd/get_cmd_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | ) 8 | 9 | func TestGetCmd(t *testing.T) { 10 | test.RunCommandTestCases(t, "users", []*test.CommandTestCase{ 11 | { 12 | []string{"get"}, 13 | nil, 14 | //configs["default"], 15 | "get_help", 16 | false, 17 | nil, 18 | }, 19 | { 20 | []string{"get", "--help"}, 21 | nil, 22 | //configs["default"], 23 | "get_help", 24 | false, 25 | nil, 26 | }, 27 | }) 28 | } 29 | -------------------------------------------------------------------------------- /cli/cmd/get_current_user_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | out "github.com/plouc/go-gitlab-client/cli/output" 8 | "github.com/spf13/cobra" 9 | ) 10 | 11 | func init() { 12 | getCmd.AddCommand(getCurrentCmd) 13 | } 14 | 15 | var getCurrentCmd = &cobra.Command{ 16 | Use: "current-user", 17 | Aliases: []string{"cu"}, 18 | Short: "Get current user", 19 | Run: func(cmd *cobra.Command, args []string) { 20 | color.Yellow("Fetching current user…") 21 | 22 | loader.Start() 23 | user, meta, err := client.CurrentUser() 24 | loader.Stop() 25 | if err != nil { 26 | fmt.Println(err.Error()) 27 | return 28 | } 29 | 30 | out.User(output, outputFormat, user) 31 | 32 | printMeta(meta, false) 33 | }, 34 | } 35 | -------------------------------------------------------------------------------- /cli/cmd/get_group_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/fatih/color" 5 | out "github.com/plouc/go-gitlab-client/cli/output" 6 | "github.com/spf13/cobra" 7 | ) 8 | 9 | var groupWithCustomAttributes bool 10 | 11 | func init() { 12 | getCmd.AddCommand(getGroupCmd) 13 | 14 | getGroupCmd.Flags().BoolVarP(&groupWithCustomAttributes, "with-custom-attributes", "x", false, "Include custom attributes (admins only)") 15 | } 16 | 17 | var getGroupCmd = &cobra.Command{ 18 | Use: resourceCmd("group", "group"), 19 | Aliases: []string{"g"}, 20 | Short: "Get all details of a group", 21 | RunE: func(cmd *cobra.Command, args []string) error { 22 | ids, err := config.aliasIdsOrArgs(currentAlias, "group", args) 23 | if err != nil { 24 | return err 25 | } 26 | 27 | color.Yellow("Fetching group (id: %s)…", ids["group_id"]) 28 | 29 | loader.Start() 30 | group, meta, err := client.Group(ids["group_id"], groupWithCustomAttributes) 31 | loader.Stop() 32 | if err != nil { 33 | return err 34 | } 35 | 36 | out.Group(output, outputFormat, group) 37 | 38 | printMeta(meta, false) 39 | 40 | relatedCommands([]*relatedCommand{ 41 | newRelatedCommand(listGroupMergeRequestsCmd, map[string]string{ 42 | "group_id": ids["group_id"], 43 | }), 44 | newRelatedCommand(listGroupVariablesCmd, map[string]string{ 45 | "group_id": ids["group_id"], 46 | }), 47 | }) 48 | 49 | return nil 50 | }, 51 | } 52 | -------------------------------------------------------------------------------- /cli/cmd/get_group_var_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/fatih/color" 5 | out "github.com/plouc/go-gitlab-client/cli/output" 6 | "github.com/spf13/cobra" 7 | ) 8 | 9 | func init() { 10 | getCmd.AddCommand(getGroupVarCmd) 11 | } 12 | 13 | var getGroupVarCmd = &cobra.Command{ 14 | Use: resourceCmd("group-var", "group-var"), 15 | Aliases: []string{"gv"}, 16 | Short: "Get the details of a group's specific variable", 17 | RunE: func(cmd *cobra.Command, args []string) error { 18 | ids, err := config.aliasIdsOrArgs(currentAlias, "group-var", args) 19 | if err != nil { 20 | return err 21 | } 22 | 23 | color.Yellow("Fetching group variable (group id: %s, key: %s)…", ids["group_id"], ids["var_key"]) 24 | 25 | loader.Start() 26 | variable, meta, err := client.GroupVariable(ids["group_id"], ids["var_key"]) 27 | loader.Stop() 28 | if err != nil { 29 | return err 30 | } 31 | 32 | out.Variable(output, outputFormat, variable) 33 | 34 | printMeta(meta, false) 35 | 36 | return nil 37 | }, 38 | } 39 | -------------------------------------------------------------------------------- /cli/cmd/get_namespace_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/fatih/color" 5 | out "github.com/plouc/go-gitlab-client/cli/output" 6 | "github.com/spf13/cobra" 7 | ) 8 | 9 | func init() { 10 | getCmd.AddCommand(getNamespaceCmd) 11 | } 12 | 13 | var getNamespaceCmd = &cobra.Command{ 14 | Use: resourceCmd("namespace", "namespace"), 15 | Aliases: []string{"ns"}, 16 | Short: "Get a single namespace", 17 | RunE: func(cmd *cobra.Command, args []string) error { 18 | ids, err := config.aliasIdsOrArgs(currentAlias, "namespace", args) 19 | if err != nil { 20 | return err 21 | } 22 | 23 | color.Yellow("Fetching namespace (id: %s)…", ids["namespace_id"]) 24 | 25 | loader.Start() 26 | namespace, meta, err := client.Namespace(ids["namespace_id"]) 27 | loader.Stop() 28 | if err != nil { 29 | return err 30 | } 31 | 32 | out.Namespace(output, outputFormat, namespace) 33 | 34 | printMeta(meta, false) 35 | 36 | return nil 37 | }, 38 | } 39 | -------------------------------------------------------------------------------- /cli/cmd/get_project_badge_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/fatih/color" 7 | out "github.com/plouc/go-gitlab-client/cli/output" 8 | "github.com/spf13/cobra" 9 | ) 10 | 11 | func init() { 12 | getCmd.AddCommand(getProjectBadgeCmd) 13 | } 14 | 15 | var getProjectBadgeCmd = &cobra.Command{ 16 | Use: resourceCmd("project-badge", "project-badge"), 17 | Aliases: []string{"pbdg"}, 18 | Short: "Get project badge info", 19 | RunE: func(cmd *cobra.Command, args []string) error { 20 | ids, err := config.aliasIdsOrArgs(currentAlias, "project-badge", args) 21 | if err != nil { 22 | return err 23 | } 24 | 25 | badgeId, err := strconv.Atoi(ids["badge_id"]) 26 | if err != nil { 27 | return err 28 | } 29 | 30 | color.Yellow("Fetching project's badge (project id: %s, badge id: %s)…", ids["project_id"], badgeId) 31 | 32 | loader.Start() 33 | badge, meta, err := client.ProjectBadge(ids["project_id"], badgeId) 34 | loader.Stop() 35 | if err != nil { 36 | return err 37 | } 38 | 39 | out.Badge(output, outputFormat, badge) 40 | 41 | printMeta(meta, false) 42 | 43 | return nil 44 | }, 45 | } 46 | -------------------------------------------------------------------------------- /cli/cmd/get_project_branch_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/fatih/color" 5 | out "github.com/plouc/go-gitlab-client/cli/output" 6 | "github.com/spf13/cobra" 7 | ) 8 | 9 | func init() { 10 | getCmd.AddCommand(getProjectBranchCmd) 11 | } 12 | 13 | var getProjectBranchCmd = &cobra.Command{ 14 | Use: resourceCmd("project-branch", "project-branch"), 15 | Aliases: []string{"pb"}, 16 | Short: "Get project branch info", 17 | RunE: func(cmd *cobra.Command, args []string) error { 18 | ids, err := config.aliasIdsOrArgs(currentAlias, "project-branch", args) 19 | if err != nil { 20 | return err 21 | } 22 | 23 | color.Yellow("Fetching project's branch (project id: %s, branch name: %s)…", ids["project_id"], ids["branch_name"]) 24 | 25 | loader.Start() 26 | branch, meta, err := client.ProjectBranch(ids["project_id"], ids["branch_name"]) 27 | loader.Stop() 28 | if err != nil { 29 | return err 30 | } 31 | 32 | out.Branch(output, outputFormat, branch) 33 | 34 | printMeta(meta, false) 35 | 36 | return nil 37 | }, 38 | } 39 | -------------------------------------------------------------------------------- /cli/cmd/get_project_hook_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/fatih/color" 5 | out "github.com/plouc/go-gitlab-client/cli/output" 6 | "github.com/spf13/cobra" 7 | ) 8 | 9 | func init() { 10 | getCmd.AddCommand(getProjectHookCmd) 11 | } 12 | 13 | var getProjectHookCmd = &cobra.Command{ 14 | Use: resourceCmd("project-hook", "project-hook"), 15 | Aliases: []string{"ph"}, 16 | Short: "Get project hook info", 17 | RunE: func(cmd *cobra.Command, args []string) error { 18 | ids, err := config.aliasIdsOrArgs(currentAlias, "project-hook", args) 19 | if err != nil { 20 | return err 21 | } 22 | 23 | color.Yellow("Fetching project's hook (project id: %s, hook id: %s)…", ids["project_id"], ids["hook_id"]) 24 | 25 | loader.Start() 26 | hook, meta, err := client.ProjectHook(ids["project_id"], ids["hook_id"]) 27 | loader.Stop() 28 | if err != nil { 29 | return err 30 | } 31 | 32 | out.Hook(output, outputFormat, hook) 33 | 34 | printMeta(meta, false) 35 | 36 | return nil 37 | }, 38 | } 39 | -------------------------------------------------------------------------------- /cli/cmd/get_project_job_cancel_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/fatih/color" 7 | out "github.com/plouc/go-gitlab-client/cli/output" 8 | "github.com/spf13/cobra" 9 | ) 10 | 11 | func init() { 12 | getProjectJobCmd.AddCommand(getProjectJobCancelCmd) 13 | } 14 | 15 | var getProjectJobCancelCmd = &cobra.Command{ 16 | Use: resourceCmd("cancel", "project-job"), 17 | Short: "Cancel project job", 18 | RunE: func(cmd *cobra.Command, args []string) error { 19 | ids, err := config.aliasIdsOrArgs(currentAlias, "project-job", args) 20 | if err != nil { 21 | return err 22 | } 23 | 24 | jobId, err := strconv.Atoi(ids["job_id"]) 25 | if err != nil { 26 | return err 27 | } 28 | 29 | color.Yellow("Cancelling project's job (project id: %s, job id: %d)…", ids["project_id"], jobId) 30 | 31 | loader.Start() 32 | job, meta, err := client.CancelProjectJob(ids["project_id"], jobId) 33 | loader.Stop() 34 | if err != nil { 35 | return err 36 | } 37 | 38 | out.Job(output, outputFormat, job) 39 | 40 | printMeta(meta, false) 41 | 42 | return nil 43 | }, 44 | } 45 | -------------------------------------------------------------------------------- /cli/cmd/get_project_job_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | 7 | "github.com/fatih/color" 8 | out "github.com/plouc/go-gitlab-client/cli/output" 9 | "github.com/spf13/cobra" 10 | ) 11 | 12 | func init() { 13 | getCmd.AddCommand(getProjectJobCmd) 14 | } 15 | 16 | var getProjectJobCmd = &cobra.Command{ 17 | Use: resourceCmd("project-job", "project-job"), 18 | Aliases: []string{"pj"}, 19 | Short: "Get project job info", 20 | RunE: func(cmd *cobra.Command, args []string) error { 21 | ids, err := config.aliasIdsOrArgs(currentAlias, "project-job", args) 22 | if err != nil { 23 | return err 24 | } 25 | 26 | jobId, err := strconv.Atoi(ids["job_id"]) 27 | if err != nil { 28 | return err 29 | } 30 | 31 | color.Yellow("Fetching project's job (project id: %s, job id: %d)…", ids["project_id"], jobId) 32 | 33 | loader.Start() 34 | job, meta, err := client.ProjectJob(ids["project_id"], jobId) 35 | loader.Stop() 36 | if err != nil { 37 | return err 38 | } 39 | 40 | out.Job(output, outputFormat, job) 41 | 42 | printMeta(meta, false) 43 | 44 | fmt.Println("") 45 | color.Yellow("Related") 46 | fmt.Printf( 47 | " To get job trace, run: %s\n", 48 | color.YellowString("glc get project-job-trace %s %d", ids["project_id"], jobId), 49 | ) 50 | fmt.Println("") 51 | 52 | return nil 53 | }, 54 | } 55 | -------------------------------------------------------------------------------- /cli/cmd/get_project_job_retry_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | 7 | "github.com/fatih/color" 8 | out "github.com/plouc/go-gitlab-client/cli/output" 9 | "github.com/spf13/cobra" 10 | ) 11 | 12 | func init() { 13 | getProjectJobCmd.AddCommand(getProjectJobRetryCmd) 14 | } 15 | 16 | var getProjectJobRetryCmd = &cobra.Command{ 17 | Use: resourceCmd("retry", "project-job"), 18 | Short: "Retry project job", 19 | RunE: func(cmd *cobra.Command, args []string) error { 20 | ids, err := config.aliasIdsOrArgs(currentAlias, "project-job", args) 21 | if err != nil { 22 | return err 23 | } 24 | 25 | jobId, err := strconv.Atoi(ids["job_id"]) 26 | if err != nil { 27 | return err 28 | } 29 | 30 | color.Yellow("Retrying project's job (project id: %s, job id: %d)…", ids["project_id"], jobId) 31 | 32 | loader.Start() 33 | job, meta, err := client.RetryProjectJob(ids["project_id"], jobId) 34 | loader.Stop() 35 | if err != nil { 36 | return err 37 | } 38 | 39 | out.Job(output, outputFormat, job) 40 | 41 | printMeta(meta, false) 42 | 43 | fmt.Println("") 44 | color.Yellow("Related") 45 | fmt.Printf( 46 | " To get job trace, run: %s\n", 47 | color.YellowString("glc get project-job-trace %s %d", ids["project_id"], job.Id), 48 | ) 49 | fmt.Println("") 50 | 51 | return nil 52 | }, 53 | } 54 | -------------------------------------------------------------------------------- /cli/cmd/get_project_job_trace_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | 7 | "github.com/fatih/color" 8 | "github.com/spf13/cobra" 9 | ) 10 | 11 | func init() { 12 | getCmd.AddCommand(getProjectJobTraceCmd) 13 | } 14 | 15 | var getProjectJobTraceCmd = &cobra.Command{ 16 | Use: resourceCmd("project-job-trace", "project-job"), 17 | Aliases: []string{"pjt"}, 18 | Short: "Get project job trace", 19 | RunE: func(cmd *cobra.Command, args []string) error { 20 | ids, err := config.aliasIdsOrArgs(currentAlias, "project-job", args) 21 | if err != nil { 22 | return err 23 | } 24 | 25 | jobId, err := strconv.Atoi(ids["job_id"]) 26 | if err != nil { 27 | return err 28 | } 29 | 30 | color.Yellow("Fetching project's job trace (project id: %s, job id: %d)…", ids["project_id"], jobId) 31 | 32 | loader.Start() 33 | trace, meta, err := client.ProjectJobTrace(ids["project_id"], jobId) 34 | loader.Stop() 35 | if err != nil { 36 | return err 37 | } 38 | 39 | fmt.Fprintln(output, trace) 40 | 41 | printMeta(meta, false) 42 | 43 | return nil 44 | }, 45 | } 46 | -------------------------------------------------------------------------------- /cli/cmd/get_project_merge_request_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/fatih/color" 7 | out "github.com/plouc/go-gitlab-client/cli/output" 8 | "github.com/spf13/cobra" 9 | ) 10 | 11 | func init() { 12 | getCmd.AddCommand(getProjectMergeRequestCmd) 13 | } 14 | 15 | var getProjectMergeRequestCmd = &cobra.Command{ 16 | Use: resourceCmd("project-merge-request", "project-merge-request"), 17 | Aliases: []string{"project-mr", "pmr"}, 18 | Short: "Get project merge request info", 19 | RunE: func(cmd *cobra.Command, args []string) error { 20 | ids, err := config.aliasIdsOrArgs(currentAlias, "project-merge-request", args) 21 | if err != nil { 22 | return err 23 | } 24 | 25 | mergeRequestIid, err := strconv.Atoi(ids["merge_request_iid"]) 26 | if err != nil { 27 | return err 28 | } 29 | 30 | color.Yellow("Fetching project merge request (project id: %s, merge request iid: %d)…", ids["project_id"], mergeRequestIid) 31 | 32 | loader.Start() 33 | mergeRequest, meta, err := client.ProjectMergeRequest(ids["project_id"], mergeRequestIid) 34 | loader.Stop() 35 | if err != nil { 36 | return err 37 | } 38 | 39 | out.MergeRequest(output, outputFormat, mergeRequest) 40 | 41 | printMeta(meta, false) 42 | 43 | return nil 44 | }, 45 | } 46 | -------------------------------------------------------------------------------- /cli/cmd/get_project_merge_request_cmd_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | ) 8 | 9 | func TestGetProjectMergeRequestCmd(t *testing.T) { 10 | test.RunCommandTestCases(t, "merge_requests", []*test.CommandTestCase{ 11 | /* 12 | { 13 | []string{"get", "project-merge-request", "-h"}, 14 | nil, 15 | //configs["default"], 16 | "get_project_merge_request_help", 17 | false, 18 | nil, 19 | }, 20 | { 21 | []string{"get", "project-mr"}, 22 | nil, 23 | //configs["default"], 24 | "get_project_merge_request_no_arg", 25 | true, 26 | nil, 27 | }, 28 | { 29 | []string{"get", "project-mr", "1"}, 30 | nil, 31 | //configs["default"], 32 | "get_project_merge_request_no_merge_request_iid", 33 | true, 34 | nil, 35 | }, 36 | */ 37 | { 38 | []string{"get", "project-mr", "1", "1"}, 39 | nil, 40 | //configs["default"], 41 | "get_project_merge_request", 42 | false, 43 | nil, 44 | }, 45 | /* 46 | { 47 | []string{"get", "project-mr", "1", "1", "-v"}, 48 | nil, 49 | //configs["default"], 50 | "get_project_merge_request_verbose", 51 | false, 52 | nil, 53 | }, 54 | */ 55 | { 56 | []string{"get", "project-mr", "1", "1", "-f", "json"}, 57 | nil, 58 | //configs["default"], 59 | "get_project_merge_request_json", 60 | false, 61 | nil, 62 | }, 63 | { 64 | []string{"get", "project-mr", "1", "1", "-f", "yaml"}, 65 | nil, 66 | //configs["default"], 67 | "get_project_merge_request_yaml", 68 | false, 69 | nil, 70 | }, 71 | }) 72 | } 73 | -------------------------------------------------------------------------------- /cli/cmd/get_project_merge_request_note_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/fatih/color" 7 | out "github.com/plouc/go-gitlab-client/cli/output" 8 | "github.com/spf13/cobra" 9 | ) 10 | 11 | func init() { 12 | getCmd.AddCommand(getProjectMergeRequestNoteCmd) 13 | } 14 | 15 | var getProjectMergeRequestNoteCmd = &cobra.Command{ 16 | Use: resourceCmd("project-merge-request-note", "project-merge-request-note"), 17 | Aliases: []string{"project-mr-note", "merge-request-note", "mr-note"}, 18 | Short: "Get project merge request note", 19 | RunE: func(cmd *cobra.Command, args []string) error { 20 | ids, err := config.aliasIdsOrArgs(currentAlias, "project-merge-request-note", args) 21 | if err != nil { 22 | return err 23 | } 24 | 25 | mergeRequestIid, err := strconv.Atoi(ids["merge_request_iid"]) 26 | if err != nil { 27 | return err 28 | } 29 | 30 | noteId, err := strconv.Atoi(ids["note_id"]) 31 | if err != nil { 32 | return err 33 | } 34 | 35 | color.Yellow( 36 | "Fetching project's merge request note (project id: %s, merge request iid: %d, note id: %d)…", 37 | ids["project_id"], mergeRequestIid, noteId, 38 | ) 39 | 40 | loader.Start() 41 | note, meta, err := client.ProjectMergeRequestNote(ids["project_id"], mergeRequestIid, noteId) 42 | loader.Stop() 43 | if err != nil { 44 | return err 45 | } 46 | 47 | out.Note(output, outputFormat, note) 48 | 49 | printMeta(meta, false) 50 | 51 | return nil 52 | }, 53 | } 54 | -------------------------------------------------------------------------------- /cli/cmd/get_project_pipeline_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/fatih/color" 5 | out "github.com/plouc/go-gitlab-client/cli/output" 6 | "github.com/spf13/cobra" 7 | ) 8 | 9 | func init() { 10 | getCmd.AddCommand(getProjectPipelineCmd) 11 | } 12 | 13 | var getProjectPipelineCmd = &cobra.Command{ 14 | Use: resourceCmd("project-pipeline", "project-pipeline"), 15 | Aliases: []string{"pp"}, 16 | Short: "Get project pipeline details", 17 | RunE: func(cmd *cobra.Command, args []string) error { 18 | ids, err := config.aliasIdsOrArgs(currentAlias, "project-pipeline", args) 19 | if err != nil { 20 | return err 21 | } 22 | 23 | color.Yellow("Fetching project's pipeline (project id: %s, pipeline id: %s)…", ids["project_id"], ids["pipeline_id"]) 24 | 25 | loader.Start() 26 | pipeline, meta, err := client.ProjectPipeline(ids["project_id"], ids["pipeline_id"]) 27 | loader.Stop() 28 | if err != nil { 29 | return err 30 | } 31 | 32 | out.Pipeline(output, outputFormat, pipeline) 33 | 34 | printMeta(meta, false) 35 | 36 | return nil 37 | }, 38 | } 39 | -------------------------------------------------------------------------------- /cli/cmd/get_project_var_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/fatih/color" 5 | out "github.com/plouc/go-gitlab-client/cli/output" 6 | "github.com/spf13/cobra" 7 | ) 8 | 9 | func init() { 10 | getCmd.AddCommand(getProjectVarCmd) 11 | } 12 | 13 | var getProjectVarCmd = &cobra.Command{ 14 | Use: resourceCmd("project-var", "project-var"), 15 | Aliases: []string{"pv"}, 16 | Short: "Get the details of a project's specific variable", 17 | RunE: func(cmd *cobra.Command, args []string) error { 18 | ids, err := config.aliasIdsOrArgs(currentAlias, "project-var", args) 19 | if err != nil { 20 | return err 21 | } 22 | 23 | color.Yellow("Fetching project variable (id: %s, key: %s)…", ids["project_id"], ids["var_key"]) 24 | 25 | loader.Start() 26 | variable, meta, err := client.ProjectVariable(ids["project_id"], ids["var_key"]) 27 | loader.Stop() 28 | if err != nil { 29 | return err 30 | } 31 | 32 | out.Variable(output, outputFormat, variable) 33 | 34 | printMeta(meta, false) 35 | 36 | return nil 37 | }, 38 | } 39 | -------------------------------------------------------------------------------- /cli/cmd/get_runner_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/fatih/color" 7 | out "github.com/plouc/go-gitlab-client/cli/output" 8 | "github.com/spf13/cobra" 9 | ) 10 | 11 | func init() { 12 | getCmd.AddCommand(getRunnerCmd) 13 | } 14 | 15 | var getRunnerCmd = &cobra.Command{ 16 | Use: resourceCmd("runner", "runner"), 17 | Aliases: []string{"r"}, 18 | Short: "Get details of a runner", 19 | RunE: func(cmd *cobra.Command, args []string) error { 20 | ids, err := config.aliasIdsOrArgs(currentAlias, "runner", args) 21 | if err != nil { 22 | return err 23 | } 24 | 25 | runnerId, err := strconv.Atoi(ids["runner_id"]) 26 | if err != nil { 27 | return err 28 | } 29 | 30 | color.Yellow("Fetching runner (id: %d)…", runnerId) 31 | 32 | loader.Start() 33 | runner, meta, err := client.Runner(runnerId) 34 | loader.Stop() 35 | if err != nil { 36 | return err 37 | } 38 | 39 | out.Runner(output, outputFormat, runner) 40 | 41 | printMeta(meta, false) 42 | 43 | return nil 44 | }, 45 | } 46 | -------------------------------------------------------------------------------- /cli/cmd/get_user_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/fatih/color" 5 | out "github.com/plouc/go-gitlab-client/cli/output" 6 | "github.com/spf13/cobra" 7 | ) 8 | 9 | func init() { 10 | getCmd.AddCommand(getUserCmd) 11 | } 12 | 13 | var getUserCmd = &cobra.Command{ 14 | Use: resourceCmd("user", "user"), 15 | Aliases: []string{"u"}, 16 | Short: "Get a single user", 17 | RunE: func(cmd *cobra.Command, args []string) error { 18 | ids, err := config.aliasIdsOrArgs(currentAlias, "user", args) 19 | if err != nil { 20 | return err 21 | } 22 | 23 | color.Yellow("Fetching user (id: %s)…", ids["user_id"]) 24 | 25 | loader.Start() 26 | user, meta, err := client.User(ids["user_id"]) 27 | loader.Stop() 28 | if err != nil { 29 | return err 30 | } 31 | 32 | out.User(output, outputFormat, user) 33 | 34 | printMeta(meta, false) 35 | 36 | relatedCommands([]*relatedCommand{ 37 | newRelatedCommand(listUserSshKeysCmd, map[string]string{ 38 | "user_id": ids["user_id"], 39 | }), 40 | }) 41 | 42 | return nil 43 | }, 44 | } 45 | -------------------------------------------------------------------------------- /cli/cmd/get_user_cmd_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | ) 8 | 9 | func TestGetUserCmd(t *testing.T) { 10 | test.RunCommandTestCases(t, "users", []*test.CommandTestCase{ 11 | /* 12 | { 13 | []string{"get", "user"}, 14 | nil, 15 | //configs["default"], 16 | "get_user_no_arg", 17 | true, 18 | nil, 19 | }, 20 | { 21 | []string{"get", "user", "-h"}, 22 | nil, 23 | //configs["default"], 24 | "get_user_help", 25 | false, 26 | nil, 27 | }, 28 | */ 29 | { 30 | []string{"get", "user", "1"}, 31 | nil, 32 | //configs["default"], 33 | "get_user", 34 | false, 35 | nil, 36 | }, 37 | /* 38 | { 39 | []string{"get", "user", "1", "-v"}, 40 | nil, 41 | //configs["default"], 42 | "get_user_verbose", 43 | false, 44 | nil, 45 | }, 46 | */ 47 | { 48 | []string{"get", "user", "1", "-f", "json"}, 49 | nil, 50 | //configs["default"], 51 | "get_user_json", 52 | false, 53 | nil, 54 | }, 55 | { 56 | []string{"get", "user", "1", "-f", "yaml"}, 57 | nil, 58 | //configs["default"], 59 | "get_user_yaml", 60 | false, 61 | nil, 62 | }, 63 | }) 64 | } 65 | -------------------------------------------------------------------------------- /cli/cmd/list_aliases_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/fatih/color" 5 | "github.com/spf13/cobra" 6 | ) 7 | 8 | func init() { 9 | listCmd.AddCommand(listAliasesCmd) 10 | } 11 | 12 | var listAliasesCmd = &cobra.Command{ 13 | Use: "aliases", 14 | Aliases: []string{"a"}, 15 | Short: "List resource aliases", 16 | Run: func(cmd *cobra.Command, args []string) { 17 | color.Yellow("Listing registered aliases…") 18 | 19 | if len(config.Aliases) == 0 { 20 | color.Red(" No alias found, create one with `glc add alias`") 21 | } else { 22 | aliasesOutput(config.Aliases) 23 | } 24 | }, 25 | } 26 | -------------------------------------------------------------------------------- /cli/cmd/list_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/spf13/cobra" 5 | ) 6 | 7 | func init() { 8 | RootCmd.AddCommand(listCmd) 9 | 10 | listCmd.PersistentFlags().IntVarP(&page, "page", "p", 1, "Page") 11 | listCmd.PersistentFlags().IntVarP(&perPage, "per-page", "l", 10, "Items per page") 12 | } 13 | 14 | var listCmd = &cobra.Command{ 15 | Use: "list", 16 | Aliases: []string{"ls"}, 17 | Short: "List resource", 18 | } 19 | -------------------------------------------------------------------------------- /cli/cmd/list_cmd_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | ) 8 | 9 | func TestListCmd(t *testing.T) { 10 | test.RunCommandTestCases(t, "users", []*test.CommandTestCase{ 11 | { 12 | []string{"list"}, 13 | nil, 14 | //configs["default"], 15 | "list_help", 16 | false, 17 | nil, 18 | }, 19 | { 20 | []string{"ls"}, 21 | nil, 22 | //configs["default"], 23 | "list_help", 24 | false, 25 | nil, 26 | }, 27 | { 28 | []string{"list", "--help"}, 29 | nil, 30 | //configs["default"], 31 | "list_help", 32 | false, 33 | nil, 34 | }, 35 | }) 36 | } 37 | -------------------------------------------------------------------------------- /cli/cmd/list_group_merge_requests_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | 7 | "github.com/fatih/color" 8 | out "github.com/plouc/go-gitlab-client/cli/output" 9 | "github.com/plouc/go-gitlab-client/gitlab" 10 | "github.com/spf13/cobra" 11 | ) 12 | 13 | func init() { 14 | listCmd.AddCommand(listGroupMergeRequestsCmd) 15 | } 16 | 17 | func fetchGroupMergeRequests(groupId int) { 18 | color.Yellow("Fetching group %d merge requests…", groupId) 19 | 20 | o := &gitlab.MergeRequestsOptions{} 21 | o.Page = page 22 | o.PerPage = perPage 23 | 24 | loader.Start() 25 | collection, meta, err := client.GroupMergeRequests(groupId, o) 26 | loader.Stop() 27 | if err != nil { 28 | fmt.Println(err.Error()) 29 | return 30 | } 31 | 32 | if len(collection.Items) == 0 { 33 | color.Red("No merge request found for group %d", groupId) 34 | } else { 35 | out.MergeRequests(output, outputFormat, collection) 36 | } 37 | 38 | printMeta(meta, true) 39 | 40 | handlePaginatedResult(meta, func() { 41 | fetchGroupMergeRequests(groupId) 42 | }) 43 | } 44 | 45 | var listGroupMergeRequestsCmd = &cobra.Command{ 46 | Use: resourceCmd("group-merge-requests", "group"), 47 | Aliases: []string{"gmr"}, 48 | Short: "List group merge requests", 49 | RunE: func(cmd *cobra.Command, args []string) error { 50 | ids, err := config.aliasIdsOrArgs(currentAlias, "group", args) 51 | if err != nil { 52 | return err 53 | } 54 | 55 | groupId, err := strconv.Atoi(ids["group_id"]) 56 | if err != nil { 57 | return err 58 | } 59 | 60 | fetchGroupMergeRequests(groupId) 61 | 62 | return nil 63 | }, 64 | } 65 | -------------------------------------------------------------------------------- /cli/cmd/list_group_merge_requests_cmd_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | ) 8 | 9 | func TestListGroupMergeRequestsCmd(t *testing.T) { 10 | test.RunCommandTestCases(t, "merge_requests", []*test.CommandTestCase{ 11 | { 12 | []string{"list", "group-merge-requests", "-h"}, 13 | nil, 14 | //configs["default"], 15 | "list_group_merge_requests_help", 16 | false, 17 | nil, 18 | }, 19 | { 20 | []string{"list", "group-merge-requests", "1"}, 21 | nil, 22 | //configs["default"], 23 | "list_group_merge_requests", 24 | false, 25 | nil, 26 | }, 27 | /* 28 | { 29 | []string{"list", "group-merge-requests", "1", "-v"}, 30 | nil, 31 | //configs["default"], 32 | "list_group_merge_requests_verbose", 33 | false, 34 | nil, 35 | }, 36 | */ 37 | { 38 | []string{"list", "group-merge-requests", "1", "-f", "json"}, 39 | nil, 40 | //configs["default"], 41 | "list_group_merge_requests_json", 42 | false, 43 | nil, 44 | }, 45 | { 46 | []string{"list", "group-merge-requests", "1", "-f", "yaml"}, 47 | nil, 48 | //configs["default"], 49 | "list_group_merge_requests_yaml", 50 | false, 51 | nil, 52 | }, 53 | }) 54 | } 55 | -------------------------------------------------------------------------------- /cli/cmd/list_group_variables_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/fatih/color" 5 | out "github.com/plouc/go-gitlab-client/cli/output" 6 | "github.com/plouc/go-gitlab-client/gitlab" 7 | "github.com/spf13/cobra" 8 | ) 9 | 10 | func init() { 11 | listCmd.AddCommand(listGroupVariablesCmd) 12 | } 13 | 14 | var listGroupVariablesCmd = &cobra.Command{ 15 | Use: resourceCmd("group-variables", "group"), 16 | Aliases: []string{"group-vars", "gv"}, 17 | Short: "Get list of a group's variables", 18 | RunE: func(cmd *cobra.Command, args []string) error { 19 | ids, err := config.aliasIdsOrArgs(currentAlias, "group", args) 20 | if err != nil { 21 | return err 22 | } 23 | 24 | color.Yellow("Fetching group variables (id: %s)…", ids["group_id"]) 25 | 26 | o := &gitlab.PaginationOptions{ 27 | Page: page, 28 | PerPage: perPage, 29 | } 30 | 31 | loader.Start() 32 | collection, meta, err := client.GroupVariables(ids["group_id"], o) 33 | loader.Stop() 34 | if err != nil { 35 | return err 36 | } 37 | 38 | if len(collection.Items) == 0 { 39 | color.Red(" No variable found for group %s", ids["group_id"]) 40 | } else { 41 | out.Variables(output, outputFormat, collection) 42 | } 43 | 44 | printMeta(meta, true) 45 | 46 | return nil 47 | }, 48 | } 49 | -------------------------------------------------------------------------------- /cli/cmd/list_groups_cmd_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | ) 8 | 9 | func TestListGroupsCmd(t *testing.T) { 10 | test.RunCommandTestCases(t, "groups", []*test.CommandTestCase{ 11 | { 12 | []string{"list", "groups", "--help"}, 13 | nil, 14 | //configs["default"], 15 | "list_groups_help", 16 | false, 17 | nil, 18 | }, 19 | { 20 | []string{"list", "groups"}, 21 | nil, 22 | //configs["default"], 23 | "list_groups", 24 | false, 25 | nil, 26 | }, 27 | /* 28 | { 29 | []string{"list", "groups", "--verbose"}, 30 | nil, 31 | //configs["default"], 32 | "list_groups_verbose", 33 | false, 34 | nil, 35 | }, 36 | */ 37 | { 38 | []string{"list", "groups", "-f", "json"}, 39 | nil, 40 | //configs["default"], 41 | "list_groups_json", 42 | false, 43 | nil, 44 | }, 45 | { 46 | []string{"list", "groups", "-f", "yaml"}, 47 | nil, 48 | //configs["default"], 49 | "list_groups_yaml", 50 | false, 51 | nil, 52 | }, 53 | }) 54 | } 55 | -------------------------------------------------------------------------------- /cli/cmd/list_merge_requests_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | out "github.com/plouc/go-gitlab-client/cli/output" 8 | "github.com/plouc/go-gitlab-client/gitlab" 9 | "github.com/spf13/cobra" 10 | ) 11 | 12 | func init() { 13 | listCmd.AddCommand(listMergeRequestsCmd) 14 | } 15 | 16 | func fetchMergeRequests() { 17 | color.Yellow("Fetching merge requests…") 18 | 19 | o := &gitlab.MergeRequestsOptions{} 20 | o.Page = page 21 | o.PerPage = perPage 22 | 23 | loader.Start() 24 | collection, meta, err := client.MergeRequests(o) 25 | loader.Stop() 26 | if err != nil { 27 | fmt.Println(err.Error()) 28 | return 29 | } 30 | 31 | if len(collection.Items) == 0 { 32 | color.Red("No merge request found") 33 | } else { 34 | out.MergeRequests(output, outputFormat, collection) 35 | } 36 | 37 | printMeta(meta, true) 38 | 39 | handlePaginatedResult(meta, fetchMergeRequests) 40 | } 41 | 42 | var listMergeRequestsCmd = &cobra.Command{ 43 | Use: "merge-requests", 44 | Aliases: []string{"mr"}, 45 | Short: "List merge requests", 46 | Run: func(cmd *cobra.Command, args []string) { 47 | fetchMergeRequests() 48 | }, 49 | } 50 | -------------------------------------------------------------------------------- /cli/cmd/list_merge_requests_cmd_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | ) 8 | 9 | func TestListMergeRequestsCmd(t *testing.T) { 10 | test.RunCommandTestCases(t, "merge_requests", []*test.CommandTestCase{ 11 | { 12 | []string{"list", "merge-requests", "--help"}, 13 | nil, 14 | //configs["default"], 15 | "list_merge_requests_help", 16 | false, 17 | nil, 18 | }, 19 | { 20 | []string{"list", "merge-requests"}, 21 | nil, 22 | //configs["default"], 23 | "list_merge_requests", 24 | false, 25 | nil, 26 | }, 27 | /* 28 | { 29 | []string{"list", "merge-requests", "--verbose"}, 30 | nil, 31 | //configs["default"], 32 | "list_merge_requests_verbose", 33 | false, 34 | nil, 35 | }, 36 | */ 37 | { 38 | []string{"list", "merge-requests", "-f", "json"}, 39 | nil, 40 | //configs["default"], 41 | "list_merge_requests_json", 42 | false, 43 | nil, 44 | }, 45 | { 46 | []string{"list", "merge-requests", "-f", "yaml"}, 47 | nil, 48 | //configs["default"], 49 | "list_merge_requests_yaml", 50 | false, 51 | nil, 52 | }, 53 | }) 54 | } 55 | -------------------------------------------------------------------------------- /cli/cmd/list_namespaces_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | out "github.com/plouc/go-gitlab-client/cli/output" 8 | "github.com/plouc/go-gitlab-client/gitlab" 9 | "github.com/spf13/cobra" 10 | ) 11 | 12 | var namespacesSearch string 13 | 14 | func init() { 15 | listCmd.AddCommand(listNamespacesCmd) 16 | 17 | listNamespacesCmd.Flags().StringVarP(&namespacesSearch, "search", "s", "", "Returns a list of namespaces the user is authorized to see based on the search criteria") 18 | } 19 | 20 | func fetchNamespaces() { 21 | color.Yellow("Fetching namespaces…") 22 | 23 | o := &gitlab.NamespacesOptions{} 24 | o.Page = page 25 | o.PerPage = perPage 26 | if namespacesSearch != "" { 27 | o.Search = namespacesSearch 28 | } 29 | 30 | loader.Start() 31 | collection, meta, err := client.Namespaces(o) 32 | loader.Stop() 33 | if err != nil { 34 | fmt.Println(err.Error()) 35 | return 36 | } 37 | 38 | if len(collection.Items) == 0 { 39 | color.Red("No namespace found") 40 | } else { 41 | out.Namespaces(output, outputFormat, collection) 42 | } 43 | 44 | printMeta(meta, true) 45 | 46 | handlePaginatedResult(meta, fetchNamespaces) 47 | } 48 | 49 | var listNamespacesCmd = &cobra.Command{ 50 | Use: "namespaces", 51 | Aliases: []string{"ns"}, 52 | Short: "List namespaces", 53 | Run: func(cmd *cobra.Command, args []string) { 54 | fetchNamespaces() 55 | }, 56 | } 57 | -------------------------------------------------------------------------------- /cli/cmd/list_namespaces_cmd_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | ) 8 | 9 | func TestListNamespacesCmd(t *testing.T) { 10 | test.RunCommandTestCases(t, "namespaces", []*test.CommandTestCase{ 11 | { 12 | []string{"list", "namespaces", "--help"}, 13 | nil, //configs["default"], 14 | "list_namespaces_help", 15 | false, 16 | nil, 17 | }, 18 | { 19 | []string{"list", "namespaces"}, 20 | nil, //configs["default"], 21 | "list_namespaces", 22 | false, 23 | nil, 24 | }, 25 | { 26 | []string{"list", "namespaces", "--search", "twitter"}, 27 | nil, //configs["default"], 28 | "list_namespaces_search", 29 | false, 30 | nil, 31 | }, 32 | { 33 | []string{"list", "namespaces", "-s", "twitter"}, 34 | nil, //configs["default"], 35 | "list_namespaces_search", 36 | false, 37 | nil, 38 | }, 39 | /* 40 | { 41 | []string{"list", "namespaces", "--verbose"}, 42 | nil, //configs["default"], 43 | "list_namespaces_verbose", 44 | false, 45 | nil, 46 | }, 47 | */ 48 | { 49 | []string{"list", "namespaces", "-f", "json"}, 50 | nil, //configs["default"], 51 | "list_namespaces_json", 52 | false, 53 | nil, 54 | }, 55 | { 56 | []string{"list", "namespaces", "-f", "yaml"}, 57 | nil, //configs["default"], 58 | "list_namespaces_yaml", 59 | false, 60 | nil, 61 | }, 62 | }) 63 | } 64 | -------------------------------------------------------------------------------- /cli/cmd/list_project_badges_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | out "github.com/plouc/go-gitlab-client/cli/output" 8 | "github.com/plouc/go-gitlab-client/gitlab" 9 | "github.com/spf13/cobra" 10 | ) 11 | 12 | func init() { 13 | listCmd.AddCommand(listProjectBadgesCmd) 14 | } 15 | 16 | func fetchProjectBadges(projectId string) { 17 | color.Yellow("Fetching project badges (id: %s)…", projectId) 18 | 19 | o := &gitlab.PaginationOptions{} 20 | o.Page = page 21 | o.PerPage = perPage 22 | 23 | loader.Start() 24 | collection, meta, err := client.ProjectBadges(projectId, o) 25 | loader.Stop() 26 | if err != nil { 27 | fmt.Println(err.Error()) 28 | return 29 | } 30 | 31 | if len(collection.Items) == 0 { 32 | color.Red("No badge found for project %s", projectId) 33 | } else { 34 | out.Badges(output, outputFormat, collection) 35 | } 36 | 37 | printMeta(meta, true) 38 | 39 | handlePaginatedResult(meta, func() { 40 | fetchProjectBadges(projectId) 41 | }) 42 | } 43 | 44 | var listProjectBadgesCmd = &cobra.Command{ 45 | Use: resourceCmd("project-badges", "project"), 46 | Aliases: []string{"pbdg"}, 47 | Short: "List project badges", 48 | RunE: func(cmd *cobra.Command, args []string) error { 49 | ids, err := config.aliasIdsOrArgs(currentAlias, "project", args) 50 | if err != nil { 51 | return err 52 | } 53 | 54 | fetchProjectBadges(ids["project_id"]) 55 | 56 | return nil 57 | }, 58 | } 59 | -------------------------------------------------------------------------------- /cli/cmd/list_project_commits.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | out "github.com/plouc/go-gitlab-client/cli/output" 8 | "github.com/plouc/go-gitlab-client/gitlab" 9 | "github.com/spf13/cobra" 10 | ) 11 | 12 | func init() { 13 | listCmd.AddCommand(listProjectCommitsCmd) 14 | } 15 | 16 | func fetchProjectCommits(projectId string) { 17 | color.Yellow("Fetching project commits (project id: %s)…", projectId) 18 | 19 | o := &gitlab.CommitsOptions{} 20 | o.Page = page 21 | o.PerPage = perPage 22 | 23 | loader.Start() 24 | collection, meta, err := client.ProjectCommits(projectId, o) 25 | loader.Stop() 26 | if err != nil { 27 | fmt.Println(err.Error()) 28 | return 29 | } 30 | 31 | if len(collection.Items) == 0 { 32 | color.Red("No commit found for project %s", projectId) 33 | } else { 34 | out.Commits(output, outputFormat, collection) 35 | } 36 | 37 | printMeta(meta, true) 38 | 39 | handlePaginatedResult(meta, func() { 40 | fetchProjectCommits(projectId) 41 | }) 42 | } 43 | 44 | var listProjectCommitsCmd = &cobra.Command{ 45 | Use: resourceCmd("project-commits", "project"), 46 | Aliases: []string{"pc"}, 47 | Short: "List project repository commits", 48 | RunE: func(cmd *cobra.Command, args []string) error { 49 | ids, err := config.aliasIdsOrArgs(currentAlias, "project", args) 50 | if err != nil { 51 | return err 52 | } 53 | 54 | fetchProjectCommits(ids["project_id"]) 55 | 56 | return nil 57 | }, 58 | } 59 | -------------------------------------------------------------------------------- /cli/cmd/list_project_environments_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | out "github.com/plouc/go-gitlab-client/cli/output" 8 | "github.com/plouc/go-gitlab-client/gitlab" 9 | "github.com/spf13/cobra" 10 | ) 11 | 12 | func init() { 13 | listCmd.AddCommand(listProjectEnvironmentsCmd) 14 | } 15 | 16 | func fetchProjectEnvironments(projectId string) { 17 | color.Yellow("Fetching project environments (project id: %s)…", projectId) 18 | 19 | o := &gitlab.PaginationOptions{} 20 | o.Page = page 21 | o.PerPage = perPage 22 | 23 | loader.Start() 24 | collection, meta, err := client.ProjectEnvironments(projectId, o) 25 | loader.Stop() 26 | if err != nil { 27 | fmt.Println(err.Error()) 28 | return 29 | } 30 | 31 | i := len(collection.Items) 32 | if i == 0 { 33 | color.Red("No environment found for project %s", projectId) 34 | } else { 35 | out.Environments(output, outputFormat, collection) 36 | } 37 | 38 | printMeta(meta, true) 39 | 40 | handlePaginatedResult(meta, func() { 41 | fetchProjectEnvironments(projectId) 42 | }) 43 | } 44 | 45 | var listProjectEnvironmentsCmd = &cobra.Command{ 46 | Use: resourceCmd("project-environments", "project"), 47 | Aliases: []string{"project-envs", "pe"}, 48 | Short: "List project environments", 49 | RunE: func(cmd *cobra.Command, args []string) error { 50 | ids, err := config.aliasIdsOrArgs(currentAlias, "project", args) 51 | if err != nil { 52 | return err 53 | } 54 | 55 | fetchProjectEnvironments(ids["project_id"]) 56 | 57 | return nil 58 | }, 59 | } 60 | -------------------------------------------------------------------------------- /cli/cmd/list_project_environments_cmd_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | ) 8 | 9 | func TestListProjectEnvironmentsCmd(t *testing.T) { 10 | test.RunCommandTestCases(t, "environments", []*test.CommandTestCase{ 11 | { 12 | []string{"list", "project-environments", "--help"}, 13 | nil, 14 | //configs["default"], 15 | "list_project_environments_help", 16 | false, 17 | nil, 18 | }, 19 | { 20 | []string{"list", "project-environments", "1"}, 21 | nil, 22 | //configs["default"], 23 | "list_project_environments", 24 | false, 25 | nil, 26 | }, 27 | /* 28 | { 29 | []string{"list", "project-environments", "1", "--verbose"}, 30 | nil, 31 | //configs["default"], 32 | "list_project_environments_verbose", 33 | false, 34 | nil, 35 | }, 36 | */ 37 | { 38 | []string{"list", "project-environments", "1", "-f", "json"}, 39 | nil, 40 | //configs["default"], 41 | "list_project_environments_json", 42 | false, 43 | nil, 44 | }, 45 | { 46 | []string{"list", "project-environments", "1", "-f", "yaml"}, 47 | nil, 48 | //configs["default"], 49 | "list_project_environments_yaml", 50 | false, 51 | nil, 52 | }, 53 | }) 54 | } 55 | -------------------------------------------------------------------------------- /cli/cmd/list_project_hooks_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | out "github.com/plouc/go-gitlab-client/cli/output" 8 | "github.com/spf13/cobra" 9 | ) 10 | 11 | func init() { 12 | listCmd.AddCommand(listProjectHooksCmd) 13 | } 14 | 15 | func fetchHooks(projectId string) { 16 | color.Yellow("Fetching project's hooks (id: %s)…", projectId) 17 | 18 | loader.Start() 19 | collection, meta, err := client.ProjectHooks(projectId) 20 | loader.Stop() 21 | if err != nil { 22 | fmt.Println(err.Error()) 23 | return 24 | } 25 | 26 | if len(collection.Items) == 0 { 27 | color.Red(" No hook found for project %s", projectId) 28 | } else { 29 | out.Hooks(output, outputFormat, collection) 30 | } 31 | 32 | printMeta(meta, true) 33 | 34 | handlePaginatedResult(meta, func() { 35 | fetchHooks(projectId) 36 | }) 37 | } 38 | 39 | var listProjectHooksCmd = &cobra.Command{ 40 | Use: resourceCmd("project-hooks", "project"), 41 | Aliases: []string{"ph"}, 42 | Short: "List project's hooks", 43 | RunE: func(cmd *cobra.Command, args []string) error { 44 | ids, err := config.aliasIdsOrArgs(currentAlias, "project", args) 45 | if err != nil { 46 | return err 47 | } 48 | 49 | fetchHooks(ids["project_id"]) 50 | 51 | return nil 52 | }, 53 | } 54 | -------------------------------------------------------------------------------- /cli/cmd/list_project_issue_notes_cmd_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | ) 8 | 9 | func TestListProjectIssueNotesCmd(t *testing.T) { 10 | test.RunCommandTestCases(t, "notes", []*test.CommandTestCase{ 11 | { 12 | []string{"list", "project-issue-notes", "--help"}, 13 | nil, 14 | //configs["default"], 15 | "list_project_issue_notes_help", 16 | false, 17 | nil, 18 | }, 19 | { 20 | []string{"list", "project-issue-notes"}, 21 | nil, 22 | //configs["default"], 23 | "list_project_issue_notes_no_project_id", 24 | true, 25 | nil, 26 | }, 27 | { 28 | []string{"list", "project-issue-notes", "1"}, 29 | nil, 30 | //configs["default"], 31 | "list_project_issue_notes_no_issue_iid", 32 | true, 33 | nil, 34 | }, 35 | { 36 | []string{"list", "project-issue-notes", "1", "5"}, 37 | nil, 38 | //configs["default"], 39 | "list_project_issue_notes", 40 | false, 41 | nil, 42 | }, 43 | { 44 | []string{"list", "project-issue-notes", "1", "5", "-f", "json"}, 45 | nil, 46 | //configs["default"], 47 | "list_project_issue_notes_json", 48 | false, 49 | nil, 50 | }, 51 | { 52 | []string{"list", "project-issue-notes", "1", "5", "-f", "yaml"}, 53 | nil, 54 | //configs["default"], 55 | "list_project_issue_notes_yaml", 56 | false, 57 | nil, 58 | }, 59 | }) 60 | } 61 | -------------------------------------------------------------------------------- /cli/cmd/list_project_merge_request_notes_cmd_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | ) 8 | 9 | func TestListProjectMergeRequestNotesCmd(t *testing.T) { 10 | test.RunCommandTestCases(t, "notes", []*test.CommandTestCase{ 11 | { 12 | []string{"list", "project-merge-request-notes", "--help"}, 13 | nil, 14 | //configs["default"], 15 | "list_project_merge_request_notes_help", 16 | false, 17 | nil, 18 | }, 19 | { 20 | []string{"list", "project-merge-request-notes"}, 21 | nil, 22 | //configs["default"], 23 | "list_project_merge_request_notes_no_project_id", 24 | true, 25 | nil, 26 | }, 27 | { 28 | []string{"list", "project-merge-request-notes", "1"}, 29 | nil, 30 | //configs["default"], 31 | "list_project_merge_request_notes_no_merge_request_iid", 32 | true, 33 | nil, 34 | }, 35 | { 36 | []string{"list", "project-merge-request-notes", "1", "3"}, 37 | nil, 38 | //configs["default"], 39 | "list_project_merge_request_notes", 40 | false, 41 | nil, 42 | }, 43 | { 44 | []string{"list", "project-merge-request-notes", "1", "3", "-f", "json"}, 45 | nil, 46 | //configs["default"], 47 | "list_project_merge_request_notes_json", 48 | false, 49 | nil, 50 | }, 51 | { 52 | []string{"list", "project-merge-request-notes", "1", "3", "-f", "yaml"}, 53 | nil, 54 | //configs["default"], 55 | "list_project_merge_request_notes_yaml", 56 | false, 57 | nil, 58 | }, 59 | }) 60 | } 61 | -------------------------------------------------------------------------------- /cli/cmd/list_project_merge_requests_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | out "github.com/plouc/go-gitlab-client/cli/output" 8 | "github.com/plouc/go-gitlab-client/gitlab" 9 | "github.com/spf13/cobra" 10 | ) 11 | 12 | func init() { 13 | listCmd.AddCommand(listProjectMergeRequestsCmd) 14 | } 15 | 16 | func fetchProjectMergeRequests(projectId string) { 17 | color.Yellow("Fetching project %s merge requests…", projectId) 18 | 19 | o := &gitlab.MergeRequestsOptions{} 20 | o.Page = page 21 | o.PerPage = perPage 22 | 23 | loader.Start() 24 | collection, meta, err := client.ProjectMergeRequests(projectId, o) 25 | loader.Stop() 26 | if err != nil { 27 | fmt.Println(err.Error()) 28 | return 29 | } 30 | 31 | if len(collection.Items) == 0 { 32 | color.Red("No merge request found for project %s", projectId) 33 | } else { 34 | out.MergeRequests(output, outputFormat, collection) 35 | } 36 | 37 | printMeta(meta, true) 38 | 39 | handlePaginatedResult(meta, func() { 40 | fetchProjectMergeRequests(projectId) 41 | }) 42 | } 43 | 44 | var listProjectMergeRequestsCmd = &cobra.Command{ 45 | Use: resourceCmd("project-merge-requests", "project"), 46 | Aliases: []string{"pmr"}, 47 | Short: "List project merge requests", 48 | RunE: func(cmd *cobra.Command, args []string) error { 49 | ids, err := config.aliasIdsOrArgs(currentAlias, "project", args) 50 | if err != nil { 51 | return err 52 | } 53 | 54 | fetchProjectMergeRequests(ids["project_id"]) 55 | 56 | return nil 57 | }, 58 | } 59 | -------------------------------------------------------------------------------- /cli/cmd/list_project_merge_requests_cmd_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | ) 8 | 9 | func TestListProjectMergeRequestsCmd(t *testing.T) { 10 | test.RunCommandTestCases(t, "merge_requests", []*test.CommandTestCase{ 11 | { 12 | []string{"list", "project-merge-requests", "--help"}, 13 | nil, 14 | //configs["default"], 15 | "list_project_merge_requests_help", 16 | false, 17 | nil, 18 | }, 19 | { 20 | []string{"list", "project-merge-requests", "1"}, 21 | nil, 22 | //configs["default"], 23 | "list_project_merge_requests", 24 | false, 25 | nil, 26 | }, 27 | /* 28 | { 29 | []string{"list", "project-merge-requests", "1", "--verbose"}, 30 | nil, 31 | //configs["default"], 32 | "list_project_merge_requests_verbose", 33 | false, 34 | nil, 35 | }, 36 | */ 37 | { 38 | []string{"list", "project-merge-requests", "1", "-f", "json"}, 39 | nil, 40 | //configs["default"], 41 | "list_project_merge_requests_json", 42 | false, 43 | nil, 44 | }, 45 | { 46 | []string{"list", "project-merge-requests", "1", "-f", "yaml"}, 47 | nil, 48 | //configs["default"], 49 | "list_project_merge_requests_yaml", 50 | false, 51 | nil, 52 | }, 53 | }) 54 | } 55 | -------------------------------------------------------------------------------- /cli/cmd/list_project_pipelines_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | out "github.com/plouc/go-gitlab-client/cli/output" 8 | "github.com/plouc/go-gitlab-client/gitlab" 9 | "github.com/spf13/cobra" 10 | ) 11 | 12 | func init() { 13 | listCmd.AddCommand(listProjectPipelinesCmd) 14 | } 15 | 16 | func fetchProjectPipelines(projectId string) { 17 | color.Yellow("Fetching project's pipelines (project id: %s)…", projectId) 18 | 19 | o := &gitlab.PipelinesOptions{} 20 | o.Page = page 21 | o.PerPage = perPage 22 | 23 | loader.Start() 24 | collection, meta, err := client.ProjectPipelines(projectId, o) 25 | loader.Stop() 26 | if err != nil { 27 | fmt.Println(err.Error()) 28 | return 29 | } 30 | 31 | if len(collection.Items) == 0 { 32 | color.Red("No pipeline found for project %s", projectId) 33 | } else { 34 | out.Pipelines(output, outputFormat, collection) 35 | } 36 | 37 | printMeta(meta, true) 38 | 39 | handlePaginatedResult(meta, func() { 40 | fetchProjectPipelines(projectId) 41 | }) 42 | } 43 | 44 | var listProjectPipelinesCmd = &cobra.Command{ 45 | Use: resourceCmd("project-pipelines", "project"), 46 | Aliases: []string{"pp"}, 47 | Short: "List project pipelines", 48 | RunE: func(cmd *cobra.Command, args []string) error { 49 | ids, err := config.aliasIdsOrArgs(currentAlias, "project", args) 50 | if err != nil { 51 | return err 52 | } 53 | 54 | fetchProjectPipelines(ids["project_id"]) 55 | 56 | return nil 57 | }, 58 | } 59 | -------------------------------------------------------------------------------- /cli/cmd/list_project_protected_branches_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | out "github.com/plouc/go-gitlab-client/cli/output" 8 | "github.com/spf13/cobra" 9 | ) 10 | 11 | func init() { 12 | listCmd.AddCommand(listProtectedBranchesCmd) 13 | } 14 | 15 | var listProtectedBranchesCmd = &cobra.Command{ 16 | Use: resourceCmd("project-protected-branches", "project"), 17 | Aliases: []string{"ppb"}, 18 | Short: "List project protected branches", 19 | RunE: func(cmd *cobra.Command, args []string) error { 20 | ids, err := config.aliasIdsOrArgs(currentAlias, "project", args) 21 | if err != nil { 22 | return err 23 | } 24 | 25 | color.Yellow("Fetching project protected branches (id: %s)…", ids["project_id"]) 26 | 27 | loader.Start() 28 | protectedBranches, meta, err := client.ProtectedBranches(ids["project_id"], nil) 29 | loader.Stop() 30 | if err != nil { 31 | return err 32 | } 33 | 34 | fmt.Println("") 35 | if len(protectedBranches) == 0 { 36 | color.Red("No protected branch found for project %s", ids["project_id"]) 37 | } else { 38 | out.ProtectedBranches(output, outputFormat, protectedBranches) 39 | } 40 | 41 | printMeta(meta, true) 42 | 43 | return nil 44 | }, 45 | } 46 | -------------------------------------------------------------------------------- /cli/cmd/list_project_snippet_notes_cmd_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | ) 8 | 9 | func TestListProjectSnippetNotesCmd(t *testing.T) { 10 | test.RunCommandTestCases(t, "notes", []*test.CommandTestCase{ 11 | { 12 | []string{"list", "project-snippet-notes", "--help"}, 13 | nil, 14 | //configs["default"], 15 | "list_project_snippet_notes_help", 16 | false, 17 | nil, 18 | }, 19 | { 20 | []string{"list", "project-snippet-notes"}, 21 | nil, 22 | //configs["default"], 23 | "list_project_snippet_notes_no_project_id", 24 | true, 25 | nil, 26 | }, 27 | { 28 | []string{"list", "project-snippet-notes", "1"}, 29 | nil, 30 | //configs["default"], 31 | "list_project_snippet_notes_no_snippet_id", 32 | true, 33 | nil, 34 | }, 35 | { 36 | []string{"list", "project-snippet-notes", "1", "7"}, 37 | nil, 38 | //configs["default"], 39 | "list_project_snippet_notes", 40 | false, 41 | nil, 42 | }, 43 | { 44 | []string{"list", "project-snippet-notes", "1", "7", "-f", "json"}, 45 | nil, 46 | //configs["default"], 47 | "list_project_snippet_notes_json", 48 | false, 49 | nil, 50 | }, 51 | { 52 | []string{"list", "project-snippet-notes", "1", "7", "-f", "yaml"}, 53 | nil, 54 | //configs["default"], 55 | "list_project_snippet_notes_yaml", 56 | false, 57 | nil, 58 | }, 59 | }) 60 | } 61 | -------------------------------------------------------------------------------- /cli/cmd/list_project_variables_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | out "github.com/plouc/go-gitlab-client/cli/output" 8 | "github.com/plouc/go-gitlab-client/gitlab" 9 | "github.com/spf13/cobra" 10 | ) 11 | 12 | func init() { 13 | listCmd.AddCommand(listProjectVariablesCmd) 14 | } 15 | 16 | var listProjectVariablesCmd = &cobra.Command{ 17 | Use: resourceCmd("project-variables", "project"), 18 | Aliases: []string{"project-vars", "pv"}, 19 | Short: "Get list of a project's variables", 20 | RunE: func(cmd *cobra.Command, args []string) error { 21 | ids, err := config.aliasIdsOrArgs(currentAlias, "project", args) 22 | if err != nil { 23 | return err 24 | } 25 | 26 | color.Yellow("Fetching project variables (id: %s)…", ids["project_id"]) 27 | 28 | o := &gitlab.PaginationOptions{ 29 | Page: page, 30 | PerPage: perPage, 31 | } 32 | 33 | loader.Start() 34 | collection, meta, err := client.ProjectVariables(ids["project_id"], o) 35 | loader.Stop() 36 | if err != nil { 37 | return err 38 | } 39 | 40 | fmt.Println("") 41 | if len(collection.Items) == 0 { 42 | color.Red(" No variable found for project %s", ids["project_id"]) 43 | } else { 44 | out.Variables(output, outputFormat, collection) 45 | } 46 | 47 | printMeta(meta, true) 48 | 49 | return nil 50 | }, 51 | } 52 | -------------------------------------------------------------------------------- /cli/cmd/list_projects_cmd_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | ) 8 | 9 | func TestListProjectsCmd(t *testing.T) { 10 | test.RunCommandTestCases(t, "projects", []*test.CommandTestCase{ 11 | { 12 | []string{"list", "projects", "--help"}, 13 | nil, 14 | //configs["default"], 15 | "list_projects_help", 16 | false, 17 | nil, 18 | }, 19 | { 20 | []string{"list", "projects"}, 21 | nil, 22 | //configs["default"], 23 | "list_projects", 24 | false, 25 | nil, 26 | }, 27 | /* 28 | { 29 | []string{"list", "projects", "--verbose"}, 30 | nil, 31 | //configs["default"], 32 | "list_projects_verbose", 33 | false, 34 | nil, 35 | }, 36 | */ 37 | { 38 | []string{"list", "projects", "-f", "json"}, 39 | nil, 40 | //configs["default"], 41 | "list_projects_json", 42 | false, 43 | nil, 44 | }, 45 | { 46 | []string{"list", "projects", "-f", "yaml"}, 47 | nil, 48 | //configs["default"], 49 | "list_projects_yaml", 50 | false, 51 | nil, 52 | }, 53 | }) 54 | } 55 | -------------------------------------------------------------------------------- /cli/cmd/list_runners_cmd_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | ) 8 | 9 | func TestListRunnersCmd(t *testing.T) { 10 | test.RunCommandTestCases(t, "runners", []*test.CommandTestCase{ 11 | { 12 | []string{"list", "runners", "--help"}, 13 | nil, 14 | //configs["default"], 15 | "list_runners_help", 16 | false, 17 | nil, 18 | }, 19 | { 20 | []string{"list", "runners"}, 21 | nil, 22 | //configs["default"], 23 | "list_runners", 24 | false, 25 | nil, 26 | }, 27 | /* 28 | { 29 | []string{"list", "runners", "--verbose"}, 30 | nil, 31 | //configs["default"], 32 | "list_runners_verbose", 33 | false, 34 | nil, 35 | }, 36 | */ 37 | { 38 | []string{"list", "runners", "-f", "json"}, 39 | nil, 40 | //configs["default"], 41 | "list_runners_json", 42 | false, 43 | nil, 44 | }, 45 | { 46 | []string{"list", "runners", "-f", "yaml"}, 47 | nil, 48 | //configs["default"], 49 | "list_runners_yaml", 50 | false, 51 | nil, 52 | }, 53 | }) 54 | } 55 | -------------------------------------------------------------------------------- /cli/cmd/list_ssh_keys_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | out "github.com/plouc/go-gitlab-client/cli/output" 8 | "github.com/plouc/go-gitlab-client/gitlab" 9 | "github.com/spf13/cobra" 10 | ) 11 | 12 | func init() { 13 | listCmd.AddCommand(listSshKeysCmd) 14 | } 15 | 16 | func fetchSshKeys() { 17 | color.Yellow("Fetching current user ssh keys…") 18 | 19 | o := &gitlab.PaginationOptions{} 20 | o.Page = page 21 | o.PerPage = perPage 22 | 23 | loader.Start() 24 | collection, meta, err := client.CurrentUserSshKeys(o) 25 | loader.Stop() 26 | if err != nil { 27 | fmt.Println(err.Error()) 28 | return 29 | } 30 | 31 | if len(collection.Items) == 0 { 32 | color.Red("No ssh key found") 33 | } else { 34 | out.SshKeys(output, outputFormat, collection) 35 | } 36 | 37 | printMeta(meta, true) 38 | 39 | handlePaginatedResult(meta, fetchSshKeys) 40 | } 41 | 42 | var listSshKeysCmd = &cobra.Command{ 43 | Use: "ssh-keys", 44 | Aliases: []string{"sk"}, 45 | Short: "List current user ssh keys", 46 | Run: func(cmd *cobra.Command, args []string) { 47 | fetchSshKeys() 48 | }, 49 | } 50 | -------------------------------------------------------------------------------- /cli/cmd/list_ssh_keys_cmd_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | ) 8 | 9 | func TestListSshKeysCmd(t *testing.T) { 10 | test.RunCommandTestCases(t, "ssh_keys", []*test.CommandTestCase{ 11 | { 12 | []string{"list", "ssh-keys", "--help"}, 13 | nil, 14 | //configs["default"], 15 | "list_ssh_keys_help", 16 | false, 17 | nil, 18 | }, 19 | { 20 | []string{"list", "ssh-keys"}, 21 | nil, 22 | //configs["default"], 23 | "list_ssh_keys", 24 | false, 25 | nil, 26 | }, 27 | /* 28 | { 29 | []string{"list", "ssh-keys", "--verbose"}, 30 | nil, 31 | //configs["default"], 32 | "list_ssh_keys_verbose", 33 | false, 34 | nil, 35 | }, 36 | */ 37 | { 38 | []string{"list", "ssh-keys", "-f", "json"}, 39 | nil, 40 | //configs["default"], 41 | "list_ssh_keys_json", 42 | false, 43 | nil, 44 | }, 45 | { 46 | []string{"list", "ssh-keys", "-f", "yaml"}, 47 | nil, 48 | //configs["default"], 49 | "list_ssh_keys_yaml", 50 | false, 51 | nil, 52 | }, 53 | }) 54 | } 55 | -------------------------------------------------------------------------------- /cli/cmd/list_user_ssh_keys_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | 7 | "github.com/fatih/color" 8 | out "github.com/plouc/go-gitlab-client/cli/output" 9 | "github.com/plouc/go-gitlab-client/gitlab" 10 | "github.com/spf13/cobra" 11 | ) 12 | 13 | func init() { 14 | listCmd.AddCommand(listUserSshKeysCmd) 15 | } 16 | 17 | func fetchUserSshKeys(userId int) { 18 | color.Yellow("Fetching user %d ssh keys…", userId) 19 | 20 | o := &gitlab.PaginationOptions{} 21 | o.Page = page 22 | o.PerPage = perPage 23 | 24 | loader.Start() 25 | collection, meta, err := client.CurrentUserSshKeys(o) 26 | loader.Stop() 27 | if err != nil { 28 | fmt.Println(err.Error()) 29 | return 30 | } 31 | 32 | if len(collection.Items) == 0 { 33 | color.Red("No ssh key found for user: %d", userId) 34 | } else { 35 | out.SshKeys(output, outputFormat, collection) 36 | } 37 | 38 | printMeta(meta, true) 39 | 40 | handlePaginatedResult(meta, func() { 41 | fetchUserSshKeys(userId) 42 | }) 43 | } 44 | 45 | var listUserSshKeysCmd = &cobra.Command{ 46 | Use: resourceCmd("user-ssh-keys", "user"), 47 | Aliases: []string{"usk"}, 48 | Short: "List specific user ssh keys", 49 | RunE: func(cmd *cobra.Command, args []string) error { 50 | ids, err := config.aliasIdsOrArgs(currentAlias, "user", args) 51 | if err != nil { 52 | return err 53 | } 54 | 55 | userId, err := strconv.Atoi(ids["user_id"]) 56 | if err != nil { 57 | return err 58 | } 59 | 60 | fetchUserSshKeys(userId) 61 | 62 | return nil 63 | }, 64 | } 65 | -------------------------------------------------------------------------------- /cli/cmd/list_user_ssh_keys_cmd_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | ) 8 | 9 | func TestListUserSshKeysCmd(t *testing.T) { 10 | test.RunCommandTestCases(t, "ssh_keys", []*test.CommandTestCase{ 11 | { 12 | []string{"list", "user-ssh-keys", "--help"}, 13 | nil, 14 | //configs["default"], 15 | "list_user_ssh_keys_help", 16 | false, 17 | nil, 18 | }, 19 | { 20 | []string{"list", "user-ssh-keys", "1"}, 21 | nil, 22 | //configs["default"], 23 | "list_user_ssh_keys", 24 | false, 25 | nil, 26 | }, 27 | /* 28 | { 29 | []string{"ls", "user-ssh-keys", "1", "-v"}, 30 | nil, 31 | //configs["default"], 32 | "ls_user_ssh_keys_verbose", 33 | false, 34 | nil, 35 | }, 36 | */ 37 | { 38 | []string{"list", "user-ssh-keys", "1", "-f", "json"}, 39 | nil, 40 | //configs["default"], 41 | "list_user_ssh_keys_json", 42 | false, 43 | nil, 44 | }, 45 | { 46 | []string{"list", "user-ssh-keys", "1", "-f", "yaml"}, 47 | nil, 48 | //configs["default"], 49 | "list_user_ssh_keys_yaml", 50 | false, 51 | nil, 52 | }, 53 | }) 54 | } 55 | -------------------------------------------------------------------------------- /cli/cmd/list_users_cmd_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | ) 8 | 9 | func TestListUsersCmd(t *testing.T) { 10 | test.RunCommandTestCases(t, "users", []*test.CommandTestCase{ 11 | { 12 | []string{"list", "users", "--help"}, 13 | nil, 14 | //configs["default"], 15 | "list_users_help", 16 | false, 17 | nil, 18 | }, 19 | { 20 | []string{"list", "users"}, 21 | nil, 22 | //configs["default"], 23 | "list_users", 24 | false, 25 | nil, 26 | }, 27 | /* 28 | { 29 | []string{"list", "users", "--verbose"}, 30 | nil, 31 | //configs["default"], 32 | "ls_users_verbose", 33 | false, 34 | nil, 35 | }, 36 | */ 37 | { 38 | []string{"list", "users", "-f", "json"}, 39 | nil, 40 | //configs["default"], 41 | "list_users_json", 42 | false, 43 | nil, 44 | }, 45 | { 46 | []string{"list", "users", "-f", "yaml"}, 47 | nil, 48 | //configs["default"], 49 | "list_users_yaml", 50 | false, 51 | nil, 52 | }, 53 | }) 54 | } 55 | -------------------------------------------------------------------------------- /cli/cmd/output.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | out "github.com/plouc/go-gitlab-client/cli/output" 5 | "github.com/plouc/go-gitlab-client/gitlab" 6 | ) 7 | 8 | func printMeta(meta *gitlab.ResponseMeta, withPagination bool) { 9 | if verbose { 10 | out.Meta(meta, withPagination) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /cli/cmd/output_config.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/olekukonko/tablewriter" 7 | "os" 8 | ) 9 | 10 | func aliasesOutput(aliases []*Alias) { 11 | fmt.Println("") 12 | table := tablewriter.NewWriter(os.Stdout) 13 | table.SetHeader([]string{ 14 | "Alias", 15 | "Resource type", 16 | "Resource id", 17 | }) 18 | table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false}) 19 | for _, alias := range aliases { 20 | table.Append([]string{ 21 | alias.Alias, 22 | alias.ResourceType, 23 | alias.IdsString(), 24 | }) 25 | } 26 | table.Render() 27 | fmt.Println("") 28 | } 29 | -------------------------------------------------------------------------------- /cli/cmd/prompt_vars.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/fatih/color" 5 | "github.com/manifoldco/promptui" 6 | "github.com/plouc/go-gitlab-client/gitlab" 7 | ) 8 | 9 | func promptVariable() (*gitlab.Variable, error) { 10 | variable := gitlab.Variable{} 11 | 12 | prompt := promptui.Prompt{ 13 | Label: "Key", 14 | } 15 | key, err := prompt.Run() 16 | if err != nil { 17 | return nil, err 18 | } 19 | variable.Key = key 20 | 21 | prompt = promptui.Prompt{ 22 | Label: "Value", 23 | } 24 | value, err := prompt.Run() 25 | if err != nil { 26 | return nil, err 27 | } 28 | variable.Value = value 29 | 30 | selectPrompt := promptui.Select{ 31 | Label: color.YellowString("Protect variable?"), 32 | Items: []string{"yes", "no"}, 33 | } 34 | idx, _, err := selectPrompt.Run() 35 | if err != nil { 36 | return nil, err 37 | } 38 | if idx == 0 { 39 | variable.Protected = true 40 | } 41 | 42 | prompt = promptui.Prompt{ 43 | Label: "EnvironmentScope", 44 | } 45 | environmentScope, err := prompt.Run() 46 | if err != nil { 47 | return nil, err 48 | } 49 | variable.EnvironmentScope = environmentScope 50 | 51 | return &variable, nil 52 | } 53 | -------------------------------------------------------------------------------- /cli/cmd/related.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | "github.com/spf13/cobra" 8 | "strings" 9 | ) 10 | 11 | type relatedCommand struct { 12 | cmd *cobra.Command 13 | args map[string]string 14 | } 15 | 16 | func newRelatedCommand(cmd *cobra.Command, args map[string]string) *relatedCommand { 17 | return &relatedCommand{cmd, args} 18 | } 19 | 20 | func getFullCommand(path string, cmd *cobra.Command) string { 21 | var p string 22 | if path == "" { 23 | p = fmt.Sprintf("%s %s", cmd.Use, path) 24 | } else { 25 | parts := strings.Split(cmd.Use, " ") 26 | p = fmt.Sprintf("%s %s", parts[0], path) 27 | } 28 | 29 | parent := cmd.Parent() 30 | if parent != nil { 31 | return getFullCommand(p, parent) 32 | } 33 | 34 | return p 35 | } 36 | 37 | func relatedCommands(cmds []*relatedCommand) { 38 | if !verbose { 39 | return 40 | } 41 | 42 | color.Yellow("Related commands:") 43 | fmt.Println("") 44 | for _, r := range cmds { 45 | full := getFullCommand("", r.cmd) 46 | for k, v := range r.args { 47 | full = strings.Replace(full, strings.ToUpper(k), v, -1) 48 | } 49 | 50 | fmt.Printf("- %-42s %s\n", r.cmd.Short, color.YellowString(full)) 51 | } 52 | fmt.Println("") 53 | } 54 | -------------------------------------------------------------------------------- /cli/cmd/rm_alias_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "github.com/fatih/color" 6 | "github.com/spf13/cobra" 7 | ) 8 | 9 | func init() { 10 | rmCmd.AddCommand(rmAliasCmd) 11 | } 12 | 13 | var rmAliasCmd = &cobra.Command{ 14 | Use: "alias [alias] [resource type]", 15 | Aliases: []string{"a"}, 16 | Short: "Remove resource alias", 17 | Args: func(cmd *cobra.Command, args []string) error { 18 | if len(args) < 2 { 19 | return fmt.Errorf("you must specify an alias and a resource type") 20 | } 21 | 22 | return nil 23 | }, 24 | Run: func(cmd *cobra.Command, args []string) { 25 | alias := args[0] 26 | resourceType := args[1] 27 | 28 | color.Yellow("Removing %s alias %s…", resourceType, alias) 29 | 30 | _, a := config.findAlias(alias, resourceType) 31 | if a == nil { 32 | color.Red("✘ No %s alias found for %s", resourceType, alias) 33 | return 34 | } 35 | 36 | config.Write(configFile) 37 | 38 | color.Green("✔ Alias %s was successfully removed", alias) 39 | }, 40 | } 41 | -------------------------------------------------------------------------------- /cli/cmd/rm_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/spf13/cobra" 5 | ) 6 | 7 | var autoConfirmRemoval bool 8 | 9 | func init() { 10 | RootCmd.AddCommand(rmCmd) 11 | 12 | rmCmd.PersistentFlags().BoolVarP(&autoConfirmRemoval, "yes", "y", false, "Do not ask for confirmation") 13 | } 14 | 15 | var rmCmd = &cobra.Command{ 16 | Use: "rm", 17 | Short: "Remove resource", 18 | } 19 | -------------------------------------------------------------------------------- /cli/cmd/rm_cmd_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | ) 8 | 9 | func TestRmCmd(t *testing.T) { 10 | test.RunCommandTestCases(t, "users", []*test.CommandTestCase{ 11 | { 12 | []string{"rm"}, 13 | nil, 14 | //configs["default"], 15 | "rm_help", 16 | false, 17 | nil, 18 | }, 19 | { 20 | []string{"rm", "--help"}, 21 | nil, 22 | //configs["default"], 23 | "rm_help", 24 | false, 25 | nil, 26 | }, 27 | }) 28 | } 29 | -------------------------------------------------------------------------------- /cli/cmd/rm_group_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | "github.com/spf13/cobra" 8 | ) 9 | 10 | func init() { 11 | rmCmd.AddCommand(rmGroupCmd) 12 | } 13 | 14 | var rmGroupCmd = &cobra.Command{ 15 | Use: resourceCmd("group", "group"), 16 | Aliases: []string{"g"}, 17 | Short: "Remove group", 18 | RunE: func(cmd *cobra.Command, args []string) error { 19 | ids, err := config.aliasIdsOrArgs(currentAlias, "group", args) 20 | if err != nil { 21 | return err 22 | } 23 | 24 | color.Yellow("Removing group (id: %s)…", ids["group_id"]) 25 | 26 | confirmed := confirmAction( 27 | fmt.Sprintf("Are you sure you want to remove group %s?", ids["group_id"]), 28 | "aborted group removal", 29 | autoConfirmRemoval, 30 | ) 31 | if !confirmed { 32 | return nil 33 | } 34 | 35 | loader.Start() 36 | message, meta, err := client.RemoveGroup(ids["group_id"]) 37 | loader.Stop() 38 | if err != nil { 39 | return err 40 | } 41 | 42 | color.Green("✔ Group was successfully removed: %s", message) 43 | 44 | printMeta(meta, false) 45 | 46 | return nil 47 | }, 48 | } 49 | -------------------------------------------------------------------------------- /cli/cmd/rm_group_epic_note_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | "github.com/spf13/cobra" 8 | "strconv" 9 | ) 10 | 11 | func init() { 12 | rmCmd.AddCommand(rmGroupEpicNoteCmd) 13 | } 14 | 15 | var rmGroupEpicNoteCmd = &cobra.Command{ 16 | Use: resourceCmd("group-epic-note", "group-epic-note"), 17 | Aliases: []string{"epic-note"}, 18 | Short: "Remove group epic note", 19 | RunE: func(cmd *cobra.Command, args []string) error { 20 | ids, err := config.aliasIdsOrArgs(currentAlias, "group-epic-note", args) 21 | if err != nil { 22 | return err 23 | } 24 | 25 | epicId, err := strconv.Atoi(ids["epic_id"]) 26 | if err != nil { 27 | return err 28 | } 29 | 30 | noteId, err := strconv.Atoi(ids["note_id"]) 31 | if err != nil { 32 | return err 33 | } 34 | 35 | color.Yellow("Removing group epic note (group id: %s, epic id: %d, note id: %d)…", ids["group_id"], epicId, noteId) 36 | 37 | confirmed := confirmAction( 38 | fmt.Sprintf("Are you sure you want to remove group %s epic %d note %d?", ids["group_id"], epicId, noteId), 39 | "aborted group epic note removal", 40 | autoConfirmRemoval, 41 | ) 42 | if !confirmed { 43 | return nil 44 | } 45 | 46 | loader.Start() 47 | meta, err := client.RemoveGroupEpicNote(ids["group_id"], epicId, noteId) 48 | loader.Stop() 49 | if err != nil { 50 | return err 51 | } 52 | 53 | color.Green("✔ Successfully removed note: %d", noteId) 54 | 55 | printMeta(meta, false) 56 | 57 | return nil 58 | }, 59 | } 60 | -------------------------------------------------------------------------------- /cli/cmd/rm_group_var_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | "github.com/spf13/cobra" 8 | ) 9 | 10 | func init() { 11 | rmCmd.AddCommand(rmGroupVarCmd) 12 | } 13 | 14 | var rmGroupVarCmd = &cobra.Command{ 15 | Use: resourceCmd("group-var", "group-var"), 16 | Aliases: []string{"gv"}, 17 | Short: "Remove a group's variable", 18 | RunE: func(cmd *cobra.Command, args []string) error { 19 | ids, err := config.aliasIdsOrArgs(currentAlias, "group-var", args) 20 | if err != nil { 21 | return err 22 | } 23 | 24 | color.Yellow("Removing group variable (group id: %s, key: %s)…", ids["group_id"], ids["var_key"]) 25 | 26 | confirmed := confirmAction( 27 | fmt.Sprintf("Are you sure you want to remove group %s variable %s?", ids["group_id"], ids["var_key"]), 28 | "aborted group variable removal", 29 | autoConfirmRemoval, 30 | ) 31 | if !confirmed { 32 | return nil 33 | } 34 | 35 | loader.Start() 36 | meta, err := client.RemoveGroupVariable(ids["group_id"], ids["var_key"]) 37 | loader.Stop() 38 | if err != nil { 39 | return err 40 | } 41 | 42 | color.Green("✔ Successfully removed variable: %s", ids["var_key"]) 43 | 44 | printMeta(meta, false) 45 | 46 | return nil 47 | }, 48 | } 49 | -------------------------------------------------------------------------------- /cli/cmd/rm_project_badge_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | "github.com/spf13/cobra" 8 | ) 9 | 10 | func init() { 11 | rmCmd.AddCommand(rmProjectBadgeCmd) 12 | } 13 | 14 | var rmProjectBadgeCmd = &cobra.Command{ 15 | Use: resourceCmd("project-badge", "project-badge"), 16 | Aliases: []string{"pbdg"}, 17 | Short: "Remove project badge", 18 | RunE: func(cmd *cobra.Command, args []string) error { 19 | ids, err := config.aliasIdsOrArgs(currentAlias, "project-badge", args) 20 | if err != nil { 21 | return err 22 | } 23 | 24 | confirmed := confirmAction( 25 | fmt.Sprintf("Are you sure you want to remove project %s badge %s?", ids["project_id"], ids["badge_id"]), 26 | "aborted project badge removal", 27 | autoConfirmRemoval, 28 | ) 29 | if !confirmed { 30 | return nil 31 | } 32 | 33 | color.Yellow("Removing project badge (project id: %s, badge id: %s)…", ids["project_id"], ids["badge_id"]) 34 | 35 | loader.Start() 36 | meta, err := client.RemoveProjectBadge(ids["project_id"], ids["badge_id"]) 37 | loader.Stop() 38 | if err != nil { 39 | return err 40 | } 41 | 42 | color.Green("✔ Project badge was successfully removed") 43 | 44 | printMeta(meta, false) 45 | 46 | return nil 47 | }, 48 | } 49 | -------------------------------------------------------------------------------- /cli/cmd/rm_project_branch_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | "github.com/spf13/cobra" 8 | ) 9 | 10 | func init() { 11 | rmCmd.AddCommand(rmProjectBranchCmd) 12 | } 13 | 14 | var rmProjectBranchCmd = &cobra.Command{ 15 | Use: resourceCmd("project-branch", "project-branch"), 16 | Aliases: []string{"pb"}, 17 | Short: "Remove project branch", 18 | RunE: func(cmd *cobra.Command, args []string) error { 19 | ids, err := config.aliasIdsOrArgs(currentAlias, "project-branch", args) 20 | if err != nil { 21 | return err 22 | } 23 | 24 | color.Yellow("Removing project branch (project id: %s, branch name: %s)…", ids["project_id"], ids["branch_name"]) 25 | 26 | confirmed := confirmAction( 27 | fmt.Sprintf("Are you sure you want to remove project %s branch: %s?", ids["project_id"], ids["branch_name"]), 28 | "aborted branch removal", 29 | autoConfirmRemoval, 30 | ) 31 | if !confirmed { 32 | return nil 33 | } 34 | 35 | loader.Start() 36 | meta, err := client.RemoveProjectBranch(ids["project_id"], ids["branch_name"]) 37 | loader.Stop() 38 | if err != nil { 39 | return err 40 | } 41 | 42 | color.Green("✔ Branch %s was successfully removed", ids["branch_name"]) 43 | 44 | printMeta(meta, false) 45 | 46 | return nil 47 | }, 48 | } 49 | -------------------------------------------------------------------------------- /cli/cmd/rm_project_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | "github.com/spf13/cobra" 8 | ) 9 | 10 | func init() { 11 | rmCmd.AddCommand(rmProjectCmd) 12 | } 13 | 14 | var rmProjectCmd = &cobra.Command{ 15 | Use: resourceCmd("project", "project"), 16 | Aliases: []string{"p"}, 17 | Short: "Remove project", 18 | RunE: func(cmd *cobra.Command, args []string) error { 19 | ids, err := config.aliasIdsOrArgs(currentAlias, "project", args) 20 | if err != nil { 21 | return err 22 | } 23 | 24 | color.Yellow("Removing project (id: %s)…", ids["project_id"]) 25 | 26 | confirmed := confirmAction( 27 | fmt.Sprintf("Are you sure you want to remove project %s?", ids["project_id"]), 28 | "aborted project removal", 29 | autoConfirmRemoval, 30 | ) 31 | if !confirmed { 32 | return nil 33 | } 34 | 35 | loader.Start() 36 | message, meta, err := client.RemoveProject(ids["project_id"]) 37 | loader.Stop() 38 | if err != nil { 39 | return err 40 | } 41 | 42 | color.Green("✔ Project was successfully removed: %s", message) 43 | 44 | printMeta(meta, false) 45 | 46 | return nil 47 | }, 48 | } 49 | -------------------------------------------------------------------------------- /cli/cmd/rm_project_environment_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | 7 | "github.com/fatih/color" 8 | "github.com/spf13/cobra" 9 | ) 10 | 11 | func init() { 12 | rmCmd.AddCommand(rmProjectEnvironmentCmd) 13 | } 14 | 15 | var rmProjectEnvironmentCmd = &cobra.Command{ 16 | Use: resourceCmd("project-environment", "project-environment"), 17 | Aliases: []string{"project-env", "pe"}, 18 | Short: "Remove project environment", 19 | RunE: func(cmd *cobra.Command, args []string) error { 20 | ids, err := config.aliasIdsOrArgs(currentAlias, "project-environment", args) 21 | if err != nil { 22 | return err 23 | } 24 | 25 | environmentId, err := strconv.Atoi(ids["environment_id"]) 26 | if err != nil { 27 | return err 28 | } 29 | 30 | confirmed := confirmAction( 31 | fmt.Sprintf("Are you sure you want to remove project %s environment %d?", ids["project_id"], environmentId), 32 | "aborted project environment removal", 33 | autoConfirmRemoval, 34 | ) 35 | if !confirmed { 36 | return nil 37 | } 38 | 39 | color.Yellow("Removing project environment (project id: %s, environment id: %d)…", ids["project_id"], environmentId) 40 | 41 | loader.Start() 42 | meta, err := client.RemoveProjectEnvironment(ids["project_id"], environmentId) 43 | loader.Stop() 44 | if err != nil { 45 | return err 46 | } 47 | 48 | color.Green("✔ Project environment was successfully removed") 49 | 50 | printMeta(meta, false) 51 | 52 | return nil 53 | }, 54 | } 55 | -------------------------------------------------------------------------------- /cli/cmd/rm_project_hook_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | "github.com/spf13/cobra" 8 | ) 9 | 10 | func init() { 11 | rmCmd.AddCommand(rmProjectHookCmd) 12 | } 13 | 14 | var rmProjectHookCmd = &cobra.Command{ 15 | Use: resourceCmd("project-hook", "project-hook"), 16 | Aliases: []string{"ph"}, 17 | Short: "Remove project hook", 18 | RunE: func(cmd *cobra.Command, args []string) error { 19 | ids, err := config.aliasIdsOrArgs(currentAlias, "project-hook", args) 20 | if err != nil { 21 | return err 22 | } 23 | 24 | color.Yellow("Removing project hook (project id: %s, hook id: %s)…", ids["project_id"], ids["hook_id"]) 25 | 26 | confirmed := confirmAction( 27 | fmt.Sprintf("Are you sure you want to remove project %s hook %s?", ids["project_id"], ids["hook_id"]), 28 | "aborted project hook removal", 29 | autoConfirmRemoval, 30 | ) 31 | if !confirmed { 32 | return nil 33 | } 34 | 35 | loader.Start() 36 | meta, err := client.RemoveProjectHook(ids["project_id"], ids["hook_id"]) 37 | loader.Stop() 38 | if err != nil { 39 | return err 40 | } 41 | 42 | printMeta(meta, false) 43 | 44 | return nil 45 | }, 46 | } 47 | -------------------------------------------------------------------------------- /cli/cmd/rm_project_issue_note_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | "github.com/spf13/cobra" 8 | "strconv" 9 | ) 10 | 11 | func init() { 12 | rmCmd.AddCommand(rmProjectIssueNoteCmd) 13 | } 14 | 15 | var rmProjectIssueNoteCmd = &cobra.Command{ 16 | Use: resourceCmd("project-issue-note", "project-issue-note"), 17 | Aliases: []string{"issue-note"}, 18 | Short: "Remove project issue note", 19 | RunE: func(cmd *cobra.Command, args []string) error { 20 | ids, err := config.aliasIdsOrArgs(currentAlias, "project-issue-note", args) 21 | if err != nil { 22 | return err 23 | } 24 | 25 | issueIid, err := strconv.Atoi(ids["issue_iid"]) 26 | if err != nil { 27 | return err 28 | } 29 | 30 | noteId, err := strconv.Atoi(ids["note_id"]) 31 | if err != nil { 32 | return err 33 | } 34 | 35 | color.Yellow("Removing project issue note (project id: %s, issue iid: %d, note id: %d)…", ids["project_id"], issueIid, noteId) 36 | 37 | confirmed := confirmAction( 38 | fmt.Sprintf("Are you sure you want to remove project %s issue %d note %d?", ids["project_id"], issueIid, noteId), 39 | "aborted project issue note removal", 40 | autoConfirmRemoval, 41 | ) 42 | if !confirmed { 43 | return nil 44 | } 45 | 46 | loader.Start() 47 | meta, err := client.RemoveProjectIssueNote(ids["project_id"], issueIid, noteId) 48 | loader.Stop() 49 | if err != nil { 50 | return err 51 | } 52 | 53 | color.Green("✔ Successfully removed note: %d", noteId) 54 | 55 | printMeta(meta, false) 56 | 57 | return nil 58 | }, 59 | } 60 | -------------------------------------------------------------------------------- /cli/cmd/rm_project_merged_branches_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | "github.com/spf13/cobra" 8 | ) 9 | 10 | func init() { 11 | rmCmd.AddCommand(rmProjectMergedBranchesCmd) 12 | } 13 | 14 | var rmProjectMergedBranchesCmd = &cobra.Command{ 15 | Use: resourceCmd("project-merged-branches", "project"), 16 | Aliases: []string{"pmb"}, 17 | Short: "Remove project merged branches", 18 | RunE: func(cmd *cobra.Command, args []string) error { 19 | ids, err := config.aliasIdsOrArgs(currentAlias, "project", args) 20 | if err != nil { 21 | return err 22 | } 23 | 24 | color.Yellow("Removing project merged branch (project id: %s)…", ids["project_id"]) 25 | 26 | confirmed := confirmAction( 27 | fmt.Sprintf("Are you sure you want to remove project %s merged branches?", ids["project_id"]), 28 | "aborted merged branches removal", 29 | autoConfirmRemoval, 30 | ) 31 | if !confirmed { 32 | return nil 33 | } 34 | 35 | loader.Start() 36 | message, meta, err := client.RemoveProjectMergedBranches(ids["project_id"]) 37 | loader.Stop() 38 | if err != nil { 39 | return err 40 | } 41 | 42 | color.Green("✔ Project merged branches were successfully removed: %s", message) 43 | 44 | printMeta(meta, false) 45 | 46 | return nil 47 | }, 48 | } 49 | -------------------------------------------------------------------------------- /cli/cmd/rm_project_protected_branch_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | "github.com/spf13/cobra" 8 | ) 9 | 10 | func init() { 11 | rmCmd.AddCommand(rmProjectProtectedBranchCmd) 12 | } 13 | 14 | var rmProjectProtectedBranchCmd = &cobra.Command{ 15 | Use: resourceCmd("project-protected-branch", "project-branch"), 16 | Aliases: []string{"ppb"}, 17 | Short: "Unprotect project branch", 18 | RunE: func(cmd *cobra.Command, args []string) error { 19 | ids, err := config.aliasIdsOrArgs(currentAlias, "project-branch", args) 20 | if err != nil { 21 | return err 22 | } 23 | 24 | color.Yellow("Unprotecting project branch (project id: %s, branch name: %s)…", ids["project_id"], ids["branch_name"]) 25 | 26 | confirmed := confirmAction( 27 | fmt.Sprintf("Are you sure you want to remove project %s protected branch %s?", ids["project_id"], ids["branch_name"]), 28 | "aborted project protected branch removal", 29 | autoConfirmRemoval, 30 | ) 31 | if !confirmed { 32 | return nil 33 | } 34 | 35 | loader.Start() 36 | meta, err := client.UnprotectBranch(ids["project_id"], ids["branch_name"]) 37 | loader.Stop() 38 | if err != nil { 39 | fmt.Println(err.Error()) 40 | return err 41 | } 42 | 43 | printMeta(meta, false) 44 | 45 | return nil 46 | }, 47 | } 48 | -------------------------------------------------------------------------------- /cli/cmd/rm_project_snippet_note_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | "github.com/spf13/cobra" 8 | "strconv" 9 | ) 10 | 11 | func init() { 12 | rmCmd.AddCommand(rmProjectSnippetNoteCmd) 13 | } 14 | 15 | var rmProjectSnippetNoteCmd = &cobra.Command{ 16 | Use: resourceCmd("project-snippet-note", "project-snippet-note"), 17 | Aliases: []string{"snippet-note"}, 18 | Short: "Remove project snippet note", 19 | RunE: func(cmd *cobra.Command, args []string) error { 20 | ids, err := config.aliasIdsOrArgs(currentAlias, "project-snippet-note", args) 21 | if err != nil { 22 | return err 23 | } 24 | 25 | snippetId, err := strconv.Atoi(ids["snippet_id"]) 26 | if err != nil { 27 | return err 28 | } 29 | 30 | noteId, err := strconv.Atoi(ids["note_id"]) 31 | if err != nil { 32 | return err 33 | } 34 | 35 | color.Yellow("Removing project snippet note (project id: %s, snippet id: %d, note id: %d)…", ids["project_id"], snippetId, noteId) 36 | 37 | confirmed := confirmAction( 38 | fmt.Sprintf("Are you sure you want to remove project %s snippet %d note %d?", ids["project_id"], snippetId, noteId), 39 | "aborted project snippet note removal", 40 | autoConfirmRemoval, 41 | ) 42 | if !confirmed { 43 | return nil 44 | } 45 | 46 | loader.Start() 47 | meta, err := client.RemoveProjectSnippetNote(ids["project_id"], snippetId, noteId) 48 | loader.Stop() 49 | if err != nil { 50 | return err 51 | } 52 | 53 | color.Green("✔ Successfully removed note: %d", noteId) 54 | 55 | printMeta(meta, false) 56 | 57 | return nil 58 | }, 59 | } 60 | -------------------------------------------------------------------------------- /cli/cmd/rm_project_star_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | out "github.com/plouc/go-gitlab-client/cli/output" 8 | "github.com/spf13/cobra" 9 | ) 10 | 11 | func init() { 12 | rmCmd.AddCommand(rmProjectStarCmd) 13 | } 14 | 15 | var rmProjectStarCmd = &cobra.Command{ 16 | Use: resourceCmd("project-star", "project"), 17 | Aliases: []string{"ps"}, 18 | Short: "Unstars a given project", 19 | RunE: func(cmd *cobra.Command, args []string) error { 20 | ids, err := config.aliasIdsOrArgs(currentAlias, "project", args) 21 | if err != nil { 22 | return err 23 | } 24 | 25 | color.Yellow("Unstaring project (project id: %s)…", ids["project_id"]) 26 | 27 | confirmed := confirmAction( 28 | fmt.Sprintf("Are you sure you want to unstar project %s?", ids["project_id"]), 29 | "aborted project star removal", 30 | autoConfirmRemoval, 31 | ) 32 | if !confirmed { 33 | return nil 34 | } 35 | 36 | loader.Start() 37 | project, meta, err := client.UnstarProject(ids["project_id"]) 38 | loader.Stop() 39 | if err != nil { 40 | fmt.Println(err.Error()) 41 | return err 42 | } 43 | 44 | if meta.StatusCode == 304 { 45 | color.Red("\n You didn't stared project %s!", ids["project_id"]) 46 | } 47 | 48 | if project != nil { 49 | out.Project(output, outputFormat, project, false) 50 | } 51 | 52 | printMeta(meta, false) 53 | 54 | return nil 55 | }, 56 | } 57 | -------------------------------------------------------------------------------- /cli/cmd/rm_project_var_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | "github.com/spf13/cobra" 8 | ) 9 | 10 | func init() { 11 | rmCmd.AddCommand(rmProjectVarCmd) 12 | } 13 | 14 | var rmProjectVarCmd = &cobra.Command{ 15 | Use: resourceCmd("project-var", "project-var"), 16 | Aliases: []string{"pv"}, 17 | Short: "Remove a project's variable", 18 | RunE: func(cmd *cobra.Command, args []string) error { 19 | ids, err := config.aliasIdsOrArgs(currentAlias, "project-var", args) 20 | if err != nil { 21 | return err 22 | } 23 | 24 | color.Yellow("Removing project variable (id: %s, key: %s)…", ids["project_id"], ids["var_key"]) 25 | 26 | confirmed := confirmAction( 27 | fmt.Sprintf("Are you sure you want to remove project %s variable %s?", ids["project_id"], ids["var_key"]), 28 | "aborted project variable removal", 29 | autoConfirmRemoval, 30 | ) 31 | if !confirmed { 32 | return nil 33 | } 34 | 35 | loader.Start() 36 | meta, err := client.RemoveProjectVariable(ids["project_id"], ids["var_key"]) 37 | loader.Stop() 38 | if err != nil { 39 | return err 40 | } 41 | 42 | color.Green("✔ Successfully removed variable: %s", ids["var_key"]) 43 | 44 | printMeta(meta, false) 45 | 46 | return nil 47 | }, 48 | } 49 | -------------------------------------------------------------------------------- /cli/cmd/root_cmd_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | ) 8 | 9 | func TestRootCmd(t *testing.T) { 10 | test.RunCommandTestCases(t, "users", []*test.CommandTestCase{ 11 | { 12 | []string{}, 13 | nil, 14 | //configs["default"], 15 | "help", 16 | false, 17 | nil, 18 | }, 19 | { 20 | []string{"help"}, 21 | nil, 22 | //configs["default"], 23 | "help", 24 | false, 25 | nil, 26 | }, 27 | }) 28 | } 29 | -------------------------------------------------------------------------------- /cli/cmd/version_cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/spf13/cobra" 7 | ) 8 | 9 | func init() { 10 | RootCmd.AddCommand(versionCmd) 11 | } 12 | 13 | var versionCmd = &cobra.Command{ 14 | Use: "version", 15 | Aliases: []string{"v"}, 16 | Short: "Print the version number of glc", 17 | Run: func(cmd *cobra.Command, args []string) { 18 | fmt.Println("glc v0.1") 19 | }, 20 | } 21 | -------------------------------------------------------------------------------- /cli/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/plouc/go-gitlab-client/cli/cmd" 5 | ) 6 | 7 | func main() { 8 | cmd.Execute() 9 | } 10 | -------------------------------------------------------------------------------- /cli/output/commits.go: -------------------------------------------------------------------------------- 1 | package output 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | 7 | "github.com/olekukonko/tablewriter" 8 | "github.com/plouc/go-gitlab-client/gitlab" 9 | ) 10 | 11 | func Commits(w io.Writer, format string, collection *gitlab.CommitCollection) { 12 | if format == "json" { 13 | collection.RenderJson(w) 14 | } else if format == "yaml" { 15 | collection.RenderYaml(w) 16 | } else { 17 | fmt.Fprintln(w, "") 18 | table := tablewriter.NewWriter(w) 19 | table.SetHeader([]string{ 20 | "Short Id", 21 | "Author name", 22 | "Title", 23 | }) 24 | table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false}) 25 | for _, commit := range collection.Items { 26 | table.Append([]string{ 27 | commit.ShortId, 28 | commit.AuthorName, 29 | commit.Title, 30 | }) 31 | } 32 | table.Render() 33 | fmt.Fprintln(w, "") 34 | } 35 | } 36 | 37 | func MinimalCommits(w io.Writer, format string, collection *gitlab.MinimalCommitCollection) { 38 | if format == "json" { 39 | collection.RenderJson(w) 40 | } else if format == "yaml" { 41 | collection.RenderYaml(w) 42 | } else { 43 | fmt.Fprintln(w, "") 44 | table := tablewriter.NewWriter(w) 45 | table.SetHeader([]string{ 46 | "Short Id", 47 | "Author name", 48 | "Title", 49 | }) 50 | table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false}) 51 | for _, commit := range collection.Items { 52 | table.Append([]string{ 53 | commit.ShortId, 54 | commit.AuthorName, 55 | commit.Title, 56 | }) 57 | } 58 | table.Render() 59 | fmt.Fprintln(w, "") 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /cli/output/environments.go: -------------------------------------------------------------------------------- 1 | package output 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | "github.com/olekukonko/tablewriter" 8 | "github.com/plouc/go-gitlab-client/gitlab" 9 | "io" 10 | ) 11 | 12 | func Environments(w io.Writer, format string, collection *gitlab.EnvironmentCollection) { 13 | if format == "json" { 14 | collection.RenderJson(w) 15 | } else if format == "yaml" { 16 | collection.RenderYaml(w) 17 | } else { 18 | fmt.Fprintln(w, "") 19 | table := tablewriter.NewWriter(w) 20 | table.SetHeader([]string{ 21 | "Id", 22 | "Name", 23 | "Slug", 24 | "External URL", 25 | }) 26 | table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false}) 27 | for _, environment := range collection.Items { 28 | table.Append([]string{ 29 | fmt.Sprintf("%d", environment.Id), 30 | environment.Name, 31 | environment.Slug, 32 | environment.ExternalUrl, 33 | }) 34 | } 35 | table.Render() 36 | fmt.Fprintln(w, "") 37 | } 38 | } 39 | 40 | func Environment(w io.Writer, format string, environment *gitlab.Environment) { 41 | if format == "json" { 42 | environment.RenderJson(w) 43 | } else if format == "yaml" { 44 | environment.RenderYaml(w) 45 | } else { 46 | fmt.Fprintln(w, "") 47 | fmt.Fprintf(w, " Id %s\n", color.YellowString("%d", environment.Id)) 48 | fmt.Fprintf(w, " Name %s\n", color.YellowString(environment.Name)) 49 | fmt.Fprintf(w, " Slug %s\n", color.YellowString(environment.Slug)) 50 | fmt.Fprintf(w, " External URL %s\n", color.YellowString(environment.ExternalUrl)) 51 | fmt.Fprintln(w, "") 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /cli/output/members.go: -------------------------------------------------------------------------------- 1 | package output 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | 7 | "github.com/olekukonko/tablewriter" 8 | "github.com/plouc/go-gitlab-client/gitlab" 9 | ) 10 | 11 | func Members(w io.Writer, format string, collection *gitlab.MemberCollection) { 12 | if format == "json" { 13 | collection.RenderJson(w) 14 | } else if format == "yaml" { 15 | collection.RenderYaml(w) 16 | } else { 17 | fmt.Fprintln(w, "") 18 | table := tablewriter.NewWriter(w) 19 | table.SetHeader([]string{ 20 | "Id", 21 | "Username", 22 | "Name", 23 | "State", 24 | "Expires at", 25 | "Access level", 26 | "Web url", 27 | }) 28 | table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false}) 29 | for _, member := range collection.Items { 30 | table.Append([]string{ 31 | fmt.Sprintf("%d", member.Id), 32 | member.Username, 33 | member.Name, 34 | member.State, 35 | member.ExpiresAt, 36 | fmt.Sprintf("%d", member.AccessLevel), 37 | member.WebUrl, 38 | }) 39 | } 40 | table.Render() 41 | fmt.Fprintln(w, "") 42 | } 43 | } 44 | 45 | func Member(w io.Writer, format string, member *gitlab.Member) { 46 | if format == "json" { 47 | member.RenderJson(w) 48 | } else if format == "yaml" { 49 | member.RenderYaml(w) 50 | } else { 51 | // @todo 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /cli/output/output.go: -------------------------------------------------------------------------------- 1 | package output 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "fmt" 7 | 8 | "github.com/fatih/color" 9 | "github.com/plouc/go-gitlab-client/gitlab" 10 | "gopkg.in/yaml.v2" 11 | "io" 12 | ) 13 | 14 | func Meta(meta *gitlab.ResponseMeta, withPagination bool) { 15 | color.Yellow("\nResponse meta") 16 | 17 | fmt.Println("") 18 | fmt.Printf(" Method %s\n", meta.Method) 19 | fmt.Printf(" Url %s\n", meta.Url) 20 | fmt.Printf(" StatusCode %d\n", meta.StatusCode) 21 | fmt.Printf(" Request id %s\n", meta.RequestId) 22 | fmt.Printf(" Runtime %f\n", meta.Runtime) 23 | 24 | if withPagination { 25 | fmt.Printf(" Page %d\n", meta.Page) 26 | fmt.Printf(" Items per page %d\n", meta.PerPage) 27 | fmt.Printf(" Previous page %d\n", meta.PrevPage) 28 | fmt.Printf(" Next page %d\n", meta.NextPage) 29 | fmt.Printf(" Total pages %d\n", meta.TotalPages) 30 | fmt.Printf(" Total %d\n", meta.Total) 31 | } 32 | 33 | fmt.Println("") 34 | } 35 | 36 | func Json(w io.Writer, v interface{}) { 37 | j, err := json.Marshal(v) 38 | if err != nil { 39 | panic(err) 40 | } 41 | 42 | var indented bytes.Buffer 43 | json.Indent(&indented, j, "", " ") 44 | 45 | indented.WriteTo(w) 46 | } 47 | 48 | func Yaml(w io.Writer, v interface{}) { 49 | j, err := yaml.Marshal(v) 50 | if err != nil { 51 | panic(err) 52 | } 53 | 54 | w.Write(j) 55 | } 56 | -------------------------------------------------------------------------------- /cli/output/ssh_keys.go: -------------------------------------------------------------------------------- 1 | package output 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/olekukonko/tablewriter" 7 | "github.com/plouc/go-gitlab-client/gitlab" 8 | "io" 9 | ) 10 | 11 | func SshKeys(w io.Writer, format string, collection *gitlab.SshKeyCollection) { 12 | if format == "json" { 13 | collection.RenderJson(w) 14 | } else if format == "yaml" { 15 | collection.RenderYaml(w) 16 | } else { 17 | fmt.Fprintln(w, "") 18 | table := tablewriter.NewWriter(w) 19 | table.SetHeader([]string{ 20 | "Id", 21 | "Title", 22 | "Key", 23 | "Created at", 24 | }) 25 | table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false}) 26 | for _, key := range collection.Items { 27 | table.Append([]string{ 28 | fmt.Sprintf("%d", key.Id), 29 | key.Title, 30 | key.Key[:16] + "…", 31 | key.CreatedAtRaw, 32 | }) 33 | } 34 | table.Render() 35 | fmt.Fprintln(w, "") 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /cli/output/variables.go: -------------------------------------------------------------------------------- 1 | package output 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/color" 7 | "github.com/olekukonko/tablewriter" 8 | "github.com/plouc/go-gitlab-client/gitlab" 9 | "io" 10 | ) 11 | 12 | func Variables(w io.Writer, format string, collection *gitlab.VariableCollection) { 13 | if format == "json" { 14 | collection.RenderJson(w) 15 | } else if format == "yaml" { 16 | collection.RenderYaml(w) 17 | } else { 18 | fmt.Fprintln(w, "") 19 | table := tablewriter.NewWriter(w) 20 | table.SetHeader([]string{ 21 | "Key", 22 | "Value", 23 | "Protected", 24 | "Environment scope", 25 | }) 26 | table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false}) 27 | for _, variable := range collection.Items { 28 | table.Append([]string{ 29 | variable.Key, 30 | variable.Value, 31 | fmt.Sprintf("%t", variable.Protected), 32 | variable.EnvironmentScope, 33 | }) 34 | } 35 | table.Render() 36 | fmt.Fprintln(w, "") 37 | } 38 | } 39 | 40 | func Variable(w io.Writer, format string, variable *gitlab.Variable) { 41 | if format == "json" { 42 | variable.RenderJson(w) 43 | } else if format == "yaml" { 44 | variable.RenderYaml(w) 45 | } else { 46 | fmt.Fprintln(w, "") 47 | 48 | fmt.Fprintf(w, " Key %s\n", color.YellowString(variable.Key)) 49 | fmt.Fprintf(w, " Value %s\n", color.YellowString(variable.Value)) 50 | fmt.Fprintf(w, " Protected %s\n", color.YellowString("%t", variable.Protected)) 51 | fmt.Fprintf(w, " EnvironmentScope %s\n", color.YellowString(variable.EnvironmentScope)) 52 | 53 | fmt.Fprintln(w, "") 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /gitlab/badges_test.go: -------------------------------------------------------------------------------- 1 | package gitlab 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | "github.com/stretchr/testify/assert" 8 | ) 9 | 10 | func TestGitlab_ProjectBadges(t *testing.T) { 11 | ts := test.CreateMockServer(t, []string{ 12 | "badges/project_1_badges", 13 | }) 14 | defer ts.Close() 15 | gitlab := NewGitlab(ts.URL, "", "") 16 | 17 | badges, meta, err := gitlab.ProjectBadges("1", nil) 18 | 19 | assert.NoError(t, err) 20 | 21 | assert.Equal(t, 5, len(badges.Items)) 22 | 23 | assert.IsType(t, new(ResponseMeta), meta) 24 | assert.Equal(t, 1, meta.Page) 25 | assert.Equal(t, 10, meta.PerPage) 26 | } 27 | 28 | func TestGitlab_ProjectBadge(t *testing.T) { 29 | ts := test.CreateMockServer(t, []string{ 30 | "badges/project_1_badge_1", 31 | }) 32 | defer ts.Close() 33 | gitlab := NewGitlab(ts.URL, "", "") 34 | 35 | badge, meta, err := gitlab.ProjectBadge("1", 1) 36 | 37 | assert.NoError(t, err) 38 | 39 | assert.IsType(t, new(Badge), badge) 40 | assert.Equal(t, 1, badge.Id) 41 | 42 | assert.IsType(t, new(ResponseMeta), meta) 43 | } 44 | -------------------------------------------------------------------------------- /gitlab/branches_test.go: -------------------------------------------------------------------------------- 1 | package gitlab 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | "github.com/stretchr/testify/assert" 8 | ) 9 | 10 | func TestGitlab_ProjectBranches(t *testing.T) { 11 | ts := test.CreateMockServer(t, []string{ 12 | "branches/project_1_branches", 13 | }) 14 | defer ts.Close() 15 | gitlab := NewGitlab(ts.URL, "", "") 16 | 17 | c, meta, err := gitlab.ProjectBranches("1", nil) 18 | 19 | assert.NoError(t, err) 20 | 21 | assert.Equal(t, 10, len(c.Items)) 22 | 23 | assert.IsType(t, new(ResponseMeta), meta) 24 | assert.Equal(t, 1, meta.Page) 25 | assert.Equal(t, 10, meta.PerPage) 26 | } 27 | -------------------------------------------------------------------------------- /gitlab/environments_test.go: -------------------------------------------------------------------------------- 1 | package gitlab 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | "github.com/stretchr/testify/assert" 8 | ) 9 | 10 | func TestGitlab_ProjectEnvironments(t *testing.T) { 11 | ts := test.CreateMockServer(t, []string{ 12 | "environments/project_1_environments", 13 | }) 14 | defer ts.Close() 15 | gitlab := NewGitlab(ts.URL, "", "") 16 | 17 | environments, meta, err := gitlab.ProjectEnvironments("1", nil) 18 | 19 | assert.NoError(t, err) 20 | 21 | assert.Equal(t, 5, len(environments.Items)) 22 | 23 | assert.IsType(t, new(ResponseMeta), meta) 24 | assert.Equal(t, 1, meta.Page) 25 | assert.Equal(t, 10, meta.PerPage) 26 | } 27 | -------------------------------------------------------------------------------- /gitlab/gitlab_test.go: -------------------------------------------------------------------------------- 1 | package gitlab 2 | 3 | import ( 4 | "github.com/stretchr/testify/assert" 5 | "testing" 6 | ) 7 | 8 | func TestGitlab_ResourceUrl(t *testing.T) { 9 | gitlab := NewGitlab("http://base_url/", "api_path", "token") 10 | 11 | assert.Equal( 12 | t, 13 | gitlab.ResourceUrl(ProjectsApiPath, nil).String(), 14 | "http://base_url/api_path/projects", 15 | ) 16 | assert.Equal( 17 | t, 18 | gitlab.ResourceUrl(ProjectApiPath, map[string]string{":id": "123"}).String(), 19 | "http://base_url/api_path/projects/123", 20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /gitlab/members_test.go: -------------------------------------------------------------------------------- 1 | package gitlab 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | "github.com/stretchr/testify/assert" 8 | ) 9 | 10 | func TestGitlab_ProjectMembers(t *testing.T) { 11 | ts := test.CreateMockServer(t, []string{ 12 | "members/project_1_members", 13 | }) 14 | defer ts.Close() 15 | gitlab := NewGitlab(ts.URL, "", "") 16 | 17 | members, meta, err := gitlab.ProjectMembers("1", nil) 18 | 19 | assert.NoError(t, err) 20 | 21 | assert.Equal(t, 10, len(members.Items)) 22 | 23 | assert.IsType(t, new(ResponseMeta), meta) 24 | assert.Equal(t, 1, meta.Page) 25 | assert.Equal(t, 10, meta.PerPage) 26 | } 27 | 28 | func TestGitlab_GroupMembers(t *testing.T) { 29 | ts := test.CreateMockServer(t, []string{ 30 | "members/group_1_members", 31 | }) 32 | defer ts.Close() 33 | gitlab := NewGitlab(ts.URL, "", "") 34 | 35 | members, meta, err := gitlab.GroupMembers("1", nil) 36 | 37 | assert.NoError(t, err) 38 | 39 | assert.Equal(t, 10, len(members.Items)) 40 | 41 | assert.IsType(t, new(ResponseMeta), meta) 42 | assert.Equal(t, 1, meta.Page) 43 | assert.Equal(t, 10, meta.PerPage) 44 | } 45 | -------------------------------------------------------------------------------- /gitlab/milestones.go: -------------------------------------------------------------------------------- 1 | package gitlab 2 | 3 | type Milestone struct { 4 | Id int `json:"id,omitempty" yaml:"id,omitempty"` 5 | Iid int `json:"iid,omitempty" yaml:"iid,omitempty"` 6 | GroupId int `json:"group_id,omitempty" yaml:"group_id,omitempty"` 7 | ProjectId int `json:"project_id,omitempty" yaml:"project_id,omitempty"` 8 | Title string `json:"title,omitempty" yaml:"title,omitempty"` 9 | Description string `json:"description,omitempty" yaml:"description,omitempty"` 10 | State string `json:"state,omitempty" yaml:"state,omitempty"` 11 | UpdatedAt string `json:"updated_at,omitempty" yaml:"updated_at,omitempty"` 12 | CreatedAt string `json:"created_at,omitempty" yaml:"created_at,omitempty"` 13 | DueDate string `json:"due_date,omitempty" yaml:"due_date,omitempty"` 14 | StartDate string `json:"start_date,omitempty" yaml:"start_date,omitempty"` 15 | WebUrl string `json:"web_url,omitempty" yaml:"web_url,omitempty"` 16 | } 17 | -------------------------------------------------------------------------------- /gitlab/namespaces_test.go: -------------------------------------------------------------------------------- 1 | package gitlab 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | "github.com/stretchr/testify/assert" 8 | ) 9 | 10 | func TestGitlab_Namespaces(t *testing.T) { 11 | ts := test.CreateMockServer(t, []string{ 12 | "namespaces/namespaces", 13 | }) 14 | defer ts.Close() 15 | gitlab := NewGitlab(ts.URL, "", "") 16 | 17 | namespaces, meta, err := gitlab.Namespaces(nil) 18 | 19 | assert.NoError(t, err) 20 | 21 | assert.IsType(t, new(Namespace), namespaces.Items[0]) 22 | assert.Equal(t, 3, len(namespaces.Items)) 23 | assert.Equal(t, 1, namespaces.Items[0].Id) 24 | assert.Equal(t, "group1", namespaces.Items[1].Path) 25 | 26 | assert.IsType(t, new(ResponseMeta), meta) 27 | assert.Equal(t, 1, meta.Page) 28 | assert.Equal(t, 10, meta.PerPage) 29 | } 30 | 31 | func TestGitlab_SearchNamespaces(t *testing.T) { 32 | ts := test.CreateMockServer(t, []string{ 33 | "namespaces/namespaces_search", 34 | }) 35 | defer ts.Close() 36 | gitlab := NewGitlab(ts.URL, "", "") 37 | 38 | namespaces, meta, err := gitlab.Namespaces(&NamespacesOptions{ 39 | Search: "twitter", 40 | }) 41 | 42 | assert.NoError(t, err) 43 | 44 | assert.IsType(t, new(Namespace), namespaces.Items[0]) 45 | assert.Equal(t, 1, len(namespaces.Items)) 46 | assert.Equal(t, 4, namespaces.Items[0].Id) 47 | assert.Equal(t, "twitter", namespaces.Items[0].Path) 48 | 49 | assert.IsType(t, new(ResponseMeta), meta) 50 | assert.Equal(t, 1, meta.Page) 51 | assert.Equal(t, 10, meta.PerPage) 52 | } 53 | -------------------------------------------------------------------------------- /gitlab/notes_test.go: -------------------------------------------------------------------------------- 1 | package gitlab 2 | 3 | import ( 4 | "github.com/plouc/go-gitlab-client/test" 5 | "github.com/stretchr/testify/assert" 6 | "testing" 7 | ) 8 | 9 | func TestGitlab_ProjectIssueNotes(t *testing.T) { 10 | ts := test.CreateMockServerFromDir(t, "notes") 11 | defer ts.Close() 12 | gitlab := NewGitlab(ts.URL, "", "") 13 | 14 | collection, meta, err := gitlab.ProjectIssueNotes("1", 5, nil) 15 | 16 | assert.NoError(t, err) 17 | 18 | assert.Equal(t, 2, len(collection.Items)) 19 | 20 | assert.IsType(t, new(ResponseMeta), meta) 21 | assert.Equal(t, 1, meta.Page) 22 | assert.Equal(t, 10, meta.PerPage) 23 | } 24 | 25 | func TestGitlab_ProjectSnippetNotes(t *testing.T) { 26 | ts := test.CreateMockServerFromDir(t, "notes") 27 | defer ts.Close() 28 | gitlab := NewGitlab(ts.URL, "", "") 29 | 30 | collection, meta, err := gitlab.ProjectSnippetNotes("1", 7, nil) 31 | 32 | assert.NoError(t, err) 33 | 34 | assert.Equal(t, 5, len(collection.Items)) 35 | 36 | assert.IsType(t, new(ResponseMeta), meta) 37 | assert.Equal(t, 1, meta.Page) 38 | assert.Equal(t, 10, meta.PerPage) 39 | } 40 | 41 | func TestGitlab_ProjectMergeRequestNotes(t *testing.T) { 42 | ts := test.CreateMockServerFromDir(t, "notes") 43 | defer ts.Close() 44 | gitlab := NewGitlab(ts.URL, "", "") 45 | 46 | collection, meta, err := gitlab.ProjectMergeRequestNotes("1", 3, nil) 47 | 48 | assert.NoError(t, err) 49 | 50 | assert.Equal(t, 6, len(collection.Items)) 51 | 52 | assert.IsType(t, new(ResponseMeta), meta) 53 | assert.Equal(t, 1, meta.Page) 54 | assert.Equal(t, 10, meta.PerPage) 55 | } 56 | -------------------------------------------------------------------------------- /gitlab/render.go: -------------------------------------------------------------------------------- 1 | package gitlab 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "gopkg.in/yaml.v2" 7 | "io" 8 | ) 9 | 10 | type Renderable interface { 11 | RenderJson(w io.Writer) error 12 | RenderYaml(w io.Writer) error 13 | } 14 | 15 | func renderJson(w io.Writer, v interface{}) error { 16 | j, err := json.Marshal(v) 17 | if err != nil { 18 | return err 19 | } 20 | 21 | var indented bytes.Buffer 22 | err = json.Indent(&indented, j, "", " ") 23 | if err != nil { 24 | return err 25 | } 26 | 27 | _, err = indented.WriteTo(w) 28 | 29 | return err 30 | } 31 | 32 | func renderYaml(w io.Writer, v interface{}) error { 33 | j, err := yaml.Marshal(v) 34 | if err != nil { 35 | return err 36 | } 37 | 38 | w.Write(j) 39 | 40 | return nil 41 | } 42 | -------------------------------------------------------------------------------- /gitlab/ssh_keys_test.go: -------------------------------------------------------------------------------- 1 | package gitlab 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/plouc/go-gitlab-client/test" 7 | "github.com/stretchr/testify/assert" 8 | ) 9 | 10 | func TestGitlab_CurrentUserSshKeys(t *testing.T) { 11 | ts := test.CreateMockServer(t, []string{ 12 | "ssh_keys/current_user_ssh_keys", 13 | }) 14 | defer ts.Close() 15 | gitlab := NewGitlab(ts.URL, "", "") 16 | 17 | keys, meta, err := gitlab.CurrentUserSshKeys(nil) 18 | 19 | assert.NoError(t, err) 20 | 21 | assert.Equal(t, 3, len(keys.Items)) 22 | 23 | assert.IsType(t, new(ResponseMeta), meta) 24 | assert.Equal(t, 1, meta.Page) 25 | assert.Equal(t, 10, meta.PerPage) 26 | } 27 | 28 | func TestGitlab_UserSshKeys(t *testing.T) { 29 | ts := test.CreateMockServer(t, []string{ 30 | "ssh_keys/user_1_ssh_keys", 31 | }) 32 | defer ts.Close() 33 | gitlab := NewGitlab(ts.URL, "", "") 34 | 35 | keys, meta, err := gitlab.UserSshKeys(1, nil) 36 | 37 | assert.NoError(t, err) 38 | 39 | assert.Equal(t, 3, len(keys.Items)) 40 | 41 | assert.IsType(t, new(ResponseMeta), meta) 42 | assert.Equal(t, 1, meta.Page) 43 | assert.Equal(t, 10, meta.PerPage) 44 | } 45 | -------------------------------------------------------------------------------- /mocks/files/badges/badge_1.json: -------------------------------------------------------------------------------- 1 | { 2 | "link_url": "https://gitlab.com/%{project_path}/commits/%{default_branch}", 3 | "image_url": "https://gitlab.com/%{project_path}/badges/%{default_branch}/pipeline.svg", 4 | "rendered_link_url": "https://gitlab.com/gitlab-org/gitlab-ce/commits/master", 5 | "rendered_image_url": "https://gitlab.com/gitlab-org/gitlab-ce/badges/master/pipeline.svg", 6 | "id": 1, 7 | "kind": "project" 8 | } -------------------------------------------------------------------------------- /mocks/files/commits/commit.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "6104942438c14ec7bd21c6cd5bd995272b3faff6", 3 | "short_id": "6104942438c", 4 | "title": "Sanitize for network graph", 5 | "author_name": "randx", 6 | "author_email": "dmitriy.zaporozhets@gmail.com", 7 | "committer_name": "Dmitriy", 8 | "committer_email": "dmitriy.zaporozhets@gmail.com", 9 | "created_at": "2012-09-20T09:06:12+03:00", 10 | "message": "Sanitize for network graph", 11 | "committed_date": "2012-09-20T09:06:12+03:00", 12 | "authored_date": "2012-09-20T09:06:12+03:00", 13 | "parent_ids": [ 14 | "ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba" 15 | ], 16 | "last_pipeline" : { 17 | "id": 8, 18 | "ref": "master", 19 | "sha": "2dc6aa325a317eda67812f05600bdf0fcdc70ab0", 20 | "status": "created" 21 | }, 22 | "stats": { 23 | "additions": 15, 24 | "deletions": 10, 25 | "total": 25 26 | }, 27 | "status": "running" 28 | } 29 | -------------------------------------------------------------------------------- /mocks/files/commits/commit_diff.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "diff": "--- a/doc/update/5.4-to-6.0.md\n+++ b/doc/update/5.4-to-6.0.md\n@@ -71,6 +71,8 @@\n sudo -u git -H bundle exec rake migrate_keys RAILS_ENV=production\n sudo -u git -H bundle exec rake migrate_inline_notes RAILS_ENV=production\n \n+sudo -u git -H bundle exec rake gitlab:assets:compile RAILS_ENV=production\n+\n ```\n \n ### 6. Update config files", 4 | "new_path": "doc/update/5.4-to-6.0.md", 5 | "old_path": "doc/update/5.4-to-6.0.md", 6 | "a_mode": null, 7 | "b_mode": "100644", 8 | "new_file": false, 9 | "renamed_file": false, 10 | "deleted_file": false 11 | } 12 | ] -------------------------------------------------------------------------------- /mocks/files/commits/commit_refs.json: -------------------------------------------------------------------------------- 1 | [ 2 | {"type": "branch", "name": "'test'"}, 3 | {"type": "branch", "name": "add-balsamiq-file"}, 4 | {"type": "branch", "name": "wip"}, 5 | {"type": "tag", "name": "v1.1.0"} 6 | ] -------------------------------------------------------------------------------- /mocks/files/commits/commit_statuses.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "status" : "pending", 4 | "created_at" : "2016-01-19T08:40:25.934Z", 5 | "started_at" : null, 6 | "name" : "bundler:audit", 7 | "allow_failure" : true, 8 | "author" : { 9 | "username" : "thedude", 10 | "state" : "active", 11 | "web_url" : "https://gitlab.example.com/thedude", 12 | "avatar_url" : "https://gitlab.example.com/uploads/user/avatar/28/The-Big-Lebowski-400-400.png", 13 | "id" : 28, 14 | "name" : "Jeff Lebowski" 15 | }, 16 | "description" : null, 17 | "sha" : "18f3e63d05582537db6d183d9d557be09e1f90c8", 18 | "target_url" : "https://gitlab.example.com/thedude/gitlab-ce/builds/91", 19 | "finished_at" : null, 20 | "id" : 91, 21 | "ref" : "master" 22 | }, 23 | { 24 | "started_at" : null, 25 | "name" : "flay", 26 | "allow_failure" : false, 27 | "status" : "pending", 28 | "created_at" : "2016-01-19T08:40:25.832Z", 29 | "target_url" : "https://gitlab.example.com/thedude/gitlab-ce/builds/90", 30 | "id" : 90, 31 | "finished_at" : null, 32 | "ref" : "master", 33 | "sha" : "18f3e63d05582537db6d183d9d557be09e1f90c8", 34 | "author" : { 35 | "id" : 28, 36 | "name" : "Jeff Lebowski", 37 | "username" : "thedude", 38 | "web_url" : "https://gitlab.example.com/thedude", 39 | "state" : "active", 40 | "avatar_url" : "https://gitlab.example.com/uploads/user/avatar/28/The-Big-Lebowski-400-400.png" 41 | }, 42 | "description" : null 43 | } 44 | ] -------------------------------------------------------------------------------- /mocks/files/commits/commits.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "ed899a2f4b50b4370feeea94676502b42383c746", 4 | "short_id": "ed899a2f4b5", 5 | "title": "Replace sanitize with escape once", 6 | "author_name": "Dmitriy Zaporozhets", 7 | "author_email": "dzaporozhets@sphereconsultinginc.com", 8 | "authored_date": "2012-09-20T11:50:22+03:00", 9 | "committer_name": "Administrator", 10 | "committer_email": "admin@example.com", 11 | "committed_date": "2012-09-20T11:50:22+03:00", 12 | "created_at": "2012-09-20T11:50:22+03:00", 13 | "message": "Replace sanitize with escape once", 14 | "parent_ids": [ 15 | "6104942438c14ec7bd21c6cd5bd995272b3faff6" 16 | ] 17 | }, 18 | { 19 | "id": "6104942438c14ec7bd21c6cd5bd995272b3faff6", 20 | "short_id": "6104942438c", 21 | "title": "Sanitize for network graph", 22 | "author_name": "randx", 23 | "author_email": "dmitriy.zaporozhets@gmail.com", 24 | "committer_name": "Dmitriy", 25 | "committer_email": "dmitriy.zaporozhets@gmail.com", 26 | "created_at": "2012-09-20T09:06:12+03:00", 27 | "message": "Sanitize for network graph", 28 | "parent_ids": [ 29 | "ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba" 30 | ] 31 | } 32 | ] 33 | -------------------------------------------------------------------------------- /mocks/files/commits/merge_request_commits.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "ed899a2f4b50b4370feeea94676502b42383c746", 4 | "short_id": "ed899a2f4b5", 5 | "title": "Replace sanitize with escape once", 6 | "author_name": "Dmitriy Zaporozhets", 7 | "author_email": "dzaporozhets@sphereconsultinginc.com", 8 | "created_at": "2012-09-20T11:50:22+03:00", 9 | "message": "Replace sanitize with escape once" 10 | }, 11 | { 12 | "id": "6104942438c14ec7bd21c6cd5bd995272b3faff6", 13 | "short_id": "6104942438c", 14 | "title": "Sanitize for network graph", 15 | "author_name": "randx", 16 | "author_email": "dmitriy.zaporozhets@gmail.com", 17 | "created_at": "2012-09-20T09:06:12+03:00", 18 | "message": "Sanitize for network graph" 19 | } 20 | ] 21 | -------------------------------------------------------------------------------- /mocks/files/environments/environments.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": 1, 4 | "name": "dev", 5 | "slug": "dev", 6 | "external_url": "http://dev-api.fake.io" 7 | }, 8 | { 9 | "id": 2, 10 | "name": "staging", 11 | "slug": "staging", 12 | "external_url": "http://staging-api.fake.io" 13 | }, 14 | { 15 | "id": 3, 16 | "name": "prod", 17 | "slug": "prod", 18 | "external_url": "http://prod-api.fake.io" 19 | }, 20 | { 21 | "id": 4, 22 | "name": "preprod", 23 | "slug": "preprod", 24 | "external_url": null 25 | }, 26 | { 27 | "id": 5, 28 | "name": "prod", 29 | "slug": "prod", 30 | "external_url": "http://api.fake.io" 31 | } 32 | ] -------------------------------------------------------------------------------- /mocks/files/groups/groups.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": 1, 4 | "name": "Foobar Group", 5 | "path": "foo-bar", 6 | "description": "An interesting group", 7 | "visibility": "public", 8 | "lfs_enabled": true, 9 | "avatar_url": "http://localhost:3000/uploads/group/avatar/1/foo.jpg", 10 | "web_url": "http://localhost:3000/foo-bar", 11 | "request_access_enabled": false, 12 | "full_name": "Foobar Group", 13 | "full_path": "foo-bar", 14 | "parent_id": null 15 | }, 16 | { 17 | "id": 2, 18 | "name": "Another Group", 19 | "path": "another", 20 | "description": "A not so interesting group", 21 | "visibility": "public", 22 | "lfs_enabled": true, 23 | "avatar_url": "http://localhost:3000/uploads/group/avatar/1/bar.jpg", 24 | "web_url": "http://localhost:3000/foo-bar/another", 25 | "request_access_enabled": false, 26 | "full_name": "Another Group", 27 | "full_path": "foo-bar/another", 28 | "parent_id": 1 29 | } 30 | ] 31 | -------------------------------------------------------------------------------- /mocks/files/namespaces/namespaces.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": 1, 4 | "path": "user1", 5 | "kind": "user" 6 | }, 7 | { 8 | "id": 2, 9 | "path": "group1", 10 | "kind": "group" 11 | }, 12 | { 13 | "id": 3, 14 | "path": "bar", 15 | "kind": "group", 16 | "full_path": "foo/bar" 17 | } 18 | ] 19 | -------------------------------------------------------------------------------- /mocks/files/namespaces/namespaces_search.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": 4, 4 | "path": "twitter", 5 | "kind": "group", 6 | "full_path": "twitter" 7 | } 8 | ] 9 | -------------------------------------------------------------------------------- /mocks/files/notes/issue_notes.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": 302, 4 | "body": "closed", 5 | "attachment": null, 6 | "author": { 7 | "id": 1, 8 | "username": "pipin", 9 | "email": "admin@example.com", 10 | "name": "Pip", 11 | "state": "active", 12 | "created_at": "2013-09-30T13:46:01Z" 13 | }, 14 | "created_at": "2013-10-02T09:22:45Z", 15 | "updated_at": "2013-10-02T10:22:45Z", 16 | "system": true, 17 | "noteable_id": 377, 18 | "noteable_type": "Issue", 19 | "noteable_iid": 377, 20 | "resolvable": false 21 | }, 22 | { 23 | "id": 305, 24 | "body": "Text of the comment\r\n", 25 | "attachment": null, 26 | "author": { 27 | "id": 1, 28 | "username": "pipin", 29 | "email": "admin@example.com", 30 | "name": "Pip", 31 | "state": "active", 32 | "created_at": "2013-09-30T13:46:01Z" 33 | }, 34 | "created_at": "2013-10-02T09:56:03Z", 35 | "updated_at": "2013-10-02T09:56:03Z", 36 | "system": true, 37 | "noteable_id": 121, 38 | "noteable_type": "Issue", 39 | "noteable_iid": 121, 40 | "resolvable": false 41 | } 42 | ] -------------------------------------------------------------------------------- /mocks/files/runners/runners.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "active": true, 4 | "description": "test-1-20150125", 5 | "id": 6, 6 | "is_shared": false, 7 | "name": null 8 | }, 9 | { 10 | "active": true, 11 | "description": "test-2-20150125", 12 | "id": 8, 13 | "is_shared": false, 14 | "name": null 15 | } 16 | ] 17 | -------------------------------------------------------------------------------- /mocks/files/ssh_keys/ssh_keys.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": 1, 4 | "title": "Public key", 5 | "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=", 6 | "created_at": "2014-08-01T14:47:39.080Z" 7 | }, 8 | { 9 | "id": 2, 10 | "title": "Whatever key", 11 | "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=", 12 | "created_at": "2014-08-01T14:47:39.080Z" 13 | }, 14 | { 15 | "id": 3, 16 | "title": "Another Public key", 17 | "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=", 18 | "created_at": "2014-08-01T14:47:39.080Z" 19 | } 20 | ] -------------------------------------------------------------------------------- /mocks/files/users/user_1.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": 1, 3 | "username": "plouc", 4 | "email": "plouc@plouc.com", 5 | "name": "Raphaël Benitte", 6 | "bio": null, 7 | "skype": "", 8 | "linkedin": "", 9 | "twitter": "", 10 | "theme_id": 2, 11 | "state": "active", 12 | "created_at": "2001-01-01T00:00:00Z", 13 | "extern_uid": "uid=plouc", 14 | "provider": "ldap" 15 | } -------------------------------------------------------------------------------- /mocks/files/users/users.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": 1, 4 | "username": "john_smith", 5 | "email": "john@example.com", 6 | "name": "John Smith", 7 | "state": "active", 8 | "created_at": "2012-05-23T08:00:58Z", 9 | "bio": null, 10 | "skype": "", 11 | "linkedin": "", 12 | "twitter": "", 13 | "website_url": "", 14 | "extern_uid": "john.smith", 15 | "provider": "provider_name", 16 | "theme_id": 1, 17 | "color_scheme_id": 2, 18 | "is_admin": false, 19 | "can_create_group": true 20 | }, 21 | { 22 | "id": 2, 23 | "username": "jack_smith", 24 | "email": "jack@example.com", 25 | "name": "Jack Smith", 26 | "state": "blocked", 27 | "created_at": "2012-05-23T08:01:01Z", 28 | "bio": null, 29 | "skype": "", 30 | "linkedin": "", 31 | "twitter": "", 32 | "website_url": "", 33 | "extern_uid": "jack.smith", 34 | "provider": "provider_name", 35 | "theme_id": 1, 36 | "color_scheme_id": 3, 37 | "is_admin": false, 38 | "can_create_group": true, 39 | "can_create_project": true 40 | } 41 | ] -------------------------------------------------------------------------------- /mocks/mappings/badges/project_1_badge_1.json: -------------------------------------------------------------------------------- 1 | { 2 | "request": { 3 | "path": "/api/v4/projects/1/badges/1", 4 | "method": "GET" 5 | }, 6 | "response": { 7 | "status": 200, 8 | "bodyFileName": "badges/badge_1.json", 9 | "headers": { 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /mocks/mappings/badges/project_1_badges.json: -------------------------------------------------------------------------------- 1 | { 2 | "request": { 3 | "path": "/api/v4/projects/1/badges", 4 | "method": "GET" 5 | }, 6 | "response": { 7 | "status": 200, 8 | "bodyFileName": "badges/badges.json", 9 | "headers": { 10 | "X-Page": "1", 11 | "X-Per-Page": "10" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mocks/mappings/branches/project_1_branches.json: -------------------------------------------------------------------------------- 1 | { 2 | "request": { 3 | "path": "/api/v4/projects/1/repository/branches", 4 | "method": "GET" 5 | }, 6 | "response": { 7 | "status": 200, 8 | "bodyFileName": "branches/branches.json", 9 | "headers": { 10 | "X-Page": "1", 11 | "X-Per-Page": "10" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mocks/mappings/commits/project_1_commit_6104942438c14ec7bd21c6cd5bd995272b3faff6.json: -------------------------------------------------------------------------------- 1 | { 2 | "request": { 3 | "path": "/api/v4/projects/1/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6", 4 | "method": "GET" 5 | }, 6 | "response": { 7 | "status": 200, 8 | "bodyFileName": "commits/commit.json", 9 | "headers": { 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /mocks/mappings/commits/project_1_commits.json: -------------------------------------------------------------------------------- 1 | { 2 | "request": { 3 | "path": "/api/v4/projects/1/repository/commits", 4 | "method": "GET" 5 | }, 6 | "response": { 7 | "status": 200, 8 | "bodyFileName": "commits/commits.json", 9 | "headers": { 10 | "X-Page": "1", 11 | "X-Per-Page": "10" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mocks/mappings/commits/project_1_merge_request_1_commits.json: -------------------------------------------------------------------------------- 1 | { 2 | "request": { 3 | "path": "/api/v4/projects/1/merge_requests/1/commits", 4 | "method": "GET" 5 | }, 6 | "response": { 7 | "status": 200, 8 | "bodyFileName": "commits/merge_request_commits.json", 9 | "headers": { 10 | "X-Page": "1", 11 | "X-Per-Page": "10" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mocks/mappings/environments/project_1_environments.json: -------------------------------------------------------------------------------- 1 | { 2 | "request": { 3 | "path": "/api/v4/projects/1/environments", 4 | "method": "GET" 5 | }, 6 | "response": { 7 | "status": 200, 8 | "bodyFileName": "environments/environments.json", 9 | "headers": { 10 | "X-Page": "1", 11 | "X-Per-Page": "10" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mocks/mappings/groups/groups.json: -------------------------------------------------------------------------------- 1 | { 2 | "request": { 3 | "path": "/api/v4/groups", 4 | "method": "GET" 5 | }, 6 | "response": { 7 | "status": 200, 8 | "bodyFileName": "groups/groups.json", 9 | "headers": { 10 | "X-Page": "1", 11 | "X-Per-Page": "10" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mocks/mappings/members/group_1_members.json: -------------------------------------------------------------------------------- 1 | { 2 | "request": { 3 | "path": "/api/v4/groups/1/members", 4 | "method": "GET" 5 | }, 6 | "response": { 7 | "status": 200, 8 | "bodyFileName": "members/members.json", 9 | "headers": { 10 | "X-Page": "1", 11 | "X-Per-Page": "10" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mocks/mappings/members/project_1_members.json: -------------------------------------------------------------------------------- 1 | { 2 | "request": { 3 | "path": "/api/v4/projects/1/members", 4 | "method": "GET" 5 | }, 6 | "response": { 7 | "status": 200, 8 | "bodyFileName": "members/members.json", 9 | "headers": { 10 | "X-Page": "1", 11 | "X-Per-Page": "10" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mocks/mappings/merge_requests/group_merge_requests.json: -------------------------------------------------------------------------------- 1 | { 2 | "request": { 3 | "path": "/api/v4/groups/1/merge_requests", 4 | "method": "GET" 5 | }, 6 | "response": { 7 | "status": 200, 8 | "bodyFileName": "merge_requests/merge_requests.json", 9 | "headers": { 10 | "X-Page": "1", 11 | "X-Per-Page": "10" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mocks/mappings/merge_requests/merge_requests.json: -------------------------------------------------------------------------------- 1 | { 2 | "request": { 3 | "path": "/api/v4/merge_requests", 4 | "method": "GET" 5 | }, 6 | "response": { 7 | "status": 200, 8 | "bodyFileName": "merge_requests/merge_requests.json", 9 | "headers": { 10 | "X-Page": "1", 11 | "X-Per-Page": "10" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mocks/mappings/merge_requests/project_1_merge_request_1.json: -------------------------------------------------------------------------------- 1 | { 2 | "request": { 3 | "path": "/api/v4/projects/1/merge_requests/1", 4 | "method": "GET" 5 | }, 6 | "response": { 7 | "status": 200, 8 | "bodyFileName": "merge_requests/merge_request.json", 9 | "headers": { 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /mocks/mappings/merge_requests/project_merge_requests.json: -------------------------------------------------------------------------------- 1 | { 2 | "request": { 3 | "path": "/api/v4/projects/1/merge_requests", 4 | "method": "GET" 5 | }, 6 | "response": { 7 | "status": 200, 8 | "bodyFileName": "merge_requests/merge_requests.json", 9 | "headers": { 10 | "X-Page": "1", 11 | "X-Per-Page": "10" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mocks/mappings/namespaces/namespaces.json: -------------------------------------------------------------------------------- 1 | { 2 | "request": { 3 | "path": "/api/v4/namespaces", 4 | "method": "GET" 5 | }, 6 | "response": { 7 | "status": 200, 8 | "bodyFileName": "namespaces/namespaces.json", 9 | "headers": { 10 | "X-Page": "1", 11 | "X-Per-Page": "10" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mocks/mappings/namespaces/namespaces_search.json: -------------------------------------------------------------------------------- 1 | { 2 | "request": { 3 | "path": "/api/v4/namespaces", 4 | "method": "GET", 5 | "query": { 6 | "search": "twitter" 7 | } 8 | }, 9 | "response": { 10 | "status": 200, 11 | "bodyFileName": "namespaces/namespaces_search.json", 12 | "headers": { 13 | "X-Page": "1", 14 | "X-Per-Page": "10" 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mocks/mappings/notes/project_1_issue_5_notes.json: -------------------------------------------------------------------------------- 1 | { 2 | "request": { 3 | "path": "/api/v4/projects/1/issues/5/notes", 4 | "method": "GET" 5 | }, 6 | "response": { 7 | "status": 200, 8 | "bodyFileName": "notes/issue_notes.json", 9 | "headers": { 10 | "X-Page": "1", 11 | "X-Per-Page": "10" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mocks/mappings/notes/project_1_merge_request_3_notes.json: -------------------------------------------------------------------------------- 1 | { 2 | "request": { 3 | "path": "/api/v4/projects/1/merge_requests/3/notes", 4 | "method": "GET" 5 | }, 6 | "response": { 7 | "status": 200, 8 | "bodyFileName": "notes/merge_request_notes.json", 9 | "headers": { 10 | "X-Page": "1", 11 | "X-Per-Page": "10" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mocks/mappings/notes/project_1_snippet_7_notes.json: -------------------------------------------------------------------------------- 1 | { 2 | "request": { 3 | "path": "/api/v4/projects/1/snippets/7/notes", 4 | "method": "GET" 5 | }, 6 | "response": { 7 | "status": 200, 8 | "bodyFileName": "notes/snippet_notes.json", 9 | "headers": { 10 | "X-Page": "1", 11 | "X-Per-Page": "10" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mocks/mappings/projects/projects.json: -------------------------------------------------------------------------------- 1 | { 2 | "request": { 3 | "path": "/api/v4/projects", 4 | "method": "GET" 5 | }, 6 | "response": { 7 | "status": 200, 8 | "bodyFileName": "projects/projects.json", 9 | "headers": { 10 | "X-Page": "1", 11 | "X-Per-Page": "10" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mocks/mappings/runners/runners.json: -------------------------------------------------------------------------------- 1 | { 2 | "request": { 3 | "path": "/api/v4/runners", 4 | "method": "GET" 5 | }, 6 | "response": { 7 | "status": 200, 8 | "bodyFileName": "runners/runners.json", 9 | "headers": { 10 | "X-Page": "1", 11 | "X-Per-Page": "10" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mocks/mappings/ssh_keys/current_user_ssh_keys.json: -------------------------------------------------------------------------------- 1 | { 2 | "request": { 3 | "path": "/api/v4/user/keys", 4 | "method": "GET" 5 | }, 6 | "response": { 7 | "status": 200, 8 | "bodyFileName": "ssh_keys/ssh_keys.json", 9 | "headers": { 10 | "X-Page": "1", 11 | "X-Per-Page": "10" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mocks/mappings/ssh_keys/user_1_ssh_keys.json: -------------------------------------------------------------------------------- 1 | { 2 | "request": { 3 | "path": "/api/v4/users/1/keys", 4 | "method": "GET" 5 | }, 6 | "response": { 7 | "status": 200, 8 | "bodyFileName": "ssh_keys/ssh_keys.json", 9 | "headers": { 10 | "X-Page": "1", 11 | "X-Per-Page": "10" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mocks/mappings/users/user_1.json: -------------------------------------------------------------------------------- 1 | { 2 | "request": { 3 | "path": "/api/v4/users/1", 4 | "method": "GET" 5 | }, 6 | "response": { 7 | "status": 200, 8 | "bodyFileName": "users/user_1.json", 9 | "headers": { 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /mocks/mappings/users/users.json: -------------------------------------------------------------------------------- 1 | { 2 | "request": { 3 | "path": "/api/v4/users", 4 | "method": "GET" 5 | }, 6 | "response": { 7 | "status": 200, 8 | "bodyFileName": "users/users.json", 9 | "headers": { 10 | "X-Page": "1", 11 | "X-Per-Page": "10" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /snapshots/get_project_merge_request.snap: -------------------------------------------------------------------------------- 1 | Fetching project merge request (project id: 1, merge request iid: 1)… 2 | 3 | Id 1 4 | Iid 1 5 | Sha 8888888888888888888888888888888888888888 6 | Title test1 7 | SourceBranch test1 8 | TargetBranch master 9 | State merged 10 | MergeStatus can_be_merged 11 | 12 | -------------------------------------------------------------------------------- /snapshots/get_project_merge_request_help.snap: -------------------------------------------------------------------------------- 1 | Get project merge request info 2 | 3 | Usage: 4 | glc get project-merge-request PROJECT_ID MERGE_REQUEST_IID [flags] 5 | 6 | Aliases: 7 | project-merge-request, project-mr, pmr 8 | 9 | Flags: 10 | -h, --help help for project-merge-request 11 | 12 | Global Flags: 13 | -a, --alias string Use resource alias 14 | -c, --config string Path to configuration file (default ".glc.yml") 15 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 16 | --no-color disable color output 17 | -o, --output-destination string Output result to file if specified 18 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 19 | --silent silent mode 20 | -v, --verbose verbose output 21 | -------------------------------------------------------------------------------- /snapshots/get_project_merge_request_no_arg.snap: -------------------------------------------------------------------------------- 1 | Error: ✘ 2 argument(s) required for project-merge-request resource but got 0: 2 | - project_id 3 | - merge_request_iid 4 | 5 | Usage: 6 | glc get project-merge-request PROJECT_ID MERGE_REQUEST_IID [flags] 7 | 8 | Aliases: 9 | project-merge-request, project-mr, pmr 10 | 11 | Flags: 12 | -h, --help help for project-merge-request 13 | 14 | Global Flags: 15 | -a, --alias string Use resource alias 16 | -c, --config string Path to configuration file (default ".glc.yml") 17 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 18 | --no-color disable color output 19 | -o, --output-destination string Output result to file if specified 20 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 21 | --silent silent mode 22 | -v, --verbose verbose output 23 | 24 | ✘ 2 argument(s) required for project-merge-request resource but got 0: 25 | - project_id 26 | - merge_request_iid 27 | 28 | -------------------------------------------------------------------------------- /snapshots/get_project_merge_request_no_merge_request_iid.snap: -------------------------------------------------------------------------------- 1 | Error: ✘ 2 argument(s) required for project-merge-request resource but got 1: 2 | - project_id 3 | - merge_request_iid 4 | 5 | Usage: 6 | glc get project-merge-request PROJECT_ID MERGE_REQUEST_IID [flags] 7 | 8 | Aliases: 9 | project-merge-request, project-mr, pmr 10 | 11 | Flags: 12 | -h, --help help for project-merge-request 13 | 14 | Global Flags: 15 | -a, --alias string Use resource alias 16 | -c, --config string Path to configuration file (default ".glc.yml") 17 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 18 | --no-color disable color output 19 | -o, --output-destination string Output result to file if specified 20 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 21 | --silent silent mode 22 | -v, --verbose verbose output 23 | 24 | ✘ 2 argument(s) required for project-merge-request resource but got 1: 25 | - project_id 26 | - merge_request_iid 27 | 28 | -------------------------------------------------------------------------------- /snapshots/get_project_merge_request_verbose.snap: -------------------------------------------------------------------------------- 1 | Fetching project merge request (project id: 1, merge request iid: 1)… 2 | 3 | Id 1 4 | Iid 1 5 | Sha 8888888888888888888888888888888888888888 6 | Title test1 7 | SourceBranch test1 8 | TargetBranch master 9 | State merged 10 | MergeStatus can_be_merged 11 | 12 | 13 | Response meta 14 | 15 | Method GET 16 | Url http://wiremock:8080/api/v4/projects/1/merge_requests/1 17 | StatusCode 200 18 | Request id 19 | Runtime 0.000000 20 | 21 | -------------------------------------------------------------------------------- /snapshots/get_project_merge_request_yaml.snap: -------------------------------------------------------------------------------- 1 | Fetching project merge request (project id: 1, merge request iid: 1)… 2 | id: 1 3 | iid: 1 4 | project_id: 3 5 | web_url: http://example.com/example/example/merge_requests/1 6 | title: test1 7 | description: fixed login page css paddings 8 | state: merged 9 | created_at: "2017-04-29T08:46:00Z" 10 | updated_at: "2017-04-29T08:46:00Z" 11 | source_branch: test1 12 | target_branch: master 13 | source_project_id: 2 14 | target_project_id: 3 15 | sha: "8888888888888888888888888888888888888888" 16 | merge_commit_sha: "9999999999999999999999999999999999999999" 17 | merge_status: can_be_merged 18 | merge_when_pipeline_succeeds: true 19 | should_remove_source_branch: true 20 | user_notes_count: 1 21 | pipeline: 22 | id: 8 23 | status: created 24 | ref: master 25 | sha: 2dc6aa325a317eda67812f05600bdf0fcdc70ab0 26 | author: 27 | id: 1 28 | username: root 29 | name: Administrator 30 | state: active 31 | web_url: https://gitlab.example.com/root 32 | assignee: 33 | id: 1 34 | username: root 35 | name: Administrator 36 | state: active 37 | web_url: https://gitlab.example.com/root 38 | time_stats: {} 39 | milestone: 40 | id: 5 41 | iid: 1 42 | project_id: 3 43 | title: v2.0 44 | description: Assumenda aut placeat expedita exercitationem labore sunt enim earum. 45 | state: closed 46 | updated_at: "2015-02-02T19:49:26.013Z" 47 | created_at: "2015-02-02T19:49:26.013Z" 48 | -------------------------------------------------------------------------------- /snapshots/get_user.snap: -------------------------------------------------------------------------------- 1 | Fetching user (id: 1)… 2 | 3 | Basic info 4 | Id 1 5 | Username plouc 6 | Email plouc@plouc.com 7 | Name Raphaël Benitte 8 | State active 9 | 10 | Rights 11 | IsAdmin false 12 | CanCreateGroup false 13 | CanCreateProject false 14 | ProjectsLimit 0 15 | 16 | Security 17 | External false 18 | TwoFactorEnabled false 19 | Identities 20 | 21 | -------------------------------------------------------------------------------- /snapshots/get_user_help.snap: -------------------------------------------------------------------------------- 1 | Get a single user 2 | 3 | Usage: 4 | glc get user USER_ID [flags] 5 | 6 | Aliases: 7 | user, u 8 | 9 | Flags: 10 | -h, --help help for user 11 | 12 | Global Flags: 13 | -a, --alias string Use resource alias 14 | -c, --config string Path to configuration file (default ".glc.yml") 15 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 16 | --no-color disable color output 17 | -o, --output-destination string Output result to file if specified 18 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 19 | --silent silent mode 20 | -v, --verbose verbose output 21 | -------------------------------------------------------------------------------- /snapshots/get_user_json.snap: -------------------------------------------------------------------------------- 1 | Fetching user (id: 1)… 2 | { 3 | "id": 1, 4 | "username": "plouc", 5 | "email": "plouc@plouc.com", 6 | "name": "Raphaël Benitte", 7 | "state": "active", 8 | "web_url": "", 9 | "created_at": "2001-01-01T00:00:00Z", 10 | "website_url": "", 11 | "organization": "", 12 | "theme_id": 2 13 | } -------------------------------------------------------------------------------- /snapshots/get_user_no_arg.snap: -------------------------------------------------------------------------------- 1 | Error: ✘ 1 argument(s) required for user resource but got 0: 2 | - user_id 3 | 4 | Usage: 5 | glc get user USER_ID [flags] 6 | 7 | Aliases: 8 | user, u 9 | 10 | Flags: 11 | -h, --help help for user 12 | 13 | Global Flags: 14 | -a, --alias string Use resource alias 15 | -c, --config string Path to configuration file (default ".glc.yml") 16 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 17 | --no-color disable color output 18 | -o, --output-destination string Output result to file if specified 19 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 20 | --silent silent mode 21 | -v, --verbose verbose output 22 | 23 | ✘ 1 argument(s) required for user resource but got 0: 24 | - user_id 25 | 26 | -------------------------------------------------------------------------------- /snapshots/get_user_verbose.snap: -------------------------------------------------------------------------------- 1 | Fetching user (id: 1)… 2 | 3 | Basic info 4 | Id 1 5 | Username plouc 6 | Email plouc@plouc.com 7 | Name Raphaël Benitte 8 | State active 9 | 10 | Rights 11 | IsAdmin false 12 | CanCreateGroup false 13 | CanCreateProject false 14 | ProjectsLimit 0 15 | 16 | Security 17 | External false 18 | TwoFactorEnabled false 19 | Identities 20 | 21 | 22 | Response meta 23 | 24 | Method GET 25 | Url http://wiremock:8080/api/v4/users/1 26 | StatusCode 200 27 | Request id 28 | Runtime 0.000000 29 | 30 | Related commands: 31 | 32 | - List specific user ssh keys glc ls user-ssh-keys 1 33 | 34 | -------------------------------------------------------------------------------- /snapshots/get_user_yaml.snap: -------------------------------------------------------------------------------- 1 | Fetching user (id: 1)… 2 | id: 1 3 | username: plouc 4 | email: plouc@plouc.com 5 | name: Raphaël Benitte 6 | state: active 7 | web_url: "" 8 | created_at: "2001-01-01T00:00:00Z" 9 | website_url: "" 10 | organization: "" 11 | theme_id: 2 12 | -------------------------------------------------------------------------------- /snapshots/help.snap: -------------------------------------------------------------------------------- 1 | gitlab Command Line Application 2 | 3 | Usage: 4 | glc [command] 5 | 6 | Available Commands: 7 | add Add resource 8 | ci-info Print information about CI environment 9 | completion Output shell completion code for the specified shell (bash or zsh) 10 | doc Generate CLI documentation in markdown format 11 | get Get resource details 12 | help Help about any command 13 | init Init glc config 14 | list List resource 15 | rm Remove resource 16 | version Print the version number of glc 17 | 18 | Flags: 19 | -a, --alias string Use resource alias 20 | -c, --config string Path to configuration file (default ".glc.yml") 21 | -h, --help help for glc 22 | --host string GitLab host 23 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 24 | --no-color disable color output 25 | -o, --output-destination string Output result to file if specified 26 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 27 | --silent silent mode 28 | -v, --verbose verbose output 29 | 30 | Use "glc [command] --help" for more information about a command. 31 | -------------------------------------------------------------------------------- /snapshots/list_group_merge_requests_help.snap: -------------------------------------------------------------------------------- 1 | List group merge requests 2 | 3 | Usage: 4 | glc list group-merge-requests GROUP_ID [flags] 5 | 6 | Aliases: 7 | group-merge-requests, gmr 8 | 9 | Flags: 10 | -h, --help help for group-merge-requests 11 | 12 | Global Flags: 13 | -a, --alias string Use resource alias 14 | -c, --config string Path to configuration file (default ".glc.yml") 15 | --host string GitLab host 16 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 17 | --no-color disable color output 18 | -o, --output-destination string Output result to file if specified 19 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 20 | -p, --page int Page (default 1) 21 | -l, --per-page int Items per page (default 10) 22 | --silent silent mode 23 | -v, --verbose verbose output 24 | -------------------------------------------------------------------------------- /snapshots/list_groups.snap: -------------------------------------------------------------------------------- 1 | Fetching groups… 2 | 3 | | ID | NAME | PATH | VISIBILITY | 4 | +----+---------------+---------+------------+ 5 | | 1 | Foobar Group | foo-bar | public | 6 | | 2 | Another Group | another | public | 7 | 8 | -------------------------------------------------------------------------------- /snapshots/list_groups_help.snap: -------------------------------------------------------------------------------- 1 | List groups 2 | 3 | Usage: 4 | glc list groups [flags] 5 | 6 | Aliases: 7 | groups, g 8 | 9 | Flags: 10 | --all Show all the groups you have access to (defaults to false for authenticated users, true for admin) 11 | -h, --help help for groups 12 | --owned Limit to groups owned by the current user 13 | -s, --search string Return the list of authorized groups matching the search criteria 14 | --statistics Include group statistics (admins only) 15 | -x, --with-custom-attributes Include custom attributes in response (admins only) 16 | 17 | Global Flags: 18 | -a, --alias string Use resource alias 19 | -c, --config string Path to configuration file (default ".glc.yml") 20 | --host string GitLab host 21 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 22 | --no-color disable color output 23 | -o, --output-destination string Output result to file if specified 24 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 25 | -p, --page int Page (default 1) 26 | -l, --per-page int Items per page (default 10) 27 | --silent silent mode 28 | -v, --verbose verbose output 29 | -------------------------------------------------------------------------------- /snapshots/list_groups_json.snap: -------------------------------------------------------------------------------- 1 | Fetching groups… 2 | [ 3 | { 4 | "id": 1, 5 | "name": "Foobar Group", 6 | "path": "foo-bar", 7 | "description": "An interesting group", 8 | "visibility": "public", 9 | "lfs_enabled": true, 10 | "request_access_enabled": false, 11 | "parent_id": 0, 12 | "shared_runners_minutes_limit": 0, 13 | "avatar_url": "http://localhost:3000/uploads/group/avatar/1/foo.jpg", 14 | "web_url": "http://localhost:3000/foo-bar", 15 | "full_name": "Foobar Group", 16 | "full_path": "foo-bar" 17 | }, 18 | { 19 | "id": 2, 20 | "name": "Another Group", 21 | "path": "another", 22 | "description": "A not so interesting group", 23 | "visibility": "public", 24 | "lfs_enabled": true, 25 | "request_access_enabled": false, 26 | "parent_id": 1, 27 | "shared_runners_minutes_limit": 0, 28 | "avatar_url": "http://localhost:3000/uploads/group/avatar/1/bar.jpg", 29 | "web_url": "http://localhost:3000/foo-bar/another", 30 | "full_name": "Another Group", 31 | "full_path": "foo-bar/another" 32 | } 33 | ] -------------------------------------------------------------------------------- /snapshots/list_groups_yaml.snap: -------------------------------------------------------------------------------- 1 | Fetching groups… 2 | - id: 1 3 | name: Foobar Group 4 | path: foo-bar 5 | description: An interesting group 6 | visibility: public 7 | lfs_enabled: true 8 | request_access_enabled: false 9 | parent_id: 0 10 | shared_runners_minutes_limit: 0 11 | avatar_url: http://localhost:3000/uploads/group/avatar/1/foo.jpg 12 | web_url: http://localhost:3000/foo-bar 13 | full_name: Foobar Group 14 | full_path: foo-bar 15 | - id: 2 16 | name: Another Group 17 | path: another 18 | description: A not so interesting group 19 | visibility: public 20 | lfs_enabled: true 21 | request_access_enabled: false 22 | parent_id: 1 23 | shared_runners_minutes_limit: 0 24 | avatar_url: http://localhost:3000/uploads/group/avatar/1/bar.jpg 25 | web_url: http://localhost:3000/foo-bar/another 26 | full_name: Another Group 27 | full_path: foo-bar/another 28 | -------------------------------------------------------------------------------- /snapshots/list_merge_requests_help.snap: -------------------------------------------------------------------------------- 1 | List merge requests 2 | 3 | Usage: 4 | glc list merge-requests [flags] 5 | 6 | Aliases: 7 | merge-requests, mr 8 | 9 | Flags: 10 | -h, --help help for merge-requests 11 | 12 | Global Flags: 13 | -a, --alias string Use resource alias 14 | -c, --config string Path to configuration file (default ".glc.yml") 15 | --host string GitLab host 16 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 17 | --no-color disable color output 18 | -o, --output-destination string Output result to file if specified 19 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 20 | -p, --page int Page (default 1) 21 | -l, --per-page int Items per page (default 10) 22 | --silent silent mode 23 | -v, --verbose verbose output 24 | -------------------------------------------------------------------------------- /snapshots/list_namespaces.snap: -------------------------------------------------------------------------------- 1 | Fetching namespaces… 2 | 3 | | ID | NAME | PATH | KIND | FULL PATH | 4 | +----+------+--------+-------+-----------+ 5 | | 1 | | user1 | user | | 6 | | 2 | | group1 | group | | 7 | | 3 | | bar | group | foo/bar | 8 | 9 | -------------------------------------------------------------------------------- /snapshots/list_namespaces_help.snap: -------------------------------------------------------------------------------- 1 | List namespaces 2 | 3 | Usage: 4 | glc list namespaces [flags] 5 | 6 | Aliases: 7 | namespaces, ns 8 | 9 | Flags: 10 | -h, --help help for namespaces 11 | -s, --search string Returns a list of namespaces the user is authorized to see based on the search criteria 12 | 13 | Global Flags: 14 | -a, --alias string Use resource alias 15 | -c, --config string Path to configuration file (default ".glc.yml") 16 | --host string GitLab host 17 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 18 | --no-color disable color output 19 | -o, --output-destination string Output result to file if specified 20 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 21 | -p, --page int Page (default 1) 22 | -l, --per-page int Items per page (default 10) 23 | --silent silent mode 24 | -v, --verbose verbose output 25 | -------------------------------------------------------------------------------- /snapshots/list_namespaces_json.snap: -------------------------------------------------------------------------------- 1 | Fetching namespaces… 2 | [ 3 | { 4 | "id": 1, 5 | "path": "user1", 6 | "kind": "user" 7 | }, 8 | { 9 | "id": 2, 10 | "path": "group1", 11 | "kind": "group" 12 | }, 13 | { 14 | "id": 3, 15 | "path": "bar", 16 | "kind": "group", 17 | "full_path": "foo/bar" 18 | } 19 | ] -------------------------------------------------------------------------------- /snapshots/list_namespaces_search.snap: -------------------------------------------------------------------------------- 1 | Fetching namespaces… 2 | 3 | | ID | NAME | PATH | KIND | FULL PATH | 4 | +----+------+--------+-------+-----------+ 5 | | 1 | | user1 | user | | 6 | | 2 | | group1 | group | | 7 | | 3 | | bar | group | foo/bar | 8 | 9 | -------------------------------------------------------------------------------- /snapshots/list_namespaces_yaml.snap: -------------------------------------------------------------------------------- 1 | Fetching namespaces… 2 | - id: 1 3 | path: user1 4 | kind: user 5 | - id: 2 6 | path: group1 7 | kind: group 8 | - id: 3 9 | path: bar 10 | kind: group 11 | full_path: foo/bar 12 | -------------------------------------------------------------------------------- /snapshots/list_project_environments.snap: -------------------------------------------------------------------------------- 1 | Fetching project environments (project id: 1)… 2 | 3 | | ID | NAME | SLUG | EXTERNAL URL | 4 | +----+---------+---------+----------------------------+ 5 | | 1 | dev | dev | http://dev-api.fake.io | 6 | | 2 | staging | staging | http://staging-api.fake.io | 7 | | 3 | prod | prod | http://prod-api.fake.io | 8 | | 4 | preprod | preprod | | 9 | | 5 | prod | prod | http://api.fake.io | 10 | 11 | -------------------------------------------------------------------------------- /snapshots/list_project_environments_help.snap: -------------------------------------------------------------------------------- 1 | List project environments 2 | 3 | Usage: 4 | glc list project-environments PROJECT_ID [flags] 5 | 6 | Aliases: 7 | project-environments, project-envs, pe 8 | 9 | Flags: 10 | -h, --help help for project-environments 11 | 12 | Global Flags: 13 | -a, --alias string Use resource alias 14 | -c, --config string Path to configuration file (default ".glc.yml") 15 | --host string GitLab host 16 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 17 | --no-color disable color output 18 | -o, --output-destination string Output result to file if specified 19 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 20 | -p, --page int Page (default 1) 21 | -l, --per-page int Items per page (default 10) 22 | --silent silent mode 23 | -v, --verbose verbose output 24 | -------------------------------------------------------------------------------- /snapshots/list_project_environments_json.snap: -------------------------------------------------------------------------------- 1 | Fetching project environments (project id: 1)… 2 | [ 3 | { 4 | "id": 1, 5 | "name": "dev", 6 | "external_url": "http://dev-api.fake.io", 7 | "slug": "dev" 8 | }, 9 | { 10 | "id": 2, 11 | "name": "staging", 12 | "external_url": "http://staging-api.fake.io", 13 | "slug": "staging" 14 | }, 15 | { 16 | "id": 3, 17 | "name": "prod", 18 | "external_url": "http://prod-api.fake.io", 19 | "slug": "prod" 20 | }, 21 | { 22 | "id": 4, 23 | "name": "preprod", 24 | "slug": "preprod" 25 | }, 26 | { 27 | "id": 5, 28 | "name": "prod", 29 | "external_url": "http://api.fake.io", 30 | "slug": "prod" 31 | } 32 | ] -------------------------------------------------------------------------------- /snapshots/list_project_environments_yaml.snap: -------------------------------------------------------------------------------- 1 | Fetching project environments (project id: 1)… 2 | - id: 1 3 | name: dev 4 | external_url: http://dev-api.fake.io 5 | slug: dev 6 | - id: 2 7 | name: staging 8 | external_url: http://staging-api.fake.io 9 | slug: staging 10 | - id: 3 11 | name: prod 12 | external_url: http://prod-api.fake.io 13 | slug: prod 14 | - id: 4 15 | name: preprod 16 | slug: preprod 17 | - id: 5 18 | name: prod 19 | external_url: http://api.fake.io 20 | slug: prod 21 | -------------------------------------------------------------------------------- /snapshots/list_project_issue_notes.snap: -------------------------------------------------------------------------------- 1 | Fetching project issue notes (project id: 1, issue iid: 5)… 2 | 3 | | ID | BODY | AUTHOR | RESOLVABLE | 4 | +-----+---------------------+--------+------------+ 5 | | 302 | closed | Pip | false | 6 | | 305 | Text of the comment | Pip | false | 7 | | | | | | 8 | 9 | -------------------------------------------------------------------------------- /snapshots/list_project_issue_notes_help.snap: -------------------------------------------------------------------------------- 1 | List project issue notes 2 | 3 | Usage: 4 | glc list project-issue-notes PROJECT_ID ISSUE_IID [flags] 5 | 6 | Aliases: 7 | project-issue-notes, issue-notes 8 | 9 | Flags: 10 | -h, --help help for project-issue-notes 11 | 12 | Global Flags: 13 | -a, --alias string Use resource alias 14 | -c, --config string Path to configuration file (default ".glc.yml") 15 | --host string GitLab host 16 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 17 | --no-color disable color output 18 | -o, --output-destination string Output result to file if specified 19 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 20 | -p, --page int Page (default 1) 21 | -l, --per-page int Items per page (default 10) 22 | --silent silent mode 23 | -v, --verbose verbose output 24 | -------------------------------------------------------------------------------- /snapshots/list_project_issue_notes_json.snap: -------------------------------------------------------------------------------- 1 | Fetching project issue notes (project id: 1, issue iid: 5)… 2 | [ 3 | { 4 | "id": 302, 5 | "body": "closed", 6 | "attachment": "", 7 | "title": "", 8 | "file_name": "", 9 | "created_at": "2013-10-02T09:22:45Z", 10 | "updated_at": "2013-10-02T10:22:45Z", 11 | "expires_at": "", 12 | "system": true, 13 | "resolvable": false, 14 | "noteable_id": 377, 15 | "noteable_iid": 377, 16 | "noteable_type": "Issue", 17 | "author": { 18 | "id": 1, 19 | "username": "pipin", 20 | "email": "admin@example.com", 21 | "name": "Pip", 22 | "state": "active", 23 | "created_at": "2013-09-30T13:46:01Z", 24 | "avatar_url": "", 25 | "web_url": "" 26 | } 27 | }, 28 | { 29 | "id": 305, 30 | "body": "Text of the comment\r\n", 31 | "attachment": "", 32 | "title": "", 33 | "file_name": "", 34 | "created_at": "2013-10-02T09:56:03Z", 35 | "updated_at": "2013-10-02T09:56:03Z", 36 | "expires_at": "", 37 | "system": true, 38 | "resolvable": false, 39 | "noteable_id": 121, 40 | "noteable_iid": 121, 41 | "noteable_type": "Issue", 42 | "author": { 43 | "id": 1, 44 | "username": "pipin", 45 | "email": "admin@example.com", 46 | "name": "Pip", 47 | "state": "active", 48 | "created_at": "2013-09-30T13:46:01Z", 49 | "avatar_url": "", 50 | "web_url": "" 51 | } 52 | } 53 | ] -------------------------------------------------------------------------------- /snapshots/list_project_issue_notes_no_issue_iid.snap: -------------------------------------------------------------------------------- 1 | Error: ✘ 2 argument(s) required for project-issue resource but got 1: 2 | - project_id 3 | - issue_iid 4 | 5 | Usage: 6 | glc list project-issue-notes PROJECT_ID ISSUE_IID [flags] 7 | 8 | Aliases: 9 | project-issue-notes, issue-notes 10 | 11 | Flags: 12 | -h, --help help for project-issue-notes 13 | 14 | Global Flags: 15 | -a, --alias string Use resource alias 16 | -c, --config string Path to configuration file (default ".glc.yml") 17 | --host string GitLab host 18 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 19 | --no-color disable color output 20 | -o, --output-destination string Output result to file if specified 21 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 22 | -p, --page int Page (default 1) 23 | -l, --per-page int Items per page (default 10) 24 | --silent silent mode 25 | -v, --verbose verbose output 26 | 27 | ✘ 2 argument(s) required for project-issue resource but got 1: 28 | - project_id 29 | - issue_iid 30 | 31 | -------------------------------------------------------------------------------- /snapshots/list_project_issue_notes_no_project_id.snap: -------------------------------------------------------------------------------- 1 | Error: ✘ 2 argument(s) required for project-issue resource but got 0: 2 | - project_id 3 | - issue_iid 4 | 5 | Usage: 6 | glc list project-issue-notes PROJECT_ID ISSUE_IID [flags] 7 | 8 | Aliases: 9 | project-issue-notes, issue-notes 10 | 11 | Flags: 12 | -h, --help help for project-issue-notes 13 | 14 | Global Flags: 15 | -a, --alias string Use resource alias 16 | -c, --config string Path to configuration file (default ".glc.yml") 17 | --host string GitLab host 18 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 19 | --no-color disable color output 20 | -o, --output-destination string Output result to file if specified 21 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 22 | -p, --page int Page (default 1) 23 | -l, --per-page int Items per page (default 10) 24 | --silent silent mode 25 | -v, --verbose verbose output 26 | 27 | ✘ 2 argument(s) required for project-issue resource but got 0: 28 | - project_id 29 | - issue_iid 30 | 31 | -------------------------------------------------------------------------------- /snapshots/list_project_issue_notes_yaml.snap: -------------------------------------------------------------------------------- 1 | Fetching project issue notes (project id: 1, issue iid: 5)… 2 | - id: 302 3 | body: closed 4 | attachment: "" 5 | title: "" 6 | file_name: "" 7 | created_at: "2013-10-02T09:22:45Z" 8 | updated_at: "2013-10-02T10:22:45Z" 9 | expires_at: "" 10 | system: true 11 | resolvable: false 12 | noteable_id: 377 13 | noteable_iid: 377 14 | noteable_type: Issue 15 | author: 16 | id: 1 17 | username: pipin 18 | email: admin@example.com 19 | name: Pip 20 | state: active 21 | created_at: "2013-09-30T13:46:01Z" 22 | avatar_url: "" 23 | web_url: "" 24 | - id: 305 25 | body: "Text of the comment\r\n" 26 | attachment: "" 27 | title: "" 28 | file_name: "" 29 | created_at: "2013-10-02T09:56:03Z" 30 | updated_at: "2013-10-02T09:56:03Z" 31 | expires_at: "" 32 | system: true 33 | resolvable: false 34 | noteable_id: 121 35 | noteable_iid: 121 36 | noteable_type: Issue 37 | author: 38 | id: 1 39 | username: pipin 40 | email: admin@example.com 41 | name: Pip 42 | state: active 43 | created_at: "2013-09-30T13:46:01Z" 44 | avatar_url: "" 45 | web_url: "" 46 | -------------------------------------------------------------------------------- /snapshots/list_project_merge_request_notes.snap: -------------------------------------------------------------------------------- 1 | Fetching project merge request notes (project id: 1, merge request iid: 3)… 2 | 3 | | ID | BODY | AUTHOR | RESOLVABLE | 4 | +--------+--------------------------------+----------------+------------+ 5 | | 157765 | assigned to @estelle.claude | Raoul Marcel | false | 6 | | 157764 | added ~45 and removed ~43 | Raoul Marcel | false | 7 | | | labels | | | 8 | | 157731 | removed ~422 label | Raoul Marcel | false | 9 | | 157730 | removed assignee | Estelle Claude | false | 10 | | 157728 | assigned to @raoul.marcel | Estelle Claude | false | 11 | | 157688 | changed milestone to %10 | Estelle Claude | false | 12 | 13 | -------------------------------------------------------------------------------- /snapshots/list_project_merge_request_notes_help.snap: -------------------------------------------------------------------------------- 1 | List project merge request notes 2 | 3 | Usage: 4 | glc list project-merge-request-notes PROJECT_ID MERGE_REQUEST_IID [flags] 5 | 6 | Aliases: 7 | project-merge-request-notes, project-mr-notes, merge-request-notes, mr-notes 8 | 9 | Flags: 10 | -h, --help help for project-merge-request-notes 11 | 12 | Global Flags: 13 | -a, --alias string Use resource alias 14 | -c, --config string Path to configuration file (default ".glc.yml") 15 | --host string GitLab host 16 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 17 | --no-color disable color output 18 | -o, --output-destination string Output result to file if specified 19 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 20 | -p, --page int Page (default 1) 21 | -l, --per-page int Items per page (default 10) 22 | --silent silent mode 23 | -v, --verbose verbose output 24 | -------------------------------------------------------------------------------- /snapshots/list_project_merge_request_notes_no_issue_iid.snap: -------------------------------------------------------------------------------- 1 | Error: ✘ 2 argument(s) required for project-issue resource but got 1: 2 | - project_id 3 | - issue_iid 4 | 5 | Usage: 6 | glc list project-issue-notes PROJECT_ID ISSUE_IID [flags] 7 | 8 | Aliases: 9 | project-issue-notes, issue-notes 10 | 11 | Flags: 12 | -h, --help help for project-issue-notes 13 | 14 | Global Flags: 15 | -a, --alias string Use resource alias 16 | -c, --config string Path to configuration file (default ".glc.yml") 17 | --host string GitLab host 18 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 19 | --no-color disable color output 20 | -o, --output-destination string Output result to file if specified 21 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 22 | -p, --page int Page (default 1) 23 | -l, --per-page int Items per page (default 10) 24 | --silent silent mode 25 | -v, --verbose verbose output 26 | 27 | ✘ 2 argument(s) required for project-issue resource but got 1: 28 | - project_id 29 | - issue_iid 30 | 31 | -------------------------------------------------------------------------------- /snapshots/list_project_merge_request_notes_no_merge_request_iid.snap: -------------------------------------------------------------------------------- 1 | Error: ✘ 2 argument(s) required for project-merge-request resource but got 1: 2 | - project_id 3 | - merge_request_iid 4 | 5 | Usage: 6 | glc list project-merge-request-notes PROJECT_ID MERGE_REQUEST_IID [flags] 7 | 8 | Aliases: 9 | project-merge-request-notes, project-mr-notes, merge-request-notes, mr-notes 10 | 11 | Flags: 12 | -h, --help help for project-merge-request-notes 13 | 14 | Global Flags: 15 | -a, --alias string Use resource alias 16 | -c, --config string Path to configuration file (default ".glc.yml") 17 | --host string GitLab host 18 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 19 | --no-color disable color output 20 | -o, --output-destination string Output result to file if specified 21 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 22 | -p, --page int Page (default 1) 23 | -l, --per-page int Items per page (default 10) 24 | --silent silent mode 25 | -v, --verbose verbose output 26 | 27 | ✘ 2 argument(s) required for project-merge-request resource but got 1: 28 | - project_id 29 | - merge_request_iid 30 | 31 | -------------------------------------------------------------------------------- /snapshots/list_project_merge_request_notes_no_project_id.snap: -------------------------------------------------------------------------------- 1 | Error: ✘ 2 argument(s) required for project-merge-request resource but got 0: 2 | - project_id 3 | - merge_request_iid 4 | 5 | Usage: 6 | glc list project-merge-request-notes PROJECT_ID MERGE_REQUEST_IID [flags] 7 | 8 | Aliases: 9 | project-merge-request-notes, project-mr-notes, merge-request-notes, mr-notes 10 | 11 | Flags: 12 | -h, --help help for project-merge-request-notes 13 | 14 | Global Flags: 15 | -a, --alias string Use resource alias 16 | -c, --config string Path to configuration file (default ".glc.yml") 17 | --host string GitLab host 18 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 19 | --no-color disable color output 20 | -o, --output-destination string Output result to file if specified 21 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 22 | -p, --page int Page (default 1) 23 | -l, --per-page int Items per page (default 10) 24 | --silent silent mode 25 | -v, --verbose verbose output 26 | 27 | ✘ 2 argument(s) required for project-merge-request resource but got 0: 28 | - project_id 29 | - merge_request_iid 30 | 31 | -------------------------------------------------------------------------------- /snapshots/list_project_merge_requests_help.snap: -------------------------------------------------------------------------------- 1 | List project merge requests 2 | 3 | Usage: 4 | glc list project-merge-requests PROJECT_ID [flags] 5 | 6 | Aliases: 7 | project-merge-requests, pmr 8 | 9 | Flags: 10 | -h, --help help for project-merge-requests 11 | 12 | Global Flags: 13 | -a, --alias string Use resource alias 14 | -c, --config string Path to configuration file (default ".glc.yml") 15 | --host string GitLab host 16 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 17 | --no-color disable color output 18 | -o, --output-destination string Output result to file if specified 19 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 20 | -p, --page int Page (default 1) 21 | -l, --per-page int Items per page (default 10) 22 | --silent silent mode 23 | -v, --verbose verbose output 24 | -------------------------------------------------------------------------------- /snapshots/list_project_snippet_notes.snap: -------------------------------------------------------------------------------- 1 | Fetching project snippet notes (project id: 1, snippet id: 7)… 2 | 3 | | ID | BODY | AUTHOR | RESOLVABLE | 4 | +--------+---------------+--------------+------------+ 5 | | 529462 | another one | Raoul Marcel | false | 6 | | 529460 | or note to be | Raoul Marcel | false | 7 | | 529459 | note? | Raoul Marcel | false | 8 | | 529458 | other | Raoul Marcel | false | 9 | | 529457 | test | Raoul Marcel | false | 10 | 11 | -------------------------------------------------------------------------------- /snapshots/list_project_snippet_notes_help.snap: -------------------------------------------------------------------------------- 1 | List project snippet notes 2 | 3 | Usage: 4 | glc list project-snippet-notes PROJECT_ID SNIPPET_ID [flags] 5 | 6 | Aliases: 7 | project-snippet-notes, snippet-notes 8 | 9 | Flags: 10 | -h, --help help for project-snippet-notes 11 | 12 | Global Flags: 13 | -a, --alias string Use resource alias 14 | -c, --config string Path to configuration file (default ".glc.yml") 15 | --host string GitLab host 16 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 17 | --no-color disable color output 18 | -o, --output-destination string Output result to file if specified 19 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 20 | -p, --page int Page (default 1) 21 | -l, --per-page int Items per page (default 10) 22 | --silent silent mode 23 | -v, --verbose verbose output 24 | -------------------------------------------------------------------------------- /snapshots/list_project_snippet_notes_no_project_id.snap: -------------------------------------------------------------------------------- 1 | Error: ✘ 2 argument(s) required for project-snippet resource but got 0: 2 | - project_id 3 | - snippet_id 4 | 5 | Usage: 6 | glc list project-snippet-notes PROJECT_ID SNIPPET_ID [flags] 7 | 8 | Aliases: 9 | project-snippet-notes, snippet-notes 10 | 11 | Flags: 12 | -h, --help help for project-snippet-notes 13 | 14 | Global Flags: 15 | -a, --alias string Use resource alias 16 | -c, --config string Path to configuration file (default ".glc.yml") 17 | --host string GitLab host 18 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 19 | --no-color disable color output 20 | -o, --output-destination string Output result to file if specified 21 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 22 | -p, --page int Page (default 1) 23 | -l, --per-page int Items per page (default 10) 24 | --silent silent mode 25 | -v, --verbose verbose output 26 | 27 | ✘ 2 argument(s) required for project-snippet resource but got 0: 28 | - project_id 29 | - snippet_id 30 | 31 | -------------------------------------------------------------------------------- /snapshots/list_project_snippet_notes_no_snippet_id.snap: -------------------------------------------------------------------------------- 1 | Error: ✘ 2 argument(s) required for project-snippet resource but got 1: 2 | - project_id 3 | - snippet_id 4 | 5 | Usage: 6 | glc list project-snippet-notes PROJECT_ID SNIPPET_ID [flags] 7 | 8 | Aliases: 9 | project-snippet-notes, snippet-notes 10 | 11 | Flags: 12 | -h, --help help for project-snippet-notes 13 | 14 | Global Flags: 15 | -a, --alias string Use resource alias 16 | -c, --config string Path to configuration file (default ".glc.yml") 17 | --host string GitLab host 18 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 19 | --no-color disable color output 20 | -o, --output-destination string Output result to file if specified 21 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 22 | -p, --page int Page (default 1) 23 | -l, --per-page int Items per page (default 10) 24 | --silent silent mode 25 | -v, --verbose verbose output 26 | 27 | ✘ 2 argument(s) required for project-snippet resource but got 1: 28 | - project_id 29 | - snippet_id 30 | 31 | -------------------------------------------------------------------------------- /snapshots/list_projects.snap: -------------------------------------------------------------------------------- 1 | Fetching projects… 2 | 3 | | ID | NAME | PUBLIC | WEBURL | 4 | +----+-----------------+--------+---------------------------------------------+ 5 | | 4 | Diaspora Client | false | http://example.com/diaspora/diaspora-client | 6 | | 6 | Puppet | false | http://example.com/brightbox/puppet | 7 | 8 | -------------------------------------------------------------------------------- /snapshots/list_projects_help.snap: -------------------------------------------------------------------------------- 1 | List projects 2 | 3 | Usage: 4 | glc list projects [flags] 5 | 6 | Aliases: 7 | projects, p 8 | 9 | Flags: 10 | --archived Limit by archived status 11 | -h, --help help for projects 12 | --membership Limit by projects that the current user is a member of 13 | --owned Limit by projects owned by the current user 14 | -s, --search string Search term 15 | --starred Limit by projects starred by the current user 16 | 17 | Global Flags: 18 | -a, --alias string Use resource alias 19 | -c, --config string Path to configuration file (default ".glc.yml") 20 | --host string GitLab host 21 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 22 | --no-color disable color output 23 | -o, --output-destination string Output result to file if specified 24 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 25 | -p, --page int Page (default 1) 26 | -l, --per-page int Items per page (default 10) 27 | --silent silent mode 28 | -v, --verbose verbose output 29 | -------------------------------------------------------------------------------- /snapshots/list_runners.snap: -------------------------------------------------------------------------------- 1 | Fetching runners… 2 | 3 | | ID | NAME | ACTIVE | ONLINE | STATUS | IP | SHARED | 4 | +----+------+--------+--------+--------+----+--------+ 5 | | 6 | | true | false | | | false | 6 | | 8 | | true | false | | | false | 7 | 8 | -------------------------------------------------------------------------------- /snapshots/list_runners_help.snap: -------------------------------------------------------------------------------- 1 | List runners 2 | 3 | Usage: 4 | glc list runners [flags] 5 | 6 | Aliases: 7 | runners, r 8 | 9 | Flags: 10 | --all Get a list of all runners in the GitLab instance (specific and shared). Access is restricted to users with admin privileges 11 | -h, --help help for runners 12 | -s, --scope string The scope of runners to show, one of: specific, shared, active, paused, online; showing all runners if none provided 13 | 14 | Global Flags: 15 | -a, --alias string Use resource alias 16 | -c, --config string Path to configuration file (default ".glc.yml") 17 | --host string GitLab host 18 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 19 | --no-color disable color output 20 | -o, --output-destination string Output result to file if specified 21 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 22 | -p, --page int Page (default 1) 23 | -l, --per-page int Items per page (default 10) 24 | --silent silent mode 25 | -v, --verbose verbose output 26 | -------------------------------------------------------------------------------- /snapshots/list_runners_json.snap: -------------------------------------------------------------------------------- 1 | Fetching runners… 2 | [ 3 | { 4 | "id": 6, 5 | "active": true, 6 | "description": "test-1-20150125" 7 | }, 8 | { 9 | "id": 8, 10 | "active": true, 11 | "description": "test-2-20150125" 12 | } 13 | ] -------------------------------------------------------------------------------- /snapshots/list_runners_yaml.snap: -------------------------------------------------------------------------------- 1 | Fetching runners… 2 | - id: 6 3 | active: true 4 | description: test-1-20150125 5 | - id: 8 6 | active: true 7 | description: test-2-20150125 8 | -------------------------------------------------------------------------------- /snapshots/list_ssh_keys.snap: -------------------------------------------------------------------------------- 1 | Fetching current user ssh keys… 2 | 3 | | ID | TITLE | KEY | CREATED AT | 4 | +----+--------------------+-------------------+--------------------------+ 5 | | 1 | Public key | ssh-rsa AAAAB3Nz… | 2014-08-01T14:47:39.080Z | 6 | | 2 | Whatever key | ssh-rsa AAAAB3Nz… | 2014-08-01T14:47:39.080Z | 7 | | 3 | Another Public key | ssh-rsa AAAAB3Nz… | 2014-08-01T14:47:39.080Z | 8 | 9 | -------------------------------------------------------------------------------- /snapshots/list_ssh_keys_help.snap: -------------------------------------------------------------------------------- 1 | List current user ssh keys 2 | 3 | Usage: 4 | glc list ssh-keys [flags] 5 | 6 | Aliases: 7 | ssh-keys, sk 8 | 9 | Flags: 10 | -h, --help help for ssh-keys 11 | 12 | Global Flags: 13 | -a, --alias string Use resource alias 14 | -c, --config string Path to configuration file (default ".glc.yml") 15 | --host string GitLab host 16 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 17 | --no-color disable color output 18 | -o, --output-destination string Output result to file if specified 19 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 20 | -p, --page int Page (default 1) 21 | -l, --per-page int Items per page (default 10) 22 | --silent silent mode 23 | -v, --verbose verbose output 24 | -------------------------------------------------------------------------------- /snapshots/list_ssh_keys_json.snap: -------------------------------------------------------------------------------- 1 | Fetching current user ssh keys… 2 | [ 3 | { 4 | "id": 1, 5 | "title": "Public key", 6 | "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=", 7 | "created_at": "2014-08-01T14:47:39.080Z" 8 | }, 9 | { 10 | "id": 2, 11 | "title": "Whatever key", 12 | "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=", 13 | "created_at": "2014-08-01T14:47:39.080Z" 14 | }, 15 | { 16 | "id": 3, 17 | "title": "Another Public key", 18 | "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=", 19 | "created_at": "2014-08-01T14:47:39.080Z" 20 | } 21 | ] -------------------------------------------------------------------------------- /snapshots/list_ssh_keys_yaml.snap: -------------------------------------------------------------------------------- 1 | Fetching current user ssh keys… 2 | - id: 1 3 | title: Public key 4 | key: ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0= 5 | created_at: "2014-08-01T14:47:39.080Z" 6 | - id: 2 7 | title: Whatever key 8 | key: ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0= 9 | created_at: "2014-08-01T14:47:39.080Z" 10 | - id: 3 11 | title: Another Public key 12 | key: ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0= 13 | created_at: "2014-08-01T14:47:39.080Z" 14 | -------------------------------------------------------------------------------- /snapshots/list_user_ssh_keys.snap: -------------------------------------------------------------------------------- 1 | Fetching user 1 ssh keys… 2 | 3 | | ID | TITLE | KEY | CREATED AT | 4 | +----+--------------------+-------------------+--------------------------+ 5 | | 1 | Public key | ssh-rsa AAAAB3Nz… | 2014-08-01T14:47:39.080Z | 6 | | 2 | Whatever key | ssh-rsa AAAAB3Nz… | 2014-08-01T14:47:39.080Z | 7 | | 3 | Another Public key | ssh-rsa AAAAB3Nz… | 2014-08-01T14:47:39.080Z | 8 | 9 | -------------------------------------------------------------------------------- /snapshots/list_user_ssh_keys_help.snap: -------------------------------------------------------------------------------- 1 | List specific user ssh keys 2 | 3 | Usage: 4 | glc list user-ssh-keys USER_ID [flags] 5 | 6 | Aliases: 7 | user-ssh-keys, usk 8 | 9 | Flags: 10 | -h, --help help for user-ssh-keys 11 | 12 | Global Flags: 13 | -a, --alias string Use resource alias 14 | -c, --config string Path to configuration file (default ".glc.yml") 15 | --host string GitLab host 16 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 17 | --no-color disable color output 18 | -o, --output-destination string Output result to file if specified 19 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 20 | -p, --page int Page (default 1) 21 | -l, --per-page int Items per page (default 10) 22 | --silent silent mode 23 | -v, --verbose verbose output 24 | -------------------------------------------------------------------------------- /snapshots/list_user_ssh_keys_json.snap: -------------------------------------------------------------------------------- 1 | Fetching user 1 ssh keys… 2 | [ 3 | { 4 | "id": 1, 5 | "title": "Public key", 6 | "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=", 7 | "created_at": "2014-08-01T14:47:39.080Z" 8 | }, 9 | { 10 | "id": 2, 11 | "title": "Whatever key", 12 | "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=", 13 | "created_at": "2014-08-01T14:47:39.080Z" 14 | }, 15 | { 16 | "id": 3, 17 | "title": "Another Public key", 18 | "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=", 19 | "created_at": "2014-08-01T14:47:39.080Z" 20 | } 21 | ] -------------------------------------------------------------------------------- /snapshots/list_user_ssh_keys_yaml.snap: -------------------------------------------------------------------------------- 1 | Fetching user 1 ssh keys… 2 | - id: 1 3 | title: Public key 4 | key: ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0= 5 | created_at: "2014-08-01T14:47:39.080Z" 6 | - id: 2 7 | title: Whatever key 8 | key: ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0= 9 | created_at: "2014-08-01T14:47:39.080Z" 10 | - id: 3 11 | title: Another Public key 12 | key: ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0= 13 | created_at: "2014-08-01T14:47:39.080Z" 14 | -------------------------------------------------------------------------------- /snapshots/list_users.snap: -------------------------------------------------------------------------------- 1 | Fetching users… 2 | 3 | | ID | USERNAME | EMAIL | NAME | STATE | IS ADMIN | EXTERNAL | 4 | +----+------------+------------------+------------+---------+----------+----------+ 5 | | 1 | john_smith | john@example.com | John Smith | active | false | false | 6 | | 2 | jack_smith | jack@example.com | Jack Smith | blocked | false | false | 7 | 8 | -------------------------------------------------------------------------------- /snapshots/list_users_help.snap: -------------------------------------------------------------------------------- 1 | List users 2 | 3 | Usage: 4 | glc list users [flags] 5 | 6 | Aliases: 7 | users, u 8 | 9 | Flags: 10 | --active Limit to active users 11 | --blocked Limit to blocked users 12 | -h, --help help for users 13 | -s, --search string Search users by email or username 14 | -u, --username string Search users by username 15 | 16 | Global Flags: 17 | -a, --alias string Use resource alias 18 | -c, --config string Path to configuration file (default ".glc.yml") 19 | --host string GitLab host 20 | -i, --interactive enable interactive mode when applicable (eg. creation, pagination) 21 | --no-color disable color output 22 | -o, --output-destination string Output result to file if specified 23 | -f, --output-format string Output format, must be one of 'text', 'json', 'yaml' 24 | -p, --page int Page (default 1) 25 | -l, --per-page int Items per page (default 10) 26 | --silent silent mode 27 | -v, --verbose verbose output 28 | -------------------------------------------------------------------------------- /snapshots/list_users_json.snap: -------------------------------------------------------------------------------- 1 | Fetching users… 2 | [ 3 | { 4 | "id": 1, 5 | "username": "john_smith", 6 | "email": "john@example.com", 7 | "name": "John Smith", 8 | "state": "active", 9 | "web_url": "", 10 | "created_at": "2012-05-23T08:00:58Z", 11 | "website_url": "", 12 | "organization": "", 13 | "theme_id": 1, 14 | "color_scheme_id": 2, 15 | "can_create_group": true 16 | }, 17 | { 18 | "id": 2, 19 | "username": "jack_smith", 20 | "email": "jack@example.com", 21 | "name": "Jack Smith", 22 | "state": "blocked", 23 | "web_url": "", 24 | "created_at": "2012-05-23T08:01:01Z", 25 | "website_url": "", 26 | "organization": "", 27 | "theme_id": 1, 28 | "color_scheme_id": 3, 29 | "can_create_group": true, 30 | "can_create_project": true 31 | } 32 | ] -------------------------------------------------------------------------------- /snapshots/list_users_yaml.snap: -------------------------------------------------------------------------------- 1 | Fetching users… 2 | - id: 1 3 | username: john_smith 4 | email: john@example.com 5 | name: John Smith 6 | state: active 7 | web_url: "" 8 | created_at: "2012-05-23T08:00:58Z" 9 | website_url: "" 10 | organization: "" 11 | theme_id: 1 12 | color_scheme_id: 2 13 | can_create_group: true 14 | - id: 2 15 | username: jack_smith 16 | email: jack@example.com 17 | name: Jack Smith 18 | state: blocked 19 | web_url: "" 20 | created_at: "2012-05-23T08:01:01Z" 21 | website_url: "" 22 | organization: "" 23 | theme_id: 1 24 | color_scheme_id: 3 25 | can_create_group: true 26 | can_create_project: true 27 | -------------------------------------------------------------------------------- /test/cli_config.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | /* 4 | type CliConfig struct { 5 | Config 6 | Dir string 7 | File string 8 | } 9 | 10 | func NewConfig(dir, file string) *CliConfig { 11 | c := &CliConfig{ 12 | Dir: dir, 13 | File: file, 14 | } 15 | c.Host = "http://wiremock:8080" 16 | c.ApiPath = "/api/v4" 17 | 18 | return c 19 | } 20 | 21 | func (c *CliConfig) Path() string { 22 | return filepath.Join(c.Dir, c.File) 23 | } 24 | 25 | func (c *CliConfig) Exists() bool { 26 | if _, err := os.Stat(c.Path()); os.IsNotExist(err) { 27 | return false 28 | } 29 | 30 | return true 31 | } 32 | 33 | func (c *CliConfig) Write() { 34 | c.Config.Write(c.Path()) 35 | } 36 | */ 37 | -------------------------------------------------------------------------------- /test/config.go: -------------------------------------------------------------------------------- 1 | package test 2 | -------------------------------------------------------------------------------- /test/utils.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "log" 5 | "path/filepath" 6 | "runtime" 7 | "testing" 8 | ) 9 | 10 | func baseDir(t *testing.T) string { 11 | _, filename, _, ok := runtime.Caller(0) 12 | if !ok { 13 | if t != nil { 14 | t.Fatal("an error occurred while recovering caller information") 15 | return "" 16 | } else { 17 | log.Fatal("an error occurred while recovering caller information") 18 | } 19 | } 20 | 21 | return filepath.Dir(filename) 22 | } 23 | --------------------------------------------------------------------------------