Skip to content

Commit

Permalink
EXT-280 - EXT-280-open-project-vcs (#744)
Browse files Browse the repository at this point in the history
* formatting file

* Warning Error
  • Loading branch information
corinnesollows authored Jul 4, 2022
1 parent 859abf9 commit f3c1720
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions cmd/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,35 @@ 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))),
url.PathEscape(remote.Organization),
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.",
Expand Down

0 comments on commit f3c1720

Please sign in to comment.