cli/commands/mr/close/mr_close.go

69 lines
1.7 KiB
Go
Raw Normal View History

Isolate commands into separate sub-packages (#229) * refactor: organize commands into separate subfolders * Format code with gofmt This commit fixes the style issues introduced in d1f70d5 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/1ce57d1c-4f1e-48c2-a4d8-00c1bce7fb49/ * 🔥 sub-packaging * Format code with gofmt This commit fixes the style issues introduced in ca0bff4 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/11379011-98c6-43ea-8baa-4fefa9b775e4/ * 🔥 sub-packaging * Format code with gofmt This commit fixes the style issues introduced in 00e5936 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/c912f945-acf3-48d2-a550-0895c0153df0/ * Done with sub-packaging 🔥 * 🔥 tests * Format code with gofmt This commit fixes the style issues introduced in 56a8ff4 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/24498865-4980-479f-90c7-7ddd228c2bb4/ * fix bug risks * fix tests * fix tests * Format code with gofmt This commit fixes the style issues introduced in c947d02 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/cb2ac46a-f857-40d5-8508-eacc253b3614/ * Format code with gofmt This commit fixes the style issues introduced in 902ff7b according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/f60ba0d6-94d3-47c0-ae27-568a5cc5d9e5/ * fix tests * fix tests * 🔥 gookit/color * Format code with gofmt This commit fixes the style issues introduced in 5a129ea according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/8f1c8327-f5c6-4ff5-97d2-3c8a23f0a1e2/ * Autofix issues in 1 files Resolved issues in the following files via DeepSource Autofix: 1. commands/cmdtest/helper.go * add tests for MR * Format code with gofmt This commit fixes the style issues introduced in 758af28 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/d55a4867-aa23-4202-b2cc-a7ceafbaa53e/ * migrate old config to new config * fix bug risks * Format code with gofmt This commit fixes the style issues introduced in 0ea8eb2 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/f90cf664-8396-4b78-814d-3167ce898164/ * refactoring Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
2020-09-29 05:55:34 +00:00
package close
import (
"fmt"
2021-01-08 19:14:04 +00:00
"github.com/MakeNowJust/heredoc"
2022-09-19 20:23:45 +00:00
"gitlab.com/gitlab-org/cli/api"
"gitlab.com/gitlab-org/cli/commands/cmdutils"
"gitlab.com/gitlab-org/cli/commands/mr/mrutils"
Isolate commands into separate sub-packages (#229) * refactor: organize commands into separate subfolders * Format code with gofmt This commit fixes the style issues introduced in d1f70d5 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/1ce57d1c-4f1e-48c2-a4d8-00c1bce7fb49/ * 🔥 sub-packaging * Format code with gofmt This commit fixes the style issues introduced in ca0bff4 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/11379011-98c6-43ea-8baa-4fefa9b775e4/ * 🔥 sub-packaging * Format code with gofmt This commit fixes the style issues introduced in 00e5936 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/c912f945-acf3-48d2-a550-0895c0153df0/ * Done with sub-packaging 🔥 * 🔥 tests * Format code with gofmt This commit fixes the style issues introduced in 56a8ff4 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/24498865-4980-479f-90c7-7ddd228c2bb4/ * fix bug risks * fix tests * fix tests * Format code with gofmt This commit fixes the style issues introduced in c947d02 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/cb2ac46a-f857-40d5-8508-eacc253b3614/ * Format code with gofmt This commit fixes the style issues introduced in 902ff7b according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/f60ba0d6-94d3-47c0-ae27-568a5cc5d9e5/ * fix tests * fix tests * 🔥 gookit/color * Format code with gofmt This commit fixes the style issues introduced in 5a129ea according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/8f1c8327-f5c6-4ff5-97d2-3c8a23f0a1e2/ * Autofix issues in 1 files Resolved issues in the following files via DeepSource Autofix: 1. commands/cmdtest/helper.go * add tests for MR * Format code with gofmt This commit fixes the style issues introduced in 758af28 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/d55a4867-aa23-4202-b2cc-a7ceafbaa53e/ * migrate old config to new config * fix bug risks * Format code with gofmt This commit fixes the style issues introduced in 0ea8eb2 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/f90cf664-8396-4b78-814d-3167ce898164/ * refactoring Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
2020-09-29 05:55:34 +00:00
"github.com/spf13/cobra"
"github.com/xanzy/go-gitlab"
)
func NewCmdClose(f *cmdutils.Factory) *cobra.Command {
var mrCloseCmd = &cobra.Command{
Use: "close [<id> | <branch>]",
Isolate commands into separate sub-packages (#229) * refactor: organize commands into separate subfolders * Format code with gofmt This commit fixes the style issues introduced in d1f70d5 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/1ce57d1c-4f1e-48c2-a4d8-00c1bce7fb49/ * 🔥 sub-packaging * Format code with gofmt This commit fixes the style issues introduced in ca0bff4 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/11379011-98c6-43ea-8baa-4fefa9b775e4/ * 🔥 sub-packaging * Format code with gofmt This commit fixes the style issues introduced in 00e5936 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/c912f945-acf3-48d2-a550-0895c0153df0/ * Done with sub-packaging 🔥 * 🔥 tests * Format code with gofmt This commit fixes the style issues introduced in 56a8ff4 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/24498865-4980-479f-90c7-7ddd228c2bb4/ * fix bug risks * fix tests * fix tests * Format code with gofmt This commit fixes the style issues introduced in c947d02 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/cb2ac46a-f857-40d5-8508-eacc253b3614/ * Format code with gofmt This commit fixes the style issues introduced in 902ff7b according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/f60ba0d6-94d3-47c0-ae27-568a5cc5d9e5/ * fix tests * fix tests * 🔥 gookit/color * Format code with gofmt This commit fixes the style issues introduced in 5a129ea according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/8f1c8327-f5c6-4ff5-97d2-3c8a23f0a1e2/ * Autofix issues in 1 files Resolved issues in the following files via DeepSource Autofix: 1. commands/cmdtest/helper.go * add tests for MR * Format code with gofmt This commit fixes the style issues introduced in 758af28 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/d55a4867-aa23-4202-b2cc-a7ceafbaa53e/ * migrate old config to new config * fix bug risks * Format code with gofmt This commit fixes the style issues introduced in 0ea8eb2 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/f90cf664-8396-4b78-814d-3167ce898164/ * refactoring Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
2020-09-29 05:55:34 +00:00
Short: `Close merge requests`,
Long: ``,
2021-01-08 19:14:04 +00:00
Example: heredoc.Doc(`
glab mr close 1
glab mr close 1 2 3 4 # close multiple branches at once
glab mr close # use checked out branch
glab mr close branch
glab mr close username:branch
glab mr close branch -R another/repo
2021-01-08 19:14:04 +00:00
`),
Isolate commands into separate sub-packages (#229) * refactor: organize commands into separate subfolders * Format code with gofmt This commit fixes the style issues introduced in d1f70d5 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/1ce57d1c-4f1e-48c2-a4d8-00c1bce7fb49/ * 🔥 sub-packaging * Format code with gofmt This commit fixes the style issues introduced in ca0bff4 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/11379011-98c6-43ea-8baa-4fefa9b775e4/ * 🔥 sub-packaging * Format code with gofmt This commit fixes the style issues introduced in 00e5936 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/c912f945-acf3-48d2-a550-0895c0153df0/ * Done with sub-packaging 🔥 * 🔥 tests * Format code with gofmt This commit fixes the style issues introduced in 56a8ff4 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/24498865-4980-479f-90c7-7ddd228c2bb4/ * fix bug risks * fix tests * fix tests * Format code with gofmt This commit fixes the style issues introduced in c947d02 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/cb2ac46a-f857-40d5-8508-eacc253b3614/ * Format code with gofmt This commit fixes the style issues introduced in 902ff7b according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/f60ba0d6-94d3-47c0-ae27-568a5cc5d9e5/ * fix tests * fix tests * 🔥 gookit/color * Format code with gofmt This commit fixes the style issues introduced in 5a129ea according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/8f1c8327-f5c6-4ff5-97d2-3c8a23f0a1e2/ * Autofix issues in 1 files Resolved issues in the following files via DeepSource Autofix: 1. commands/cmdtest/helper.go * add tests for MR * Format code with gofmt This commit fixes the style issues introduced in 758af28 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/d55a4867-aa23-4202-b2cc-a7ceafbaa53e/ * migrate old config to new config * fix bug risks * Format code with gofmt This commit fixes the style issues introduced in 0ea8eb2 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/f90cf664-8396-4b78-814d-3167ce898164/ * refactoring Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
2020-09-29 05:55:34 +00:00
RunE: func(cmd *cobra.Command, args []string) error {
var err error
2021-01-29 00:56:45 +00:00
c := f.IO.Color()
Isolate commands into separate sub-packages (#229) * refactor: organize commands into separate subfolders * Format code with gofmt This commit fixes the style issues introduced in d1f70d5 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/1ce57d1c-4f1e-48c2-a4d8-00c1bce7fb49/ * 🔥 sub-packaging * Format code with gofmt This commit fixes the style issues introduced in ca0bff4 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/11379011-98c6-43ea-8baa-4fefa9b775e4/ * 🔥 sub-packaging * Format code with gofmt This commit fixes the style issues introduced in 00e5936 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/c912f945-acf3-48d2-a550-0895c0153df0/ * Done with sub-packaging 🔥 * 🔥 tests * Format code with gofmt This commit fixes the style issues introduced in 56a8ff4 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/24498865-4980-479f-90c7-7ddd228c2bb4/ * fix bug risks * fix tests * fix tests * Format code with gofmt This commit fixes the style issues introduced in c947d02 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/cb2ac46a-f857-40d5-8508-eacc253b3614/ * Format code with gofmt This commit fixes the style issues introduced in 902ff7b according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/f60ba0d6-94d3-47c0-ae27-568a5cc5d9e5/ * fix tests * fix tests * 🔥 gookit/color * Format code with gofmt This commit fixes the style issues introduced in 5a129ea according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/8f1c8327-f5c6-4ff5-97d2-3c8a23f0a1e2/ * Autofix issues in 1 files Resolved issues in the following files via DeepSource Autofix: 1. commands/cmdtest/helper.go * add tests for MR * Format code with gofmt This commit fixes the style issues introduced in 758af28 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/d55a4867-aa23-4202-b2cc-a7ceafbaa53e/ * migrate old config to new config * fix bug risks * Format code with gofmt This commit fixes the style issues introduced in 0ea8eb2 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/f90cf664-8396-4b78-814d-3167ce898164/ * refactoring Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
2020-09-29 05:55:34 +00:00
apiClient, err := f.HttpClient()
if err != nil {
return err
}
mrs, repo, err := mrutils.MRsFromArgs(f, args, "opened")
Isolate commands into separate sub-packages (#229) * refactor: organize commands into separate subfolders * Format code with gofmt This commit fixes the style issues introduced in d1f70d5 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/1ce57d1c-4f1e-48c2-a4d8-00c1bce7fb49/ * 🔥 sub-packaging * Format code with gofmt This commit fixes the style issues introduced in ca0bff4 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/11379011-98c6-43ea-8baa-4fefa9b775e4/ * 🔥 sub-packaging * Format code with gofmt This commit fixes the style issues introduced in 00e5936 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/c912f945-acf3-48d2-a550-0895c0153df0/ * Done with sub-packaging 🔥 * 🔥 tests * Format code with gofmt This commit fixes the style issues introduced in 56a8ff4 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/24498865-4980-479f-90c7-7ddd228c2bb4/ * fix bug risks * fix tests * fix tests * Format code with gofmt This commit fixes the style issues introduced in c947d02 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/cb2ac46a-f857-40d5-8508-eacc253b3614/ * Format code with gofmt This commit fixes the style issues introduced in 902ff7b according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/f60ba0d6-94d3-47c0-ae27-568a5cc5d9e5/ * fix tests * fix tests * 🔥 gookit/color * Format code with gofmt This commit fixes the style issues introduced in 5a129ea according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/8f1c8327-f5c6-4ff5-97d2-3c8a23f0a1e2/ * Autofix issues in 1 files Resolved issues in the following files via DeepSource Autofix: 1. commands/cmdtest/helper.go * add tests for MR * Format code with gofmt This commit fixes the style issues introduced in 758af28 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/d55a4867-aa23-4202-b2cc-a7ceafbaa53e/ * migrate old config to new config * fix bug risks * Format code with gofmt This commit fixes the style issues introduced in 0ea8eb2 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/f90cf664-8396-4b78-814d-3167ce898164/ * refactoring Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
2020-09-29 05:55:34 +00:00
if err != nil {
return err
}
l := &gitlab.UpdateMergeRequestOptions{}
l.StateEvent = gitlab.String("close")
for _, mr := range mrs {
if err = mrutils.MRCheckErrors(mr, mrutils.MRCheckErrOptions{
Closed: true,
Merged: true,
}); err != nil {
return err
}
2020-12-27 16:39:34 +00:00
fmt.Fprintf(f.IO.StdOut, "- Closing Merge request...\n")
_, err := api.UpdateMR(apiClient, repo.FullName(), mr.IID, l)
Isolate commands into separate sub-packages (#229) * refactor: organize commands into separate subfolders * Format code with gofmt This commit fixes the style issues introduced in d1f70d5 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/1ce57d1c-4f1e-48c2-a4d8-00c1bce7fb49/ * 🔥 sub-packaging * Format code with gofmt This commit fixes the style issues introduced in ca0bff4 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/11379011-98c6-43ea-8baa-4fefa9b775e4/ * 🔥 sub-packaging * Format code with gofmt This commit fixes the style issues introduced in 00e5936 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/c912f945-acf3-48d2-a550-0895c0153df0/ * Done with sub-packaging 🔥 * 🔥 tests * Format code with gofmt This commit fixes the style issues introduced in 56a8ff4 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/24498865-4980-479f-90c7-7ddd228c2bb4/ * fix bug risks * fix tests * fix tests * Format code with gofmt This commit fixes the style issues introduced in c947d02 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/cb2ac46a-f857-40d5-8508-eacc253b3614/ * Format code with gofmt This commit fixes the style issues introduced in 902ff7b according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/f60ba0d6-94d3-47c0-ae27-568a5cc5d9e5/ * fix tests * fix tests * 🔥 gookit/color * Format code with gofmt This commit fixes the style issues introduced in 5a129ea according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/8f1c8327-f5c6-4ff5-97d2-3c8a23f0a1e2/ * Autofix issues in 1 files Resolved issues in the following files via DeepSource Autofix: 1. commands/cmdtest/helper.go * add tests for MR * Format code with gofmt This commit fixes the style issues introduced in 758af28 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/d55a4867-aa23-4202-b2cc-a7ceafbaa53e/ * migrate old config to new config * fix bug risks * Format code with gofmt This commit fixes the style issues introduced in 0ea8eb2 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/f90cf664-8396-4b78-814d-3167ce898164/ * refactoring Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
2020-09-29 05:55:34 +00:00
if err != nil {
return err
}
// Update the value of the merge request to closed so that mrutils.DisplayMR
// prints it as red
mr.State = "closed"
2021-01-29 00:56:45 +00:00
fmt.Fprintf(f.IO.StdOut, "%s Closed Merge request !%d\n", c.RedCheck(), mr.IID)
fmt.Fprintln(f.IO.StdOut, mrutils.DisplayMR(c, mr, f.IO.IsaTTY))
Isolate commands into separate sub-packages (#229) * refactor: organize commands into separate subfolders * Format code with gofmt This commit fixes the style issues introduced in d1f70d5 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/1ce57d1c-4f1e-48c2-a4d8-00c1bce7fb49/ * 🔥 sub-packaging * Format code with gofmt This commit fixes the style issues introduced in ca0bff4 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/11379011-98c6-43ea-8baa-4fefa9b775e4/ * 🔥 sub-packaging * Format code with gofmt This commit fixes the style issues introduced in 00e5936 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/c912f945-acf3-48d2-a550-0895c0153df0/ * Done with sub-packaging 🔥 * 🔥 tests * Format code with gofmt This commit fixes the style issues introduced in 56a8ff4 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/24498865-4980-479f-90c7-7ddd228c2bb4/ * fix bug risks * fix tests * fix tests * Format code with gofmt This commit fixes the style issues introduced in c947d02 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/cb2ac46a-f857-40d5-8508-eacc253b3614/ * Format code with gofmt This commit fixes the style issues introduced in 902ff7b according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/f60ba0d6-94d3-47c0-ae27-568a5cc5d9e5/ * fix tests * fix tests * 🔥 gookit/color * Format code with gofmt This commit fixes the style issues introduced in 5a129ea according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/8f1c8327-f5c6-4ff5-97d2-3c8a23f0a1e2/ * Autofix issues in 1 files Resolved issues in the following files via DeepSource Autofix: 1. commands/cmdtest/helper.go * add tests for MR * Format code with gofmt This commit fixes the style issues introduced in 758af28 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/d55a4867-aa23-4202-b2cc-a7ceafbaa53e/ * migrate old config to new config * fix bug risks * Format code with gofmt This commit fixes the style issues introduced in 0ea8eb2 according to the output from gofmt. Details: https://deepsource.io/gh/profclems/glab/transform/f90cf664-8396-4b78-814d-3167ce898164/ * refactoring Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
2020-09-29 05:55:34 +00:00
}
return nil
},
}
return mrCloseCmd
}