-
-
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.
issue_reopen: Add subcommand to reopen closed issues
Commit 6e4a87a added such a command for merge requests; the same functionality is useful for issues too, so add the subcommand there as well.
- 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 issueReopenCmd = &cobra.Command{ | ||
Use: "reopen [remote] <id>", | ||
Short: "Reopen a closed issue", | ||
Long: ``, | ||
PersistentPreRun: LabPersistentPreRun, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
rn, id, err := parseArgsRemoteAndID(args) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
p, err := lab.FindProject(rn) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
err = lab.IssueReopen(p.ID, int(id)) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Printf("Issue #%d reopened\n", id) | ||
}, | ||
} | ||
|
||
func init() { | ||
issueCmd.AddCommand(issueReopenCmd) | ||
carapace.Gen(mrReopenCmd).PositionalCompletion( | ||
action.Remotes(), | ||
action.Issues(issueList), | ||
) | ||
} |
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_issueCloseReopen(t *testing.T) { | ||
tests := []struct { | ||
desc string | ||
opt string | ||
expected string | ||
}{ | ||
{ | ||
desc: "reopen-open", | ||
opt: "reopen", | ||
expected: "issue not closed", | ||
}, | ||
{ | ||
desc: "close-open", | ||
opt: "close", | ||
expected: "Issue #1 closed", | ||
}, | ||
{ | ||
desc: "close-closed", | ||
opt: "close", | ||
expected: "issue already closed", | ||
}, | ||
{ | ||
desc: "reopen-closed", | ||
opt: "reopen", | ||
expected: "Issue #1 reopened", | ||
}, | ||
} | ||
|
||
repo := copyTestRepo(t) | ||
for _, test := range tests { | ||
test := test | ||
t.Run(test.desc, func(t *testing.T) { | ||
cmd := exec.Command(labBinaryPath, "issue", test.opt, "1") | ||
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