Support for directory based repo and GH_REPO env variable

This commit is contained in:
benebsiny 2024-01-27 11:44:07 +08:00
parent 0ce66347b9
commit adc0abe5da
4 changed files with 74 additions and 28 deletions

View file

@ -2,6 +2,7 @@ package unlink
import (
"github.com/cli/cli/v2/internal/config"
"github.com/cli/cli/v2/internal/ghrepo"
"github.com/cli/cli/v2/pkg/cmd/project/shared/queries"
"github.com/cli/cli/v2/pkg/cmdutil"
"github.com/cli/cli/v2/pkg/iostreams"
@ -27,18 +28,20 @@ func TestNewCmdUnlink(t *testing.T) {
wantsErr: true,
wantsErrMsg: "invalid number: x",
},
{
name: "specify-nothing",
cli: "",
wantsErr: true,
wantsErrMsg: "specify either `--repo` or `--team`",
},
{
name: "specify-repo-and-team",
cli: "--repo my-repo --team my-team",
wantsErr: true,
wantsErrMsg: "specify only one of `--repo` or `--team`",
},
{
name: "specify-nothing",
cli: "",
wants: unlinkOpts{
repo: "REPO",
owner: "OWNER",
},
},
{
name: "repo",
cli: "--repo my-repo",
@ -62,13 +65,21 @@ func TestNewCmdUnlink(t *testing.T) {
},
},
{
name: "owner",
name: "owner-with-repo-flag",
cli: "--repo my-repo --owner monalisa",
wants: unlinkOpts{
owner: "monalisa",
repo: "my-repo",
},
},
{
name: "owner-without-repo-flag",
cli: "--owner monalisa",
wants: unlinkOpts{
owner: "monalisa",
repo: "REPO",
},
},
{
name: "json",
cli: "--repo my-repo --format json",
@ -86,6 +97,9 @@ func TestNewCmdUnlink(t *testing.T) {
ios, _, _, _ := iostreams.Test()
f := &cmdutil.Factory{
IOStreams: ios,
BaseRepo: func() (ghrepo.Interface, error) {
return ghrepo.New("OWNER", "REPO"), nil
},
}
argv, err := shlex.Split(tt.cli)