-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mr_reopen: add command for reopening a closed MR
MRs can be closed from `lab` cli, it should also be possible to reopen them as needed. This patch enables `lab mr reopen` command, allowing the user to reopen the desired MR. Signed-off-by: Bruno Meneguele <[email protected]>
- Loading branch information
Showing
3 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/rsteube/carapace" | ||
"github.com/spf13/cobra" | ||
"github.com/zaquestion/lab/internal/action" | ||
lab "github.com/zaquestion/lab/internal/gitlab" | ||
) | ||
|
||
var mrReopenCmd = &cobra.Command{ | ||
Use: "reopen [remote] <id>", | ||
Short: "Reopen a closed merge request", | ||
Long: ``, | ||
PersistentPreRun: LabPersistentPreRun, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
rn, id, err := parseArgsWithGitBranchMR(args) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
p, err := lab.FindProject(rn) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
err = lab.MRReopen(p.ID, int(id)) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Printf("Merge Request #%d reopened\n", id) | ||
}, | ||
} | ||
|
||
func init() { | ||
mrCmd.AddCommand(mrReopenCmd) | ||
carapace.Gen(mrReopenCmd).PositionalCompletion( | ||
action.Remotes(), | ||
action.MergeRequests(mrList), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package cmd | ||
|
||
import ( | ||
"os/exec" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_mrCloseReopen(t *testing.T) { | ||
tests := []struct { | ||
desc string | ||
opt string | ||
expected string | ||
}{ | ||
{ | ||
desc: "reopen-open", | ||
opt: "reopen", | ||
expected: "mr not closed", | ||
}, | ||
{ | ||
desc: "close-open", | ||
opt: "close", | ||
expected: "Merge Request #19 closed", | ||
}, | ||
{ | ||
desc: "close-closed", | ||
opt: "close", | ||
expected: "mr already closed", | ||
}, | ||
{ | ||
desc: "reopen-closed", | ||
opt: "reopen", | ||
expected: "Merge Request #19 reopened", | ||
}, | ||
} | ||
|
||
repo := copyTestRepo(t) | ||
for _, test := range tests { | ||
test := test | ||
t.Run(test.desc, func(t *testing.T) { | ||
cmd := exec.Command(labBinaryPath, "mr", test.opt, "19") | ||
cmd.Dir = repo | ||
|
||
b, err := cmd.CombinedOutput() | ||
if err != nil { | ||
t.Log(string(b)) | ||
} | ||
|
||
out := string(b) | ||
require.Contains(t, out, test.expected) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters