-
Notifications
You must be signed in to change notification settings - Fork 232
/
open.go
47 lines (37 loc) · 1.05 KB
/
open.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package cmd
import (
"fmt"
"net/url"
"strings"
"github.com/CircleCI-Public/circleci-cli/git"
"github.com/pkg/browser"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
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`
func openProjectInBrowser() error {
remote, err := git.InferProjectFromGitRemotes()
if err != nil {
return errors.Wrap(err, errorMessage)
}
return browser.OpenURL(projectUrl(remote))
}
func newOpenCommand() *cobra.Command {
openCommand := &cobra.Command{
Use: "open",
Short: "Open the current project in the browser.",
RunE: func(_ *cobra.Command, _ []string) error {
return openProjectInBrowser()
},
}
return openCommand
}