From f3c17207b51e455c0c001ca9e7aca02d9d8a4216 Mon Sep 17 00:00:00 2001 From: corinnesollows Date: Mon, 4 Jul 2022 10:30:33 -0300 Subject: [PATCH] EXT-280 - EXT-280-open-project-vcs (#744) * formatting file * Warning Error --- cmd/open.go | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/cmd/open.go b/cmd/open.go index 52d134b72..8300aec65 100644 --- a/cmd/open.go +++ b/cmd/open.go @@ -11,6 +11,12 @@ import ( "github.com/spf13/cobra" ) +// errorMessage string containing the error message displayed in both the open command and the follow command +var errorMessage = ` +This command is intended to be run from a git repository with a remote named 'origin' that is hosted on Github or Bitbucket only. +We are not currently supporting any other hosts.` + +//projectUrl uses the provided values to create the url to open func projectUrl(remote *git.Remote) string { return fmt.Sprintf("https://app.circleci.com/pipelines/%s/%s/%s", url.PathEscape(strings.ToLower(string(remote.VcsType))), @@ -18,24 +24,22 @@ func projectUrl(remote *git.Remote) string { url.PathEscape(remote.Project)) } -var errorMessage = ` -Unable detect which URL should be opened. This command is intended to be run from -a git repository with a remote named 'origin' that is hosted on Github or Bitbucket -Error` - +//openProjectInBrowser takes the created url and opens a browser to it func openProjectInBrowser() error { - remote, err := git.InferProjectFromGitRemotes() - if err != nil { return errors.Wrap(err, errorMessage) } - - return browser.OpenURL(projectUrl(remote)) + //check that project url contains github or bitbucket; our legacy vcs + if remote.VcsType == git.GitHub || remote.VcsType == git.Bitbucket { + return browser.OpenURL(projectUrl(remote)) + } + //if not warn user their vcs is not supported + return errors.New(errorMessage) } +// newOpenCommand creates the cli command open func newOpenCommand() *cobra.Command { - openCommand := &cobra.Command{ Use: "open", Short: "Open the current project in the browser.",