Skip to content

Commit

Permalink
Add support for lab project browse
Browse files Browse the repository at this point in the history
  • Loading branch information
zaquestion committed Jun 20, 2018
1 parent d3b1b72 commit d63266a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
44 changes: 44 additions & 0 deletions cmd/project_browse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package cmd

import (
"log"

"github.com/spf13/cobra"
"github.com/zaquestion/lab/internal/git"
lab "github.com/zaquestion/lab/internal/gitlab"
)

var projectBrowseCmd = &cobra.Command{
Use: "browse [remote]",
Aliases: []string{"b"},
Short: "View project in a browser",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
remote, _, err := parseArgsRemote(args)
if err != nil {
log.Fatal(err)
}
if remote == "" {
remote = forkedFromRemote
}

name, err := git.PathWithNameSpace(remote)
if err != nil {
log.Fatal(err)
}

p, err := lab.FindProject(name)
if err != nil {
log.Fatal(err)
}

err = browse(p.WebURL)
if err != nil {
log.Fatal(err)
}
},
}

func init() {
projectCmd.AddCommand(projectBrowseCmd)
}
19 changes: 19 additions & 0 deletions cmd/project_browse_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cmd

import (
"testing"

"github.com/stretchr/testify/require"
)

func Test_projectBrowse(t *testing.T) {
oldBrowse := browse
defer func() { browse = oldBrowse }()

browse = func(url string) error {
require.Equal(t, "https://gitlab.com/zaquestion/test", url)
return nil
}

projectBrowseCmd.Run(nil, []string{""})
}

0 comments on commit d63266a

Please sign in to comment.