Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EXT-280 - EXT-280-open-project-vcs #744

Merged
merged 4 commits into from
Jul 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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