chore: re-add linting/formatting job to ci

This commit is contained in:
Kai Armstrong 2022-11-17 18:36:09 +00:00 committed by Gary Holtz
parent 5ddf81ee69
commit 39e9e21313
146 changed files with 253 additions and 269 deletions

View File

@ -20,17 +20,20 @@ include:
- template: Security/SAST.gitlab-ci.yml - template: Security/SAST.gitlab-ci.yml
- template: Security/Dependency-Scanning.gitlab-ci.yml - template: Security/Dependency-Scanning.gitlab-ci.yml
- template: Security/Secret-Detection.gitlab-ci.yml - template: Security/Secret-Detection.gitlab-ci.yml
- local: .gitlab/ci/*.gitlab-ci.yml
# From: https://docs.gitlab.com/ee/ci/caching/#cache-go-dependencies # From: https://docs.gitlab.com/ee/ci/caching/#cache-go-dependencies
.go-cache: .go-cache:
variables: variables:
GOPATH: $CI_PROJECT_DIR/.go GOPATH: $CI_PROJECT_DIR/.go
GOLANGCI_LINT_CACHE: $CI_PROJECT_DIR/.golangci-lint
before_script: before_script:
- mkdir -p .go - mkdir -p .go .golangci-lint
cache: cache:
paths: paths:
- .go/pkg/mod/ - .go/pkg/mod/
- .golangci-lint/
.documentation: .documentation:
stage: documentation stage: documentation

View File

@ -1,13 +1,14 @@
lint: lint:
extends: .go-cache
image: registry.gitlab.com/gitlab-org/gitlab-build-images:golangci-lint-alpine image: registry.gitlab.com/gitlab-org/gitlab-build-images:golangci-lint-alpine
stage: test stage: test
script: script:
- golangci-lint --version
# Use default .golangci.yml file from the image if one is not present in the project root. # Use default .golangci.yml file from the image if one is not present in the project root.
- '[ -e .golangci.yml ] || cp /golangci/.golangci.yml .' - '[ -e .golangci.yml ] || cp /golangci/.golangci.yml .'
# Write the code coverage report to gl-code-quality-report.json # Write the code coverage report to gl-code-quality-report.json
# and print linting issues to stdout in the format: path/to/file:line description
# remove `--issues-exit-code 0` or set to non-zero to fail the job if linting issues are detected # remove `--issues-exit-code 0` or set to non-zero to fail the job if linting issues are detected
- golangci-lint run --issues-exit-code 0 --out-format code-climate | tee gl-code-quality-report.json | jq -r '.[] | "\(.location.path):\(.location.lines.begin) \(.description)"' - golangci-lint run --out-format colored-line-number:stdout,code-climate:gl-code-quality-report.json
artifacts: artifacts:
reports: reports:
codequality: gl-code-quality-report.json codequality: gl-code-quality-report.json

View File

@ -1,7 +1,17 @@
linters:
enable:
- gofmt
run: run:
timeout: 5m timeout: 5m
modules-download-mode: readonly modules-download-mode: readonly
linters:
disable-all: true
enable:
- errcheck
- exportloopref
- gofumpt
- goimports
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- unused

View File

@ -1,3 +1,5 @@
# Contributing Guide
## Developer Certificate of Origin + License ## Developer Certificate of Origin + License
Contributions to this repository are subject to the [Developer Certificate of Origin](https://docs.gitlab.com/ee/legal/developer_certificate_of_origin.html#developer-certificate-of-origin-version-11). Contributions to this repository are subject to the [Developer Certificate of Origin](https://docs.gitlab.com/ee/legal/developer_certificate_of_origin.html#developer-certificate-of-origin-version-11).
@ -16,26 +18,29 @@ Use your best judgement, and feel free to propose changes to this document in a
Please do: Please do:
* Check existing issues to verify that the bug or feature request has not already been submitted. - Check existing issues to verify that the bug or feature request has not already been submitted.
* Open an issue if things aren't working as expected. - Open an issue if things aren't working as expected.
* Open an issue to propose a significant change. - Open an issue to propose a significant change.
* Open an issue to propose a feature. - Open an issue to propose a feature.
* Open a merge request to fix a bug. - Open a merge request to fix a bug.
* Open a merge request to fix documentation about a command. - Open a merge request to fix documentation about a command.
* Open a merge request for an issue and leave a comment claiming it. - Open a merge request for an issue and leave a comment claiming it.
Please avoid: Please avoid:
* Opening merge requests for issues marked `blocked`. - Opening merge requests for issues marked `blocked`.
* Opening merge requests for documentation for a new command specifically. Manual pages are auto-generated from source after every release - Opening merge requests for documentation for a new command specifically. Manual pages are auto-generated from source after every release
## Code of Conduct ## Code of Conduct
We want to create a welcoming environment for everyone who is interested in contributing. Visit our [Code of Conduct page](https://about.gitlab.com/community/contribute/code-of-conduct/) to learn more about our commitment to an open and welcoming environment. We want to create a welcoming environment for everyone who is interested in contributing. Visit our [Code of Conduct page](https://about.gitlab.com/community/contribute/code-of-conduct/) to learn more about our commitment to an open and welcoming environment.
## Getting Started ## Getting Started
### Building the project ### Building the project
Prerequisites: Prerequisites:
- Go 1.16+ - Go 1.16+
Build with: `make` or `go build -o bin/glab ./cmd/glab/main.go` Build with: `make` or `go build -o bin/glab ./cmd/glab/main.go`
@ -59,6 +64,15 @@ on [GitLab.com](https://gitlab.com).
1. Make your change, add tests, and ensure tests pass 1. Make your change, add tests, and ensure tests pass
1. Submit a merge request 1. Submit a merge request
### Formatting your code
We use [`golangci-lint`](https://golangci-lint.run/) to lint and format
the code in this project. The linter configuration can be seen
[here](https://gitlab.com/gitlab-org/cli/-/blob/main/.golangci.yml).
Additional details about code style and format are in the
[go guide](https://docs.gitlab.com/ee/development/go_guide/#code-style-and-format).
## Commit Messages ## Commit Messages
### TL;DR: Your commit message should be semantic ### TL;DR: Your commit message should be semantic
@ -76,6 +90,7 @@ Any line of the commit message cannot be longer than 100 characters! This allows
``` ```
### Message Header ### Message Header
Ideally, the commit message heading which contains the description, should not be more than 50 characters Ideally, the commit message heading which contains the description, should not be more than 50 characters
The message header is a single line that contains a succinct description of the change containing a type, an optional scope, and a subject. The message header is a single line that contains a succinct description of the change containing a type, an optional scope, and a subject.
@ -100,9 +115,9 @@ Scope can be anything specifying the place of the commit change. For example eve
This is a very short description of the change This is a very short description of the change
* `use imperative, present tense: “change” not “changed” nor “changes”` - `use imperative, present tense: “change” not “changed” nor “changes”`
* `don't capitalize the first letter` - `don't capitalize the first letter`
* `no dot (.) at the end` - `no dot (.) at the end`
### Message Body ### Message Body
@ -137,4 +152,3 @@ fix(login): allow provided user preferences to override default preferences
Fixes #025 Fixes #025
``` ```

View File

@ -78,6 +78,7 @@ func GetClient() *Client {
// HTTPClient returns the httpClient instance used to initialise the gitlab api client // HTTPClient returns the httpClient instance used to initialise the gitlab api client
func HTTPClient() *http.Client { return apiClient.HTTPClient() } func HTTPClient() *http.Client { return apiClient.HTTPClient() }
func (c *Client) HTTPClient() *http.Client { func (c *Client) HTTPClient() *http.Client {
if c.httpClientOverride != nil { if c.httpClientOverride != nil {
return c.httpClientOverride return c.httpClientOverride
@ -90,12 +91,14 @@ func (c *Client) HTTPClient() *http.Client {
// OverrideHTTPClient overrides the default http client // OverrideHTTPClient overrides the default http client
func OverrideHTTPClient(client *http.Client) { apiClient.OverrideHTTPClient(client) } func OverrideHTTPClient(client *http.Client) { apiClient.OverrideHTTPClient(client) }
func (c *Client) OverrideHTTPClient(client *http.Client) { func (c *Client) OverrideHTTPClient(client *http.Client) {
c.httpClientOverride = client c.httpClientOverride = client
} }
// Token returns the authentication token // Token returns the authentication token
func Token() string { return apiClient.Token() } func Token() string { return apiClient.Token() }
func (c *Client) Token() string { func (c *Client) Token() string {
return c.token return c.token
} }

View File

@ -11,7 +11,7 @@ func Test_tlsConfig(t *testing.T) {
type args struct { type args struct {
host string host string
} }
var tests = []struct { tests := []struct {
name string name string
args args args args
want []uint16 want []uint16
@ -38,7 +38,6 @@ func Test_tlsConfig(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
client := tlsConfig(tt.args.host) client := tlsConfig(tt.args.host)
assert.Equal(t, tt.want, client.CipherSuites) assert.Equal(t, tt.want, client.CipherSuites)

View File

@ -166,7 +166,6 @@ var GetPipeline = func(client *gitlab.Client, pid int, l *gitlab.RequestOptionFu
} }
pipe, _, err := client.Pipelines.GetPipeline(repo, pid) pipe, _, err := client.Pipelines.GetPipeline(repo, pid)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -179,13 +178,12 @@ var GetPipelineVariables = func(client *gitlab.Client, pid int, l *gitlab.Reques
} }
pipe, _, err := client.Pipelines.GetPipeline(repo, pid) pipe, _, err := client.Pipelines.GetPipeline(repo, pid)
if err != nil { if err != nil {
return nil, err return nil, err
} }
projectID := pipe.ProjectID projectID := pipe.ProjectID
pipelineVars, _, err := client.Pipelines.GetPipelineVariables(projectID, pid) pipelineVars, _, err := client.Pipelines.GetPipelineVariables(projectID, pid)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -12,7 +12,6 @@ var GetFile = func(client *gitlab.Client, projectID interface{}, path string, re
Ref: &ref, Ref: &ref,
} }
file, _, err := client.RepositoryFiles.GetFile(projectID, path, fileOpts) file, _, err := client.RepositoryFiles.GetFile(projectID, path, fileOpts)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -55,7 +55,6 @@ var DeleteProjectVariable = func(client *gitlab.Client, projectID interface{}, k
}, },
} }
_, err := client.ProjectVariables.RemoveVariable(projectID, key, reqOpts) _, err := client.ProjectVariables.RemoveVariable(projectID, key, reqOpts)
if err != nil { if err != nil {
return err return err
} }
@ -68,7 +67,7 @@ var UpdateProjectVariable = func(client *gitlab.Client, projectID interface{}, k
client = apiClient.Lab() client = apiClient.Lab()
} }
var filter = func(request *retryablehttp.Request) error { filter := func(request *retryablehttp.Request) error {
q := request.URL.Query() q := request.URL.Query()
q.Add("filter[environment_scope]", *opts.EnvironmentScope) q.Add("filter[environment_scope]", *opts.EnvironmentScope)
@ -127,7 +126,6 @@ var DeleteGroupVariable = func(client *gitlab.Client, groupID interface{}, key s
} }
_, err := client.GroupVariables.RemoveVariable(groupID, key) _, err := client.GroupVariables.RemoveVariable(groupID, key)
if err != nil { if err != nil {
return err return err
} }

View File

@ -36,7 +36,7 @@ func main() {
} }
os.Exit(1) os.Exit(1)
} }
err := os.MkdirAll(*path, 0755) err := os.MkdirAll(*path, 0o755)
if err != nil { if err != nil {
fatal(err) fatal(err)
} }
@ -75,7 +75,7 @@ func genWebDocs(glabCli *cobra.Command, path string) error {
for _, cmd := range cmds { for _, cmd := range cmds {
fmt.Println("Generating docs for " + cmd.Name()) fmt.Println("Generating docs for " + cmd.Name())
// create directories for parent commands // create directories for parent commands
_ = os.MkdirAll(path+cmd.Name(), 0750) _ = os.MkdirAll(path+cmd.Name(), 0o750)
// Generate parent command // Generate parent command
out := new(bytes.Buffer) out := new(bytes.Buffer)
@ -88,7 +88,7 @@ func genWebDocs(glabCli *cobra.Command, path string) error {
for _, cmdC := range cmd.Commands() { for _, cmdC := range cmd.Commands() {
if cmdC.HasAvailableSubCommands() { if cmdC.HasAvailableSubCommands() {
fmt.Println("Generating subcommand docs for " + cmdC.Name()) fmt.Println("Generating subcommand docs for " + cmdC.Name())
_ = os.MkdirAll(path+cmd.Name()+"/"+cmdC.Name(), 0750) _ = os.MkdirAll(path+cmd.Name()+"/"+cmdC.Name(), 0o750)
// Generate parent command // Generate parent command
out := new(bytes.Buffer) out := new(bytes.Buffer)
@ -97,7 +97,7 @@ func genWebDocs(glabCli *cobra.Command, path string) error {
return err return err
} }
err = config.WriteFile(path+cmd.Name()+"/"+cmdC.Name()+"/index.md", out.Bytes(), 0755) err = config.WriteFile(path+cmd.Name()+"/"+cmdC.Name()+"/index.md", out.Bytes(), 0o755)
if err != nil { if err != nil {
return err return err
} }
@ -119,7 +119,7 @@ func genWebDocs(glabCli *cobra.Command, path string) error {
} }
} }
err = config.WriteFile(path+cmd.Name()+"/index.md", out.Bytes(), 0755) err = config.WriteFile(path+cmd.Name()+"/index.md", out.Bytes(), 0o755)
if err != nil { if err != nil {
return err return err
} }
@ -190,14 +190,14 @@ func GenMarkdownCustom(cmd *cobra.Command, w io.Writer) error {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
name := cmd.CommandPath() name := cmd.CommandPath()
//GitLab Specific Docs Metadata // GitLab Specific Docs Metadata
buf.WriteString("---" + "\n") buf.WriteString("---" + "\n")
buf.WriteString("stage: Create" + "\n") buf.WriteString("stage: Create" + "\n")
buf.WriteString("group: Code Review" + "\n") buf.WriteString("group: Code Review" + "\n")
buf.WriteString("info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments" + "\n") buf.WriteString("info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments" + "\n")
buf.WriteString("---" + "\n\n") buf.WriteString("---" + "\n\n")
//Generated by a script // Generated by a script
buf.WriteString("<!--" + "\n") buf.WriteString("<!--" + "\n")
buf.WriteString("This documentation is auto generated by a script." + "\n") buf.WriteString("This documentation is auto generated by a script." + "\n")
buf.WriteString("Please do not edit this file directly, check cmd/gen-docs/docs.go." + "\n") buf.WriteString("Please do not edit this file directly, check cmd/gen-docs/docs.go." + "\n")

View File

@ -10,7 +10,7 @@ import (
) )
func NewCmdAlias(f *cmdutils.Factory) *cobra.Command { func NewCmdAlias(f *cmdutils.Factory) *cobra.Command {
var aliasCmd = &cobra.Command{ aliasCmd := &cobra.Command{
Use: "alias [command] [flags]", Use: "alias [command] [flags]",
Short: `Create, list and delete aliases`, Short: `Create, list and delete aliases`,
Long: ``, Long: ``,

View File

@ -23,7 +23,7 @@ func NewCmdDelete(f *cmdutils.Factory, runF func(*DeleteOptions) error) *cobra.C
IO: f.IO, IO: f.IO,
} }
var aliasDeleteCmd = &cobra.Command{ aliasDeleteCmd := &cobra.Command{
Use: "delete <alias name> [flags]", Use: "delete <alias name> [flags]",
Short: `Delete an alias.`, Short: `Delete an alias.`,
Long: ``, Long: ``,
@ -54,7 +54,6 @@ func deleteRun(cmd *cobra.Command, opts *DeleteOptions) error {
expansion, ok := aliasCfg.Get(opts.Name) expansion, ok := aliasCfg.Get(opts.Name)
if !ok { if !ok {
return fmt.Errorf("no such alias %s", opts.Name) return fmt.Errorf("no such alias %s", opts.Name)
} }
err = aliasCfg.Delete(opts.Name) err = aliasCfg.Delete(opts.Name)
if err != nil { if err != nil {

View File

@ -25,7 +25,7 @@ func NewCmdList(f *cmdutils.Factory, runF func(*ListOptions) error) *cobra.Comma
IO: f.IO, IO: f.IO,
} }
var aliasListCmd = &cobra.Command{ aliasListCmd := &cobra.Command{
Use: "list [flags]", Use: "list [flags]",
Short: `List the available aliases.`, Short: `List the available aliases.`,
Long: ``, Long: ``,

View File

@ -28,7 +28,7 @@ func NewCmdSet(f *cmdutils.Factory, runF func(*SetOptions) error) *cobra.Command
Config: f.Config, Config: f.Config,
} }
var aliasSetCmd = &cobra.Command{ aliasSetCmd := &cobra.Command{
Use: "set <alias name> '<command>' [flags]", Use: "set <alias name> '<command>' [flags]",
Short: `Set an alias.`, Short: `Set an alias.`,
Long: heredoc.Doc(` Long: heredoc.Doc(`

View File

@ -83,7 +83,6 @@ func TestAliasSet_empty_aliases(t *testing.T) {
`)) `))
output, err := runCommand(cfg, true, "co 'mr checkout'") output, err := runCommand(cfg, true, "co 'mr checkout'")
if err != nil { if err != nil {
t.Fatalf("unexpected error: %s", err) t.Fatalf("unexpected error: %s", err)
} }
@ -135,13 +134,17 @@ func TestAliasSet_arg_processing(t *testing.T) {
{`iz 'issue list'`, "- Adding alias for.*iz.*issue list", "iz: issue list"}, {`iz 'issue list'`, "- Adding alias for.*iz.*issue list", "iz: issue list"},
{`ii 'issue list --author="$1" --label="$2"'`, {
`ii 'issue list --author="$1" --label="$2"'`,
`- Adding alias for.*ii.*issue list --author="\$1" --label="\$2"`, `- Adding alias for.*ii.*issue list --author="\$1" --label="\$2"`,
`ii: issue list --author="\$1" --label="\$2"`}, `ii: issue list --author="\$1" --label="\$2"`,
},
{`ix "issue list --author='\$1' --label='\$2'"`, {
`ix "issue list --author='\$1' --label='\$2'"`,
`- Adding alias for.*ix.*issue list --author='\$1' --label='\$2'`, `- Adding alias for.*ix.*issue list --author='\$1' --label='\$2'`,
`ix: issue list --author='\$1' --label='\$2'`}, `ix: issue list --author='\$1' --label='\$2'`,
},
} }
for _, c := range cases { for _, c := range cases {
@ -198,7 +201,6 @@ view: mr view
test.ExpectLines(t, output.Stderr(), "Adding alias for.*view.*mr view", "Added alias.") test.ExpectLines(t, output.Stderr(), "Adding alias for.*view.*mr view", "Added alias.")
assert.Equal(t, expected, mainBuf.String()) assert.Equal(t, expected, mainBuf.String())
} }
func TestAliasSet_invalid_command(t *testing.T) { func TestAliasSet_invalid_command(t *testing.T) {

View File

@ -104,7 +104,7 @@ func NewCmdApi(f *cmdutils.Factory, runF func(*ApiOptions) error) *cobra.Command
there are no more pages of results. For GraphQL requests, this requires that the there are no more pages of results. For GraphQL requests, this requires that the
original query accepts an '$endCursor: String' variable and that it fetches the original query accepts an '$endCursor: String' variable and that it fetches the
'pageInfo{ hasNextPage, endCursor }' set of fields from a collection. 'pageInfo{ hasNextPage, endCursor }' set of fields from a collection.
`,"`"), `, "`"),
Example: heredoc.Doc(` Example: heredoc.Doc(`
$ glab api projects/:fullpath/releases $ glab api projects/:fullpath/releases

View File

@ -68,7 +68,6 @@ func httpRequest(client *api.Client, config config.Config, hostname string, meth
baseURL, _ = url.Parse(baseURLStr) baseURL, _ = url.Parse(baseURLStr)
req, err := api.NewHTTPRequest(client, method, baseURL, body, headers, bodyIsJSON) req, err := api.NewHTTPRequest(client, method, baseURL, body, headers, bodyIsJSON)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -100,7 +100,7 @@ hosts:
if envIsSet && originalEnvVarToken != "" { if envIsSet && originalEnvVarToken != "" {
_ = os.Setenv("GITLAB_TOKEN", "") _ = os.Setenv("GITLAB_TOKEN", "")
} }
var client = &http.Client{} client := &http.Client{}
client.Transport = roundTripFunc(func(req *http.Request) (*http.Response, error) { client.Transport = roundTripFunc(func(req *http.Request) (*http.Response, error) {
t.Log("Tsti") t.Log("Tsti")
return &http.Response{ return &http.Response{

View File

@ -137,7 +137,6 @@ func loginRun() error {
"GitLab Self-hosted Instance", "GitLab Self-hosted Instance",
}, },
}, &hostType) }, &hostType)
if err != nil { if err != nil {
return fmt.Errorf("could not prompt: %w", err) return fmt.Errorf("could not prompt: %w", err)
} }

View File

@ -282,7 +282,6 @@ git_protocol: ssh
IO: io, IO: io,
} }
t.Run("no instance authenticated", func(t *testing.T) { t.Run("no instance authenticated", func(t *testing.T) {
err := statusRun(opts) err := statusRun(opts)
assert.Equal(t, err, cmdutils.SilentError) assert.Equal(t, err, cmdutils.SilentError)
assert.Equal(t, stdout.String(), "") assert.Equal(t, stdout.String(), "")

View File

@ -15,7 +15,7 @@ import (
) )
func NewCmdRun(f *cmdutils.Factory) *cobra.Command { func NewCmdRun(f *cmdutils.Factory) *cobra.Command {
var jobArtifactCmd = &cobra.Command{ jobArtifactCmd := &cobra.Command{
Use: "artifact <refName> <jobName> [flags]", Use: "artifact <refName> <jobName> [flags]",
Short: `Download all Artifacts from the last pipeline`, Short: `Download all Artifacts from the last pipeline`,
Aliases: []string{"push"}, Aliases: []string{"push"},
@ -26,7 +26,6 @@ func NewCmdRun(f *cmdutils.Factory) *cobra.Command {
Long: ``, Long: ``,
Args: cobra.ExactArgs(2), Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
repo, err := f.BaseRepo() repo, err := f.BaseRepo()
if err != nil { if err != nil {
return err return err
@ -51,7 +50,7 @@ func NewCmdRun(f *cmdutils.Factory) *cobra.Command {
} }
if !config.CheckPathExists(path) { if !config.CheckPathExists(path) {
if err := os.Mkdir(path, 0755); err != nil { if err := os.Mkdir(path, 0o755); err != nil {
return err return err
} }
} }

View File

@ -18,7 +18,7 @@ import (
) )
func NewCmdCI(f *cmdutils.Factory) *cobra.Command { func NewCmdCI(f *cmdutils.Factory) *cobra.Command {
var ciCmd = &cobra.Command{ ciCmd := &cobra.Command{
Use: "ci <command> [flags]", Use: "ci <command> [flags]",
Short: `Work with GitLab CI pipelines and jobs`, Short: `Work with GitLab CI pipelines and jobs`,
Long: ``, Long: ``,

View File

@ -31,5 +31,4 @@ func TestPipelineCmd(t *testing.T) {
out := <-outC out := <-outC
assert.Contains(t, out, "Use \"ci [command] --help\" for more information about a command.\n") assert.Contains(t, out, "Use \"ci [command] --help\" for more information about a command.\n")
} }

View File

@ -15,7 +15,7 @@ import (
) )
func NewCmdDelete(f *cmdutils.Factory) *cobra.Command { func NewCmdDelete(f *cmdutils.Factory) *cobra.Command {
var pipelineDeleteCmd = &cobra.Command{ pipelineDeleteCmd := &cobra.Command{
Use: "delete <id> [flags]", Use: "delete <id> [flags]",
Short: `Delete a CI pipeline`, Short: `Delete a CI pipeline`,
Example: heredoc.Doc(` Example: heredoc.Doc(`
@ -25,7 +25,6 @@ func NewCmdDelete(f *cmdutils.Factory) *cobra.Command {
Long: ``, Long: ``,
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
var err error var err error
c := f.IO.Color() c := f.IO.Color()
apiClient, err := f.HttpClient() apiClient, err := f.HttpClient()
@ -71,7 +70,6 @@ func NewCmdDelete(f *cmdutils.Factory) *cobra.Command {
} }
return nil return nil
}, },
} }

View File

@ -22,7 +22,7 @@ type PipelineMergedResponse struct {
} }
func NewCmdGet(f *cmdutils.Factory) *cobra.Command { func NewCmdGet(f *cmdutils.Factory) *cobra.Command {
var pipelineGetCmd = &cobra.Command{ pipelineGetCmd := &cobra.Command{
Use: "get [flags]", Use: "get [flags]",
Short: `Get JSON of a running CI pipeline on current or other branch specified`, Short: `Get JSON of a running CI pipeline on current or other branch specified`,
Aliases: []string{"stats"}, Aliases: []string{"stats"},
@ -64,7 +64,14 @@ func NewCmdGet(f *cmdutils.Factory) *cobra.Command {
} }
jobs, err := api.GetPipelineJobs(apiClient, pipelineId, repo.FullName()) jobs, err := api.GetPipelineJobs(apiClient, pipelineId, repo.FullName())
if err != nil {
return err
}
variables, err := api.GetPipelineVariables(apiClient, pipelineId, nil, repo.FullName()) variables, err := api.GetPipelineVariables(apiClient, pipelineId, nil, repo.FullName())
if err != nil {
return err
}
mergedPipelineObject := &PipelineMergedResponse{ mergedPipelineObject := &PipelineMergedResponse{
Pipeline: pipeline, Pipeline: pipeline,

View File

@ -14,7 +14,7 @@ import (
) )
func NewCmdCI(f *cmdutils.Factory) *cobra.Command { func NewCmdCI(f *cmdutils.Factory) *cobra.Command {
var pipelineCICmd = &cobra.Command{ pipelineCICmd := &cobra.Command{
Use: "ci <command> [flags]", Use: "ci <command> [flags]",
Short: `Work with GitLab CI pipelines and jobs`, Short: `Work with GitLab CI pipelines and jobs`,
Example: heredoc.Doc(` Example: heredoc.Doc(`

View File

@ -30,5 +30,4 @@ func TestNewCmdCI(t *testing.T) {
assert.Contains(t, stdout.String(), "Work with GitLab CI pipelines and jobs\n") assert.Contains(t, stdout.String(), "Work with GitLab CI pipelines and jobs\n")
assert.Contains(t, stderr.String(), "") assert.Contains(t, stderr.String(), "")
assert.Contains(t, stdout.String(), "This command is deprecated. All the commands under it has been moved to `ci` or `pipeline` command. See https://gitlab.com/gitlab-org/cli/issues/372 for more info.\n") assert.Contains(t, stdout.String(), "This command is deprecated. All the commands under it has been moved to `ci` or `pipeline` command. See https://gitlab.com/gitlab-org/cli/issues/372 for more info.\n")
} }

View File

@ -17,7 +17,7 @@ import (
) )
func NewCmdLint(f *cmdutils.Factory) *cobra.Command { func NewCmdLint(f *cmdutils.Factory) *cobra.Command {
var pipelineCILintCmd = &cobra.Command{ pipelineCILintCmd := &cobra.Command{
Use: "lint", Use: "lint",
Short: "Checks if your `.gitlab-ci.yml` file is valid.", Short: "Checks if your `.gitlab-ci.yml` file is valid.",
Args: cobra.MaximumNArgs(1), Args: cobra.MaximumNArgs(1),

View File

@ -14,7 +14,7 @@ import (
) )
func NewCmdList(f *cmdutils.Factory) *cobra.Command { func NewCmdList(f *cmdutils.Factory) *cobra.Command {
var pipelineListCmd = &cobra.Command{ pipelineListCmd := &cobra.Command{
Use: "list [flags]", Use: "list [flags]",
Short: `Get the list of CI pipelines`, Short: `Get the list of CI pipelines`,
Example: heredoc.Doc(` Example: heredoc.Doc(`

View File

@ -12,7 +12,7 @@ import (
) )
func NewCmdRetry(f *cmdutils.Factory) *cobra.Command { func NewCmdRetry(f *cmdutils.Factory) *cobra.Command {
var pipelineRetryCmd = &cobra.Command{ pipelineRetryCmd := &cobra.Command{
Use: "retry <job-id>", Use: "retry <job-id>",
Short: `Retry a CI job`, Short: `Retry a CI job`,
Aliases: []string{}, Aliases: []string{},
@ -48,7 +48,6 @@ func NewCmdRetry(f *cmdutils.Factory) *cobra.Command {
fmt.Fprintln(f.IO.StdOut, "Retried job (id:", job.ID, "), status:", job.Status, ", ref:", job.Ref, ", weburl: ", job.WebURL, ")") fmt.Fprintln(f.IO.StdOut, "Retried job (id:", job.ID, "), status:", job.Status, ", ref:", job.Ref, ", weburl: ", job.WebURL, ")")
return nil return nil
}, },
} }

View File

@ -85,7 +85,7 @@ func extractFileVar(s string) (*gitlab.PipelineVariableOptions, error) {
} }
func NewCmdRun(f *cmdutils.Factory) *cobra.Command { func NewCmdRun(f *cmdutils.Factory) *cobra.Command {
var pipelineRunCmd = &cobra.Command{ pipelineRunCmd := &cobra.Command{
Use: "run [flags]", Use: "run [flags]",
Short: `Create or run a new CI pipeline`, Short: `Create or run a new CI pipeline`,
Aliases: []string{"create"}, Aliases: []string{"create"},

View File

@ -17,7 +17,7 @@ import (
) )
func NewCmdStatus(f *cmdutils.Factory) *cobra.Command { func NewCmdStatus(f *cmdutils.Factory) *cobra.Command {
var pipelineStatusCmd = &cobra.Command{ pipelineStatusCmd := &cobra.Command{
Use: "status [flags]", Use: "status [flags]",
Short: `View a running CI pipeline on current or other branch specified`, Short: `View a running CI pipeline on current or other branch specified`,
Aliases: []string{"stats"}, Aliases: []string{"stats"},
@ -96,7 +96,7 @@ func NewCmdStatus(f *cmdutils.Factory) *cobra.Command {
default: default:
status = c.Gray(s) status = c.Gray(s)
} }
//fmt.Println(job.Tag) // fmt.Println(job.Tag)
if compact { if compact {
fmt.Fprintf(writer, "(%s) • %s [%s]\n", status, job.Name, job.Stage) fmt.Fprintf(writer, "(%s) • %s [%s]\n", status, job.Name, job.Stage)
} else { } else {

View File

@ -37,7 +37,7 @@ func NewCmdTrace(f *cmdutils.Factory, runE func(traceOpts *TraceOpts) error) *co
opts := &TraceOpts{ opts := &TraceOpts{
IO: f.IO, IO: f.IO,
} }
var pipelineCITraceCmd = &cobra.Command{ pipelineCITraceCmd := &cobra.Command{
Use: "trace [<job-id>] [flags]", Use: "trace [<job-id>] [flags]",
Short: `Trace a CI job log in real time`, Short: `Trace a CI job log in real time`,
Example: heredoc.Doc(` Example: heredoc.Doc(`

View File

@ -116,7 +116,6 @@ hosts:
assert.Equal(t, tt.wantOpts.IO, actualOpts.IO) assert.Equal(t, tt.wantOpts.IO, actualOpts.IO)
}) })
} }
} }
func TestTraceRun(t *testing.T) { func TestTraceRun(t *testing.T) {
@ -182,5 +181,4 @@ func TestTraceRun(t *testing.T) {
tt.assertContains(t, stdout.String()) tt.assertContains(t, stdout.String())
}) })
} }
} }

View File

@ -24,6 +24,9 @@ import (
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/xanzy/go-gitlab" "github.com/xanzy/go-gitlab"
"golang.org/x/text/cases"
"golang.org/x/text/language"
) )
type ViewOpts struct { type ViewOpts struct {
@ -38,7 +41,7 @@ type ViewOpts struct {
func NewCmdView(f *cmdutils.Factory) *cobra.Command { func NewCmdView(f *cmdutils.Factory) *cobra.Command {
opts := ViewOpts{} opts := ViewOpts{}
var pipelineCIView = &cobra.Command{ pipelineCIView := &cobra.Command{
Use: "view [branch/tag]", Use: "view [branch/tag]",
Short: "View, run, trace/logs, and cancel CI jobs current pipeline", Short: "View, run, trace/logs, and cancel CI jobs current pipeline",
Long: heredoc.Doc(`Supports viewing, running, tracing, and canceling jobs. Long: heredoc.Doc(`Supports viewing, running, tracing, and canceling jobs.
@ -448,7 +451,8 @@ func jobsView(app *tview.Application, jobsCh chan []*gitlab.Job, inputCh chan st
x, y, w, h := boxX, maxY/6-4, maxTitle+2, 3 x, y, w, h := boxX, maxY/6-4, maxTitle+2, 3
b := box(root, key, x, y, w, h) b := box(root, key, x, y, w, h)
b.SetText(strings.Title(j.Stage)) caser := cases.Title(language.English)
b.SetText(caser.String(j.Stage))
b.SetTextAlign(tview.AlignCenter) b.SetTextAlign(tview.AlignCenter)
} }
@ -525,8 +529,8 @@ func jobsView(app *tview.Application, jobsCh chan []*gitlab.Job, inputCh chan st
} }
root.SendToFront("jobs-" + curJob.Name) root.SendToFront("jobs-" + curJob.Name)
} }
func box(root *tview.Pages, key string, x, y, w, h int) *tview.TextView { func box(root *tview.Pages, key string, x, y, w, h int) *tview.TextView {
b, ok := boxes[key] b, ok := boxes[key]
if !ok { if !ok {

View File

@ -23,7 +23,7 @@ func assertScreen(t *testing.T, screen tcell.Screen, expected []string) {
r, _, _, _ := screen.GetContent(x, y) r, _, _, _ := screen.GetContent(x, y)
runes[x] = r runes[x] = r
_ = expectedRune _ = expectedRune
//assert.Equal(t, expectedRune, r, "%s != %s at (%d,%d)", // assert.Equal(t, expectedRune, r, "%s != %s at (%d,%d)",
// strconv.QuoteRune(expectedRune), strconv.QuoteRune(r), x, y) // strconv.QuoteRune(expectedRune), strconv.QuoteRune(r), x, y)
} }
@ -411,7 +411,6 @@ func Test_LinkJobsNegative(t *testing.T) {
t.Run(test.desc, func(t *testing.T) { t.Run(test.desc, func(t *testing.T) {
t.Parallel() t.Parallel()
assert.Error(t, linkJobs(screen, test.jobs, test.boxes)) assert.Error(t, linkJobs(screen, test.jobs, test.boxes))
}) })
} }
} }

View File

@ -95,7 +95,7 @@ func InitTest(m *testing.M, suffix string) {
} }
func RunCommand(cmd *cobra.Command, cli string, stds ...*bytes.Buffer) (*test.CmdOut, error) { func RunCommand(cmd *cobra.Command, cli string, stds ...*bytes.Buffer) (*test.CmdOut, error) {
//var stdin *bytes.Buffer // var stdin *bytes.Buffer
var stderr *bytes.Buffer var stderr *bytes.Buffer
var stdout *bytes.Buffer var stdout *bytes.Buffer

View File

@ -465,7 +465,6 @@ func (ua *UserAssignments) UsersFromAddRemove(
apiClient *gitlab.Client, apiClient *gitlab.Client,
actions []string, actions []string,
) (*[]int, []string, error) { ) (*[]int, []string, error) {
var assignedIDs []int var assignedIDs []int
var usernames []string var usernames []string

View File

@ -83,7 +83,6 @@ func Test_ParseAssignees(t *testing.T) {
assert.ElementsMatch(t, uaGot.ToReplace, tC.wantReplace) assert.ElementsMatch(t, uaGot.ToReplace, tC.wantReplace)
}) })
} }
} }
func Test_VerifyAssignees(t *testing.T) { func Test_VerifyAssignees(t *testing.T) {
@ -743,7 +742,6 @@ func Test_AssigneesPrompt(t *testing.T) {
assert.Equal(t, tC.expectedStdErr, outErr) assert.Equal(t, tC.expectedStdErr, outErr)
} }
assert.ElementsMatch(t, got, tC.output) assert.ElementsMatch(t, got, tC.output)
}) })
} }
@ -1114,8 +1112,8 @@ func Test_LabelsPromptPromptsFail(t *testing.T) {
assert.Nil(t, got) assert.Nil(t, got)
assert.EqualError(t, err, "AskQuestionWithInput prompt failed") assert.EqualError(t, err, "AskQuestionWithInput prompt failed")
}) })
} }
func Test_LabelsPromptMultiSelect(t *testing.T) { func Test_LabelsPromptMultiSelect(t *testing.T) {
// mock glrepo.Remote object // mock glrepo.Remote object
repo := glrepo.New("foo", "bar") repo := glrepo.New("foo", "bar")
@ -1380,5 +1378,4 @@ func TestListGitLabTemplates(t *testing.T) {
assert.EqualValues(t, test.wantTemplates, gotTemplates, "Templates got didn't match") assert.EqualValues(t, test.wantTemplates, gotTemplates, "Templates got didn't match")
}) })
} }
} }

View File

@ -107,7 +107,6 @@ func HTTPClientFactory(f *Factory) {
} }
func NewFactory() *Factory { func NewFactory() *Factory {
return &Factory{ return &Factory{
Config: configFunc, Config: configFunc,
Remotes: remotesFunc, Remotes: remotesFunc,

View File

@ -17,7 +17,7 @@ func NewCmdCompletion(io *iostreams.IOStreams) *cobra.Command {
excludeDesc = false excludeDesc = false
) )
var completionCmd = &cobra.Command{ completionCmd := &cobra.Command{
Use: "completion", Use: "completion",
Short: "Generate shell completion scripts", Short: "Generate shell completion scripts",
Long: heredoc.Docf(` Long: heredoc.Docf(`

View File

@ -147,7 +147,7 @@ func NewCmdConfigInit(f *cmdutils.Factory) *cobra.Command {
$ glab config init $ glab config init
? Enter default GitLab Host (Current Value: https://gitlab.com): ? Enter default GitLab Host (Current Value: https://gitlab.com):
%[1]s %[1]s
`,"```"), `, "```"),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return configInit(f) return configInit(f)
}, },

View File

@ -8,7 +8,7 @@ import (
) )
func NewCmdBoard(f *cmdutils.Factory) *cobra.Command { func NewCmdBoard(f *cmdutils.Factory) *cobra.Command {
var issueCmd = &cobra.Command{ issueCmd := &cobra.Command{
Use: "board [command] [flags]", Use: "board [command] [flags]",
Short: `Work with GitLab Issue Boards in the given project.`, Short: `Work with GitLab Issue Boards in the given project.`,
Long: ``, Long: ``,

View File

@ -14,7 +14,7 @@ import (
var boardName string var boardName string
func NewCmdCreate(f *cmdutils.Factory) *cobra.Command { func NewCmdCreate(f *cmdutils.Factory) *cobra.Command {
var issueCmd = &cobra.Command{ issueCmd := &cobra.Command{
Use: "create [flags]", Use: "create [flags]",
Short: `Create a project issue board.`, Short: `Create a project issue board.`,
Long: ``, Long: ``,

View File

@ -76,7 +76,6 @@ func TestNewCmdCreate(t *testing.T) {
assert.Contains(t, out, tc.want) assert.Contains(t, out, tc.want)
assert.Contains(t, stderr.String(), "") assert.Contains(t, stderr.String(), "")
}) })
} }
} }

View File

@ -14,6 +14,9 @@ import (
"gitlab.com/gitlab-org/cli/api" "gitlab.com/gitlab-org/cli/api"
"gitlab.com/gitlab-org/cli/commands/cmdutils" "gitlab.com/gitlab-org/cli/commands/cmdutils"
"gitlab.com/gitlab-org/cli/internal/glrepo" "gitlab.com/gitlab-org/cli/internal/glrepo"
"golang.org/x/text/cases"
"golang.org/x/text/language"
) )
var ( var (
@ -22,8 +25,10 @@ var (
repo glrepo.Interface repo glrepo.Interface
) )
const closed string = "closed" const (
const opened string = "opened" closed string = "closed"
opened string = "opened"
)
type issueBoardViewOptions struct { type issueBoardViewOptions struct {
assignee string assignee string
@ -40,8 +45,8 @@ type boardMeta struct {
} }
func NewCmdView(f *cmdutils.Factory) *cobra.Command { func NewCmdView(f *cmdutils.Factory) *cobra.Command {
var opts = &issueBoardViewOptions{} opts := &issueBoardViewOptions{}
var viewCmd = &cobra.Command{ viewCmd := &cobra.Command{
Use: "view [flags]", Use: "view [flags]",
Short: `View project issue board.`, Short: `View project issue board.`,
Long: ``, Long: ``,
@ -149,16 +154,17 @@ func NewCmdView(f *cmdutils.Factory) *cobra.Command {
} }
// format table title // format table title
caser := cases.Title(language.English)
var boardType, boardContext string var boardType, boardContext string
if selectedBoard.group != nil { if selectedBoard.group != nil {
boardType = strings.Title("group") boardType = caser.String("group")
boardContext = project.Namespace.Name boardContext = project.Namespace.Name
} else { } else {
boardType = strings.Title("project") boardType = caser.String("project")
boardContext = project.NameWithNamespace boardContext = project.NameWithNamespace
} }
root.SetBorderPadding(1, 1, 2, 2).SetBorder(true).SetTitle( root.SetBorderPadding(1, 1, 2, 2).SetBorder(true).SetTitle(
fmt.Sprintf(" %s • %s ", strings.Title(boardType+" issue board"), boardContext), fmt.Sprintf(" %s • %s ", caser.String(boardType+" issue board"), boardContext),
) )
screen, err := tcell.NewScreen() screen, err := tcell.NewScreen()
@ -245,7 +251,7 @@ func buildLabelString(labelDetails []*gitlab.LabelDetails) string {
labels += fmt.Sprintf("[white:%s:-]%s[white:-:-] ", ld.Color, ld.Name) labels += fmt.Sprintf("[white:%s:-]%s[white:-:-] ", ld.Color, ld.Name)
} }
if labels != "" { if labels != "" {
labels = strings.TrimSpace(labels) + fmt.Sprintf("\n") labels = strings.TrimSpace(labels) + "\n"
} }
return labels return labels
} }
@ -269,7 +275,6 @@ func mapBoardData(
projectIssueBoards []*gitlab.IssueBoard, projectIssueBoards []*gitlab.IssueBoard,
projectGroupIssueBoards []*gitlab.GroupIssueBoard, projectGroupIssueBoards []*gitlab.GroupIssueBoard,
) ([]string, map[string]boardMeta) { ) ([]string, map[string]boardMeta) {
// find longest board name to base padding on // find longest board name to base padding on
maxNameLength := 0 maxNameLength := 0
for _, board := range projectIssueBoards { for _, board := range projectIssueBoards {

View File

@ -13,7 +13,7 @@ import (
) )
func NewCmdClose(f *cmdutils.Factory) *cobra.Command { func NewCmdClose(f *cmdutils.Factory) *cobra.Command {
var issueCloseCmd = &cobra.Command{ issueCloseCmd := &cobra.Command{
Use: "close <id>", Use: "close <id>",
Short: `Close an issue`, Short: `Close an issue`,
Long: ``, Long: ``,

View File

@ -60,7 +60,6 @@ func Test_issueClose(t *testing.T) {
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.Name, func(t *testing.T) { t.Run(tc.Name, func(t *testing.T) {
io, _, stdout, stderr := iostreams.Test() io, _, stdout, stderr := iostreams.Test()
f := cmdtest.StubFactory("https://gitlab.com/glab-cli/test") f := cmdtest.StubFactory("https://gitlab.com/glab-cli/test")
f.IO = io f.IO = io
@ -81,7 +80,7 @@ func Test_issueClose(t *testing.T) {
} }
out := stripansi.Strip(stdout.String()) out := stripansi.Strip(stdout.String())
//outErr := stripansi.Strip(stderr.String()) // outErr := stripansi.Strip(stderr.String())
for _, msg := range tc.ExpectedMsg { for _, msg := range tc.ExpectedMsg {
assert.Contains(t, out, msg) assert.Contains(t, out, msg)

View File

@ -61,7 +61,7 @@ func NewCmdCreate(f *cmdutils.Factory) *cobra.Command {
Remotes: f.Remotes, Remotes: f.Remotes,
Config: f.Config, Config: f.Config,
} }
var issueCreateCmd = &cobra.Command{ issueCreateCmd := &cobra.Command{
Use: "create [flags]", Use: "create [flags]",
Short: `Create an issue`, Short: `Create an issue`,
Long: ``, Long: ``,

View File

@ -64,7 +64,8 @@ func Test_IssueCreate(t *testing.T) {
cmd := NewCmdCreate(f) cmd := NewCmdCreate(f)
cmd.Flags().StringP("repo", "R", "", "") cmd.Flags().StringP("repo", "R", "", "")
cliStr := []string{"-t", "myissuetitle", cliStr := []string{
"-t", "myissuetitle",
"-d", "myissuebody", "-d", "myissuebody",
"-l", "test,bug", "-l", "test,bug",
"--weight", "1", "--weight", "1",

View File

@ -12,7 +12,7 @@ import (
) )
func NewCmdDelete(f *cmdutils.Factory) *cobra.Command { func NewCmdDelete(f *cmdutils.Factory) *cobra.Command {
var issueDeleteCmd = &cobra.Command{ issueDeleteCmd := &cobra.Command{
Use: "delete <id>", Use: "delete <id>",
Short: `Delete an issue`, Short: `Delete an issue`,
Long: ``, Long: ``,

View File

@ -68,7 +68,6 @@ func TestNewCmdDelete(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
io, _, stdout, stderr := iostreams.Test() io, _, stdout, stderr := iostreams.Test()
f := cmdtest.StubFactory("") f := cmdtest.StubFactory("")
f.IO = io f.IO = io

View File

@ -19,7 +19,7 @@ import (
) )
func NewCmdIssue(f *cmdutils.Factory) *cobra.Command { func NewCmdIssue(f *cmdutils.Factory) *cobra.Command {
var issueCmd = &cobra.Command{ issueCmd := &cobra.Command{
Use: "issue [command] [flags]", Use: "issue [command] [flags]",
Short: `Work with GitLab issues`, Short: `Work with GitLab issues`,
Long: ``, Long: ``,

View File

@ -100,7 +100,6 @@ func IssuesFromArgs(apiClient *gitlab.Client, baseRepoFn func() (glrepo.Interfac
return nil, nil, err return nil, nil, err
} }
return issues, baseRepo, nil return issues, baseRepo, nil
} }
func IssueFromArg(apiClient *gitlab.Client, baseRepoFn func() (glrepo.Interface, error), arg string) (*gitlab.Issue, glrepo.Interface, error) { func IssueFromArg(apiClient *gitlab.Client, baseRepoFn func() (glrepo.Interface, error), arg string) (*gitlab.Issue, glrepo.Interface, error) {
@ -139,8 +138,10 @@ func IssueFromArg(apiClient *gitlab.Client, baseRepoFn func() (glrepo.Interface,
// //
// OWNER/REPO/issues/id // OWNER/REPO/issues/id
// GROUP/NAMESPACE/REPO/issues/id // GROUP/NAMESPACE/REPO/issues/id
var issueURLPersonalRE = regexp.MustCompile(`^/([^/]+)/([^/]+)/issues/(\d+)`) var (
var issueURLGroupRE = regexp.MustCompile(`^/([^/]+)/([^/]+)/([^/]+)/issues/(\d+)`) issueURLPersonalRE = regexp.MustCompile(`^/([^/]+)/([^/]+)/issues/(\d+)`)
issueURLGroupRE = regexp.MustCompile(`^/([^/]+)/([^/]+)/([^/]+)/issues/(\d+)`)
)
func issueMetadataFromURL(s string) (int, glrepo.Interface) { func issueMetadataFromURL(s string) (int, glrepo.Interface) {
u, err := url.Parse(s) u, err := url.Parse(s)

View File

@ -56,11 +56,11 @@ type ListOptions struct {
} }
func NewCmdList(f *cmdutils.Factory, runE func(opts *ListOptions) error) *cobra.Command { func NewCmdList(f *cmdutils.Factory, runE func(opts *ListOptions) error) *cobra.Command {
var opts = &ListOptions{ opts := &ListOptions{
IO: f.IO, IO: f.IO,
} }
var issueListCmd = &cobra.Command{ issueListCmd := &cobra.Command{
Use: "list [flags]", Use: "list [flags]",
Short: `List project issues`, Short: `List project issues`,
Long: ``, Long: ``,

View File

@ -208,7 +208,6 @@ func TestIssueList_tty_withIssueType(t *testing.T) {
func TestIssueList_tty_mine(t *testing.T) { func TestIssueList_tty_mine(t *testing.T) {
t.Run("mine with all flag and user exists", func(t *testing.T) { t.Run("mine with all flag and user exists", func(t *testing.T) {
fakeHTTP := httpmock.New() fakeHTTP := httpmock.New()
defer fakeHTTP.Verify(t) defer fakeHTTP.Verify(t)
@ -230,7 +229,6 @@ func TestIssueList_tty_mine(t *testing.T) {
`) `)
}) })
t.Run("user does not exists", func(t *testing.T) { t.Run("user does not exists", func(t *testing.T) {
fakeHTTP := httpmock.New() fakeHTTP := httpmock.New()
defer fakeHTTP.Verify(t) defer fakeHTTP.Verify(t)

View File

@ -15,7 +15,7 @@ import (
) )
func NewCmdNote(f *cmdutils.Factory) *cobra.Command { func NewCmdNote(f *cmdutils.Factory) *cobra.Command {
var issueNoteCreateCmd = &cobra.Command{ issueNoteCreateCmd := &cobra.Command{
Use: "note <issue-id>", Use: "note <issue-id>",
Aliases: []string{"comment"}, Aliases: []string{"comment"},
Short: "Add a comment or note to an issue on GitLab", Short: "Add a comment or note to an issue on GitLab",

View File

@ -72,7 +72,6 @@ func Test_NewCmdNote(t *testing.T) {
defer fakeHTTP.Verify(t) defer fakeHTTP.Verify(t)
t.Run("--message flag specified", func(t *testing.T) { t.Run("--message flag specified", func(t *testing.T) {
fakeHTTP.RegisterResponder("POST", "/projects/OWNER/REPO/issues/1/notes", fakeHTTP.RegisterResponder("POST", "/projects/OWNER/REPO/issues/1/notes",
httpmock.NewStringResponse(201, ` httpmock.NewStringResponse(201, `
{ {
@ -153,7 +152,6 @@ func Test_mrNoteCreate_prompt(t *testing.T) {
defer fakeHTTP.Verify(t) defer fakeHTTP.Verify(t)
t.Run("message provided", func(t *testing.T) { t.Run("message provided", func(t *testing.T) {
fakeHTTP.RegisterResponder("POST", "/projects/OWNER/REPO/issues/1/notes", fakeHTTP.RegisterResponder("POST", "/projects/OWNER/REPO/issues/1/notes",
httpmock.NewStringResponse(201, ` httpmock.NewStringResponse(201, `
{ {
@ -190,7 +188,6 @@ func Test_mrNoteCreate_prompt(t *testing.T) {
}) })
t.Run("message is empty", func(t *testing.T) { t.Run("message is empty", func(t *testing.T) {
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/issues/1", fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/issues/1",
httpmock.NewStringResponse(200, ` httpmock.NewStringResponse(200, `
{ {

View File

@ -13,7 +13,7 @@ import (
) )
func NewCmdReopen(f *cmdutils.Factory) *cobra.Command { func NewCmdReopen(f *cmdutils.Factory) *cobra.Command {
var issueReopenCmd = &cobra.Command{ issueReopenCmd := &cobra.Command{
Use: "reopen <id>", Use: "reopen <id>",
Short: `Reopen a closed issue`, Short: `Reopen a closed issue`,
Long: ``, Long: ``,
@ -30,7 +30,6 @@ func NewCmdReopen(f *cmdutils.Factory) *cobra.Command {
c := f.IO.Color() c := f.IO.Color()
apiClient, err := f.HttpClient() apiClient, err := f.HttpClient()
if err != nil { if err != nil {
return err return err
} }

View File

@ -11,7 +11,7 @@ import (
) )
func NewCmdSubscribe(f *cmdutils.Factory) *cobra.Command { func NewCmdSubscribe(f *cmdutils.Factory) *cobra.Command {
var issueSubscribeCmd = &cobra.Command{ issueSubscribeCmd := &cobra.Command{
Use: "subscribe <id>", Use: "subscribe <id>",
Short: `Subscribe to an issue`, Short: `Subscribe to an issue`,
Long: ``, Long: ``,

View File

@ -12,7 +12,7 @@ import (
) )
func NewCmdUnsubscribe(f *cmdutils.Factory) *cobra.Command { func NewCmdUnsubscribe(f *cmdutils.Factory) *cobra.Command {
var issueUnsubscribeCmd = &cobra.Command{ issueUnsubscribeCmd := &cobra.Command{
Use: "unsubscribe <id>", Use: "unsubscribe <id>",
Short: `Unsubscribe to an issue`, Short: `Unsubscribe to an issue`,
Long: ``, Long: ``,

View File

@ -15,7 +15,7 @@ import (
) )
func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command {
var issueUpdateCmd = &cobra.Command{ issueUpdateCmd := &cobra.Command{
Use: "update <id>", Use: "update <id>",
Short: `Update issue`, Short: `Update issue`,
Long: ``, Long: ``,

View File

@ -102,7 +102,6 @@ func TestNewCmdUpdate(t *testing.T) {
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.Name, func(t *testing.T) { t.Run(tc.Name, func(t *testing.T) {
args, _ := shlex.Split(tc.Issue) args, _ := shlex.Split(tc.Issue)
cmd.SetArgs(args) cmd.SetArgs(args)
cmd.SetOut(ioutil.Discard) cmd.SetOut(ioutil.Discard)

View File

@ -36,7 +36,7 @@ func NewCmdView(f *cmdutils.Factory) *cobra.Command {
opts := &ViewOpts{ opts := &ViewOpts{
IO: f.IO, IO: f.IO,
} }
var issueViewCmd = &cobra.Command{ issueViewCmd := &cobra.Command{
Use: "view <id>", Use: "view <id>",
Short: `Display the title, body, and other information about an issue.`, Short: `Display the title, body, and other information about an issue.`,
Long: ``, Long: ``,
@ -50,7 +50,6 @@ func NewCmdView(f *cmdutils.Factory) *cobra.Command {
`), `),
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
apiClient, err := f.HttpClient() apiClient, err := f.HttpClient()
if err != nil { if err != nil {
return err return err
@ -64,7 +63,7 @@ func NewCmdView(f *cmdutils.Factory) *cobra.Command {
opts.Issue = issue opts.Issue = issue
//open in browser if --web flag is specified // open in browser if --web flag is specified
if opts.Web { if opts.Web {
if f.IO.IsaTTY && f.IO.IsErrTTY { if f.IO.IsaTTY && f.IO.IsErrTTY {
fmt.Fprintf(opts.IO.StdErr, "Opening %s in your browser.\n", utils.DisplayURL(opts.Issue.WebURL)) fmt.Fprintf(opts.IO.StdErr, "Opening %s in your browser.\n", utils.DisplayURL(opts.Issue.WebURL))

View File

@ -151,7 +151,6 @@ func TestNewCmdView(t *testing.T) {
} }
t.Run("show", func(t *testing.T) { t.Run("show", func(t *testing.T) {
cmd := NewCmdView(stubFactory) cmd := NewCmdView(stubFactory)
cmdutils.EnableRepoOverride(cmd, stubFactory) cmdutils.EnableRepoOverride(cmd, stubFactory)
_, err := cmdtest.RunCommand(cmd, "13 -c -s -R glab-cli/test") _, err := cmdtest.RunCommand(cmd, "13 -c -s -R glab-cli/test")

View File

@ -12,7 +12,7 @@ import (
) )
func NewCmdCreate(f *cmdutils.Factory) *cobra.Command { func NewCmdCreate(f *cmdutils.Factory) *cobra.Command {
var labelCreateCmd = &cobra.Command{ labelCreateCmd := &cobra.Command{
Use: "create [flags]", Use: "create [flags]",
Short: `Create labels for repository/project`, Short: `Create labels for repository/project`,
Long: ``, Long: ``,
@ -24,7 +24,6 @@ func NewCmdCreate(f *cmdutils.Factory) *cobra.Command {
`), `),
Args: cobra.ExactArgs(0), Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
var err error var err error
apiClient, err := f.HttpClient() apiClient, err := f.HttpClient()

View File

@ -8,7 +8,7 @@ import (
) )
func NewCmdLabel(f *cmdutils.Factory) *cobra.Command { func NewCmdLabel(f *cmdutils.Factory) *cobra.Command {
var labelCmd = &cobra.Command{ labelCmd := &cobra.Command{
Use: "label <command> [flags]", Use: "label <command> [flags]",
Short: `Manage labels on remote`, Short: `Manage labels on remote`,
Long: ``, Long: ``,

View File

@ -14,7 +14,7 @@ import (
) )
func NewCmdList(f *cmdutils.Factory) *cobra.Command { func NewCmdList(f *cmdutils.Factory) *cobra.Command {
var labelListCmd = &cobra.Command{ labelListCmd := &cobra.Command{
Use: "list [flags]", Use: "list [flags]",
Short: `List labels in repository`, Short: `List labels in repository`,
Long: ``, Long: ``,
@ -76,7 +76,6 @@ func NewCmdList(f *cmdutils.Factory) *cobra.Command {
//} //}
return nil return nil
}, },
} }

View File

@ -12,7 +12,7 @@ import (
) )
func NewCmdApprove(f *cmdutils.Factory) *cobra.Command { func NewCmdApprove(f *cmdutils.Factory) *cobra.Command {
var mrApproveCmd = &cobra.Command{ mrApproveCmd := &cobra.Command{
Use: "approve {<id> | <branch>}", Use: "approve {<id> | <branch>}",
Short: `Approve merge requests`, Short: `Approve merge requests`,
Long: ``, Long: ``,
@ -63,7 +63,7 @@ func NewCmdApprove(f *cmdutils.Factory) *cobra.Command {
}, },
} }
//mrApproveCmd.Flags().StringP("password", "p", "", "Current users password. Required if 'Require user password to approve' is enabled in the project settings.") // mrApproveCmd.Flags().StringP("password", "p", "", "Current users password. Required if 'Require user password to approve' is enabled in the project settings.")
mrApproveCmd.Flags().StringP("sha", "s", "", "SHA which must match the SHA of the HEAD commit of the merge request") mrApproveCmd.Flags().StringP("sha", "s", "", "SHA which must match the SHA of the HEAD commit of the merge request")
return mrApproveCmd return mrApproveCmd
} }

View File

@ -10,7 +10,7 @@ import (
) )
func NewCmdApprovers(f *cmdutils.Factory) *cobra.Command { func NewCmdApprovers(f *cmdutils.Factory) *cobra.Command {
var mrApproversCmd = &cobra.Command{ mrApproversCmd := &cobra.Command{
Use: "approvers [<id> | <branch>] [flags]", Use: "approvers [<id> | <branch>] [flags]",
Short: `List eligible approvers for merge requests in any state`, Short: `List eligible approvers for merge requests in any state`,
Long: ``, Long: ``,

View File

@ -19,12 +19,10 @@ type mrCheckoutConfig struct {
upstream string upstream string
} }
var ( var mrCheckoutCfg mrCheckoutConfig
mrCheckoutCfg mrCheckoutConfig
)
func NewCmdCheckout(f *cmdutils.Factory) *cobra.Command { func NewCmdCheckout(f *cmdutils.Factory) *cobra.Command {
var mrCheckoutCmd = &cobra.Command{ mrCheckoutCmd := &cobra.Command{
Use: "checkout [<id> | <branch>]", Use: "checkout [<id> | <branch>]",
Short: "Checkout to an open merge request", Short: "Checkout to an open merge request",
Long: ``, Long: ``,
@ -93,7 +91,6 @@ func NewCmdCheckout(f *cmdutils.Factory) *cobra.Command {
fmt.Println(err) fmt.Println(err)
} }
repoRemote, err := remotes.FindByRepo(repo.RepoOwner(), repo.RepoName()) repoRemote, err := remotes.FindByRepo(repo.RepoOwner(), repo.RepoName())
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }

View File

@ -13,7 +13,7 @@ import (
) )
func NewCmdClose(f *cmdutils.Factory) *cobra.Command { func NewCmdClose(f *cmdutils.Factory) *cobra.Command {
var mrCloseCmd = &cobra.Command{ mrCloseCmd := &cobra.Command{
Use: "close [<id> | <branch>]", Use: "close [<id> | <branch>]",
Short: `Close merge requests`, Short: `Close merge requests`,
Long: ``, Long: ``,

View File

@ -83,7 +83,7 @@ func NewCmdCreate(f *cmdutils.Factory, runE func(opts *CreateOpts) error) *cobra
HeadRepo: resolvedHeadRepo(f), HeadRepo: resolvedHeadRepo(f),
} }
var mrCreateCmd = &cobra.Command{ mrCreateCmd := &cobra.Command{
Use: "create", Use: "create",
Short: `Create new merge request`, Short: `Create new merge request`,
Long: ``, Long: ``,
@ -607,7 +607,7 @@ func mrBodyAndTitle(opts *CreateOpts) error {
func handlePush(opts *CreateOpts, remote *glrepo.Remote) error { func handlePush(opts *CreateOpts, remote *glrepo.Remote) error {
if opts.ShouldPush { if opts.ShouldPush {
var sourceRemote = remote sourceRemote := remote
sourceBranch := opts.SourceBranch sourceBranch := opts.SourceBranch

View File

@ -150,7 +150,8 @@ func TestNewCmdCreate_tty(t *testing.T) {
deadbeef refs/remotes/origin/feat-new-mr deadbeef refs/remotes/origin/feat-new-mr
`)) `))
cliStr := []string{"-t", "myMRtitle", cliStr := []string{
"-t", "myMRtitle",
"-d", "myMRbody", "-d", "myMRbody",
"-l", "test,bug", "-l", "test,bug",
"--milestone", "1", "--milestone", "1",

View File

@ -12,7 +12,7 @@ import (
) )
func NewCmdDelete(f *cmdutils.Factory) *cobra.Command { func NewCmdDelete(f *cmdutils.Factory) *cobra.Command {
var mrDeleteCmd = &cobra.Command{ mrDeleteCmd := &cobra.Command{
Use: "delete [<id> | <branch>]", Use: "delete [<id> | <branch>]",
Short: `Delete merge requests`, Short: `Delete merge requests`,
Long: ``, Long: ``,

View File

@ -121,7 +121,6 @@ hosts:
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
cli := strings.Join(tt.args, " ") cli := strings.Join(tt.args, " ")
t.Log(cli) t.Log(cli)
argv, err := shlex.Split(cli) argv, err := shlex.Split(cli)

View File

@ -17,7 +17,7 @@ import (
) )
func NewCmdFor(f *cmdutils.Factory) *cobra.Command { func NewCmdFor(f *cmdutils.Factory) *cobra.Command {
var mrForCmd = &cobra.Command{ mrForCmd := &cobra.Command{
Use: "for", Use: "for",
Short: `Create new merge request for an issue`, Short: `Create new merge request for an issue`,
Long: ``, Long: ``,
@ -84,7 +84,6 @@ func NewCmdFor(f *cmdutils.Factory) *cobra.Command {
_, branchErr = api.CreateBranch(apiClient, repo.FullName(), lb) _, branchErr = api.CreateBranch(apiClient, repo.FullName(), lb)
fmt.Println(branchErr) fmt.Println(branchErr)
} }
} }
var mergeTitle string var mergeTitle string

View File

@ -15,7 +15,7 @@ import (
) )
func NewCmdIssues(f *cmdutils.Factory) *cobra.Command { func NewCmdIssues(f *cmdutils.Factory) *cobra.Command {
var mrIssuesCmd = &cobra.Command{ mrIssuesCmd := &cobra.Command{
Use: "issues [<id> | <branch>]", Use: "issues [<id> | <branch>]",
Short: `Get issues related to a particular merge request.`, Short: `Get issues related to a particular merge request.`,
Long: ``, Long: ``,

View File

@ -53,11 +53,11 @@ type ListOptions struct {
} }
func NewCmdList(f *cmdutils.Factory, runE func(opts *ListOptions) error) *cobra.Command { func NewCmdList(f *cmdutils.Factory, runE func(opts *ListOptions) error) *cobra.Command {
var opts = &ListOptions{ opts := &ListOptions{
IO: f.IO, IO: f.IO,
} }
var mrListCmd = &cobra.Command{ mrListCmd := &cobra.Command{
Use: "list [flags]", Use: "list [flags]",
Short: `List merge requests`, Short: `List merge requests`,
Long: ``, Long: ``,
@ -230,7 +230,6 @@ func listRun(opts *ListOptions) error {
if len(assigneeIds) > 0 || len(reviewerIds) > 0 { if len(assigneeIds) > 0 || len(reviewerIds) > 0 {
mergeRequests, err = api.ListMRsWithAssigneesOrReviewers(apiClient, repo.FullName(), l, assigneeIds, reviewerIds) mergeRequests, err = api.ListMRsWithAssigneesOrReviewers(apiClient, repo.FullName(), l, assigneeIds, reviewerIds)
} else if opts.Group != "" { } else if opts.Group != "" {
mergeRequests, err = api.ListGroupMRs(apiClient, opts.Group, api.ProjectListMROptionsToGroup(l)) mergeRequests, err = api.ListGroupMRs(apiClient, opts.Group, api.ProjectListMROptionsToGroup(l))
title.RepoName = opts.Group title.RepoName = opts.Group

View File

@ -42,11 +42,11 @@ type MergeOpts struct {
} }
func NewCmdMerge(f *cmdutils.Factory) *cobra.Command { func NewCmdMerge(f *cmdutils.Factory) *cobra.Command {
var opts = &MergeOpts{ opts := &MergeOpts{
MergeMethod: MRMergeMethodMerge, MergeMethod: MRMergeMethodMerge,
} }
var mrMergeCmd = &cobra.Command{ mrMergeCmd := &cobra.Command{
Use: "merge {<id> | <branch>}", Use: "merge {<id> | <branch>}",
Short: `Merge/Accept merge requests`, Short: `Merge/Accept merge requests`,
Long: ``, Long: ``,
@ -264,7 +264,7 @@ func mergeMethodSurvey() (MRMergeMethod, error) {
method MRMergeMethod method MRMergeMethod
} }
var mergeOpts = []mergeOption{ mergeOpts := []mergeOption{
{title: "Create a merge commit", method: MRMergeMethodMerge}, {title: "Create a merge commit", method: MRMergeMethodMerge},
{title: "Rebase and merge", method: MRMergeMethodRebase}, {title: "Rebase and merge", method: MRMergeMethodRebase},
{title: "Squash and merge", method: MRMergeMethodSquash}, {title: "Squash and merge", method: MRMergeMethodSquash},

View File

@ -28,7 +28,7 @@ import (
) )
func NewCmdMR(f *cmdutils.Factory) *cobra.Command { func NewCmdMR(f *cmdutils.Factory) *cobra.Command {
var mrCmd = &cobra.Command{ mrCmd := &cobra.Command{
Use: "mr <command> [flags]", Use: "mr <command> [flags]",
Short: `Create, view and manage merge requests`, Short: `Create, view and manage merge requests`,
Long: ``, Long: ``,

View File

@ -37,5 +37,4 @@ func TestMrCmd_noARgs(t *testing.T) {
out := <-outC out := <-outC
assert.Contains(t, out, "Use \"mr [command] --help\" for more information about a command.\n") assert.Contains(t, out, "Use \"mr [command] --help\" for more information about a command.\n")
} }

View File

@ -492,7 +492,6 @@ func Test_MRFromArgsWithOpts(t *testing.T) {
assert.Nil(t, gotMR) assert.Nil(t, gotMR)
assert.Nil(t, gotRepo) assert.Nil(t, gotRepo)
assert.EqualError(t, err, `no merge requests from branch "foo"`) assert.EqualError(t, err, `no merge requests from branch "foo"`)
}) })
t.Run("api.GetMR", func(t *testing.T) { t.Run("api.GetMR", func(t *testing.T) {
f := *f f := *f

View File

@ -14,7 +14,7 @@ import (
) )
func NewCmdNote(f *cmdutils.Factory) *cobra.Command { func NewCmdNote(f *cmdutils.Factory) *cobra.Command {
var mrCreateNoteCmd = &cobra.Command{ mrCreateNoteCmd := &cobra.Command{
Use: "note [<id> | <branch>]", Use: "note [<id> | <branch>]",
Aliases: []string{"comment"}, Aliases: []string{"comment"},
Short: "Add a comment or note to merge request", Short: "Add a comment or note to merge request",

View File

@ -77,7 +77,6 @@ func Test_NewCmdNote(t *testing.T) {
defer fakeHTTP.Verify(t) defer fakeHTTP.Verify(t)
t.Run("--message flag specified", func(t *testing.T) { t.Run("--message flag specified", func(t *testing.T) {
fakeHTTP.RegisterResponder("POST", "/projects/OWNER/REPO/merge_requests/1/notes", fakeHTTP.RegisterResponder("POST", "/projects/OWNER/REPO/merge_requests/1/notes",
httpmock.NewStringResponse(201, ` httpmock.NewStringResponse(201, `
{ {
@ -158,7 +157,6 @@ func Test_mrNoteCreate_prompt(t *testing.T) {
defer fakeHTTP.Verify(t) defer fakeHTTP.Verify(t)
t.Run("message provided", func(t *testing.T) { t.Run("message provided", func(t *testing.T) {
fakeHTTP.RegisterResponder("POST", "/projects/OWNER/REPO/merge_requests/1/notes", fakeHTTP.RegisterResponder("POST", "/projects/OWNER/REPO/merge_requests/1/notes",
httpmock.NewStringResponse(201, ` httpmock.NewStringResponse(201, `
{ {
@ -195,7 +193,6 @@ func Test_mrNoteCreate_prompt(t *testing.T) {
}) })
t.Run("message is empty", func(t *testing.T) { t.Run("message is empty", func(t *testing.T) {
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/merge_requests/1", fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/merge_requests/1",
httpmock.NewStringResponse(200, ` httpmock.NewStringResponse(200, `
{ {
@ -224,7 +221,6 @@ func Test_mrNoteCreate_no_duplicate(t *testing.T) {
defer fakeHTTP.Verify(t) defer fakeHTTP.Verify(t)
t.Run("message provided", func(t *testing.T) { t.Run("message provided", func(t *testing.T) {
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/merge_requests/1", fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/merge_requests/1",
httpmock.NewStringResponse(200, ` httpmock.NewStringResponse(200, `
{ {

View File

@ -9,10 +9,10 @@ import (
) )
func NewCmdRebase(f *cmdutils.Factory) *cobra.Command { func NewCmdRebase(f *cmdutils.Factory) *cobra.Command {
var mrRebaseCmd = &cobra.Command{ mrRebaseCmd := &cobra.Command{
Use: "rebase [<id> | <branch>] [flags]", Use: "rebase [<id> | <branch>] [flags]",
Short: `Automatically rebase the source_branch of the merge request against its target_branch.`, Short: `Automatically rebase the source_branch of the merge request against its target_branch.`,
Long: heredoc.Doc(`If you don't have permissions to push to the merge request's source branch - you'll get a 403 Forbidden response. Long: heredoc.Doc(`If you don't have permissions to push to the merge request's source branch - you'll get a 403 Forbidden response.
`), `),
Example: heredoc.Doc(` Example: heredoc.Doc(`
glab mr rebase 123 glab mr rebase 123

View File

@ -13,7 +13,7 @@ import (
) )
func NewCmdReopen(f *cmdutils.Factory) *cobra.Command { func NewCmdReopen(f *cmdutils.Factory) *cobra.Command {
var mrReopenCmd = &cobra.Command{ mrReopenCmd := &cobra.Command{
Use: "reopen [<id>... | <branch>...]", Use: "reopen [<id>... | <branch>...]",
Short: `Reopen merge requests`, Short: `Reopen merge requests`,
Example: heredoc.Doc(` Example: heredoc.Doc(`

View File

@ -12,7 +12,7 @@ import (
) )
func NewCmdRevoke(f *cmdutils.Factory) *cobra.Command { func NewCmdRevoke(f *cmdutils.Factory) *cobra.Command {
var mrRevokeCmd = &cobra.Command{ mrRevokeCmd := &cobra.Command{
Use: "revoke [<id> | <branch>]", Use: "revoke [<id> | <branch>]",
Short: `Revoke approval on a merge request`, Short: `Revoke approval on a merge request`,
Long: ``, Long: ``,

View File

@ -12,7 +12,7 @@ import (
) )
func NewCmdSubscribe(f *cmdutils.Factory) *cobra.Command { func NewCmdSubscribe(f *cmdutils.Factory) *cobra.Command {
var mrSubscribeCmd = &cobra.Command{ mrSubscribeCmd := &cobra.Command{
Use: "subscribe [<id> | <branch>]", Use: "subscribe [<id> | <branch>]",
Short: `Subscribe to merge requests`, Short: `Subscribe to merge requests`,
Long: ``, Long: ``,

View File

@ -104,7 +104,8 @@ hosts:
{ {
Name: "Issue on another repo", Name: "Issue on another repo",
Issue: "1 -R profclems/glab", Issue: "1 -R profclems/glab",
ExpectedMsg: []string{"- Subscribing to merge request !1", ExpectedMsg: []string{
"- Subscribing to merge request !1",
"✓ You have successfully subscribed to merge request !1", "✓ You have successfully subscribed to merge request !1",
"https://gitlab.com/profclems/glab/-/merge_requests/1\n", "https://gitlab.com/profclems/glab/-/merge_requests/1\n",
}, },

View File

@ -12,7 +12,7 @@ import (
) )
func NewCmdTodo(f *cmdutils.Factory) *cobra.Command { func NewCmdTodo(f *cmdutils.Factory) *cobra.Command {
var mrToDoCmd = &cobra.Command{ mrToDoCmd := &cobra.Command{
Use: "todo [<id> | <branch>]", Use: "todo [<id> | <branch>]",
Aliases: []string{"add-todo"}, Aliases: []string{"add-todo"},
Short: "Add a ToDo to merge request", Short: "Add a ToDo to merge request",

View File

@ -12,7 +12,7 @@ import (
) )
func NewCmdUnsubscribe(f *cmdutils.Factory) *cobra.Command { func NewCmdUnsubscribe(f *cmdutils.Factory) *cobra.Command {
var mrUnsubscribeCmd = &cobra.Command{ mrUnsubscribeCmd := &cobra.Command{
Use: "unsubscribe [<id> | <branch>]", Use: "unsubscribe [<id> | <branch>]",
Short: `Unsubscribe from merge requests`, Short: `Unsubscribe from merge requests`,
Long: ``, Long: ``,

View File

@ -15,7 +15,7 @@ import (
) )
func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command { func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command {
var mrUpdateCmd = &cobra.Command{ mrUpdateCmd := &cobra.Command{
Use: "update [<id> | <branch>]", Use: "update [<id> | <branch>]",
Short: `Update merge requests`, Short: `Update merge requests`,
Long: ``, Long: ``,

View File

@ -117,14 +117,16 @@ hosts:
{ {
Name: "Remove source branch", Name: "Remove source branch",
Args: "1 --remove-source-branch", Args: "1 --remove-source-branch",
ExpectedMsg: []string{"- Updating merge request !1", ExpectedMsg: []string{
"- Updating merge request !1",
"✓ enabled removal of source branch on merge", "✓ enabled removal of source branch on merge",
}, },
}, },
{ {
Name: "Restore remove source branch", Name: "Restore remove source branch",
Args: "1 --remove-source-branch", Args: "1 --remove-source-branch",
ExpectedMsg: []string{"- Updating merge request !1", ExpectedMsg: []string{
"- Updating merge request !1",
"✓ disabled removal of source branch on merge", "✓ disabled removal of source branch on merge",
}, },
}, },

View File

@ -31,7 +31,7 @@ func NewCmdView(f *cmdutils.Factory) *cobra.Command {
opts := &ViewOpts{ opts := &ViewOpts{
IO: f.IO, IO: f.IO,
} }
var mrViewCmd = &cobra.Command{ mrViewCmd := &cobra.Command{
Use: "view {<id> | <branch>}", Use: "view {<id> | <branch>}",
Short: `Display the title, body, and other information about a merge request.`, Short: `Display the title, body, and other information about a merge request.`,
Long: ``, Long: ``,

View File

@ -164,7 +164,6 @@ func TestMRView(t *testing.T) {
cmdutils.EnableRepoOverride(cmd, stubFactory) cmdutils.EnableRepoOverride(cmd, stubFactory)
_, err := cmdtest.RunCommand(cmd, "13 -c -s -R glab-cli/test") _, err := cmdtest.RunCommand(cmd, "13 -c -s -R glab-cli/test")
if err != nil { if err != nil {
t.Error(err) t.Error(err)
return return

View File

@ -16,7 +16,7 @@ import (
) )
func NewCmdArchive(f *cmdutils.Factory) *cobra.Command { func NewCmdArchive(f *cmdutils.Factory) *cobra.Command {
var repoArchiveCmd = &cobra.Command{ repoArchiveCmd := &cobra.Command{
Use: "archive <command> [flags]", Use: "archive <command> [flags]",
Short: `Get an archive of the repository.`, Short: `Get an archive of the repository.`,
Example: heredoc.Doc(` Example: heredoc.Doc(`

View File

@ -60,7 +60,7 @@ func NewCmdClone(f *cmdutils.Factory, runE func(*CloneOptions, *ContextOpts) err
ctxOpts := &ContextOpts{} ctxOpts := &ContextOpts{}
var repoCloneCmd = &cobra.Command{ repoCloneCmd := &cobra.Command{
Use: "clone <repo> [<dir>] [-- [<gitflags>...]]", Use: "clone <repo> [<dir>] [-- [<gitflags>...]]",
Short: `Clone a GitLab repository/project`, Short: `Clone a GitLab repository/project`,
Example: heredoc.Doc(` Example: heredoc.Doc(`
@ -158,7 +158,7 @@ func NewCmdClone(f *cmdutils.Factory, runE func(*CloneOptions, *ContextOpts) err
func listProjects(opts *CloneOptions, ListGroupProjectOpts *gitlab.ListGroupProjectsOptions) ([]*gitlab.Project, error) { func listProjects(opts *CloneOptions, ListGroupProjectOpts *gitlab.ListGroupProjectsOptions) ([]*gitlab.Project, error) {
var projects []*gitlab.Project var projects []*gitlab.Project
var hasRemaining = true hasRemaining := true
for hasRemaining { for hasRemaining {
currentPage, resp, err := api.ListGroupProjects(opts.APIClient.Lab(), opts.GroupName, ListGroupProjectOpts) currentPage, resp, err := api.ListGroupProjects(opts.APIClient.Lab(), opts.GroupName, ListGroupProjectOpts)
@ -216,7 +216,7 @@ func groupClone(opts *CloneOptions, ctxOpts *ContextOpts) error {
ListGroupProjectOpts.Page = opts.Page ListGroupProjectOpts.Page = opts.Page
} }
var projects, err = listProjects(opts, ListGroupProjectOpts) projects, err := listProjects(opts, ListGroupProjectOpts)
var finalOutput []string var finalOutput []string
for _, project := range projects { for _, project := range projects {
ctxOpt := *ctxOpts ctxOpt := *ctxOpts

View File

@ -189,20 +189,20 @@ hosts:
} }
func Test_repoClone_group(t *testing.T) { func Test_repoClone_group(t *testing.T) {
var names = []string{"glab-cli/test", "glab-cli/test-pv"} names := []string{"glab-cli/test", "glab-cli/test-pv"}
var urls = []string{"git@gitlab.com:glab-cli/test.git", "git@gitlab.com:glab-cli/test-pv.git"} urls := []string{"git@gitlab.com:glab-cli/test.git", "git@gitlab.com:glab-cli/test-pv.git"}
repoCloneTest(t, names, urls, 0, false) repoCloneTest(t, names, urls, 0, false)
} }
func Test_repoClone_group_single(t *testing.T) { func Test_repoClone_group_single(t *testing.T) {
var names = []string{"glab-cli/test"} names := []string{"glab-cli/test"}
var urls = []string{"git@gitlab.com:glab-cli/test.git"} urls := []string{"git@gitlab.com:glab-cli/test.git"}
repoCloneTest(t, names, urls, 1, false) repoCloneTest(t, names, urls, 1, false)
} }
func Test_repoClone_group_paginate(t *testing.T) { func Test_repoClone_group_paginate(t *testing.T) {
var names = []string{"glab-cli/test", "glab-cli/test-pv"} names := []string{"glab-cli/test", "glab-cli/test-pv"}
var urls = []string{"git@gitlab.com:glab-cli/test.git", "git@gitlab.com:glab-cli/test-pv.git"} urls := []string{"git@gitlab.com:glab-cli/test.git", "git@gitlab.com:glab-cli/test-pv.git"}
repoCloneTest(t, names, urls, 1, true) repoCloneTest(t, names, urls, 1, true)
} }
@ -234,7 +234,7 @@ hosts:
defer restore() defer restore()
cmd := NewCmdClone(fac, nil) cmd := NewCmdClone(fac, nil)
var cli = "-g glab-cli" cli := "-g glab-cli"
if perPage != 0 { if perPage != 0 {
cli += fmt.Sprintf(" --per-page %d", perPage) cli += fmt.Sprintf(" --per-page %d", perPage)
} }

View File

@ -29,7 +29,7 @@ func NewCmdContributors(f *cmdutils.Factory) *cobra.Command {
opts := &Options{ opts := &Options{
IO: f.IO, IO: f.IO,
} }
var repoContributorsCmd = &cobra.Command{ repoContributorsCmd := &cobra.Command{
Use: "contributors", Use: "contributors",
Short: `Get repository contributors list.`, Short: `Get repository contributors list.`,
Example: heredoc.Doc(` Example: heredoc.Doc(`

Some files were not shown because too many files have changed in this diff Show More