Skip to content

Commit

Permalink
Add support for gvt project
Browse files Browse the repository at this point in the history
  • Loading branch information
adamliesko committed Mar 10, 2018
1 parent 8a03bcf commit 17add77
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 4 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@
[![asciicast](https://asciinema.org/a/168466.png)](https://asciinema.org/a/168466)

`go-thanks` is a cmd line utility to show some love to all the hardworking Gophers, from whose work you profit daily by using their OSS.
It automatically detects imported packages from Go package managers ([dep](https://github.com/golang/dep), [Govendor](https://github.com/kardianos/govendor) and [Glide](https://github.com/Masterminds/glide))
and stars package repositories on Github and Gitlab. Inspired by [cargo-thanks](https://github.com/softprops/cargo-thanks) from the Rust ecosystem.
It automatically detects imported packages and stars their repositories on Github and Gitlab from following Go package managers:
- [dep](https://github.com/golang/dep)
- [Govendor](https://github.com/kardianos/govendor)
- [Glide](https://github.com/Masterminds/glide)
- [gvt](https://github.com/FiloSottile/gvt)

Inspired by [cargo-thanks](https://github.com/softprops/cargo-thanks) from the Rust ecosystem.

## Installation
```
Expand Down
5 changes: 3 additions & 2 deletions discover/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ type Discoverer interface {
Repositories(path string) (RepoMap, error)
}

var discoverers = []Discoverer{Dep{}, Glide{}, Govendor{}, Gvt{}}

// Repositories produces a slice of repositories extracted from the passed in discoverers within one's Go project.
func Repositories(path string) ([]Repository, error) {
discoverers := []Discoverer{Dep{}, Glide{}, Govendor{}}

repoMap := make(RepoMap)

for _, d := range discoverers {
if inUse, err := d.InUse(path); !inUse || err != nil {
continue
Expand Down
17 changes: 17 additions & 0 deletions discover/discover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@ func TestDiscoverRepositories(t *testing.T) {
},
wantErr: nil,
},
{
name: "gvt",
path: path.Join("test", "project_gvt"),
wantRepos: []Repository{
{
Name: "gocovmerge",
Owner: "wadey",
URL: "github.com/wadey/gocovmerge",
},
},
wantErr: nil,
},
{
name: "nothing to be found",
path: path.Join("test", "project_none"),
Expand All @@ -133,6 +145,11 @@ func TestDiscoverRepositories(t *testing.T) {
path: path.Join("test", "project_errors_govendor"),
wantErr: errors.New(""),
},
{
name: "errors from gvt",
path: path.Join("test", "project_errors_gvt"),
wantErr: errors.New(""),
},
{
name: "errors from all except dep still errors out",
path: path.Join("test", "project_errors_dep_ok"),
Expand Down
66 changes: 66 additions & 0 deletions discover/gvt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package discover

import (
"encoding/json"
"io/ioutil"
"os"
"path"
)

// Gvt is a discoverer for gvt Go package manager.
type Gvt struct{}

// Name returns name of Gvt discoverer.
func (g Gvt) Name() string {
return "gvt"
}

// InUse checks whether project is using gvt as a package manager.
func (g Gvt) InUse(projectPath string) (bool, error) {
_, err := os.Stat(gvtFilePath(projectPath))
if err != nil {
return false, err
}

return true, nil
}

func gvtFilePath(projectPath string) string {
return path.Join(projectPath, "vendor", "manifest")
}

// Repositories discovers repositories belonging to packages imported inside a project managed by Gvt.
func (g Gvt) Repositories(projectPath string) (RepoMap, error) {
list, err := packageListGvt(projectPath)
if err != nil {
return nil, err
}

repoMap := RepoMap{}
for _, p := range list.Dependencies {
repoMap.add(p.Importpath)
}

return repoMap, nil
}

type gvtList struct {
Dependencies []struct {
Importpath string `json:"importpath"`
} `json:"dependencies"`
}

func packageListGvt(projectPath string) (gvtList, error) {
list := gvtList{}

content, err := ioutil.ReadFile(gvtFilePath(projectPath))
if err != nil {
return gvtList{}, err
}
err = json.Unmarshal(content, &list)
if err != nil {
return gvtList{}, err
}

return list, nil
}
1 change: 1 addition & 0 deletions discover/test/project_errors_gvt/vendor/manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MISSING JSON
13 changes: 13 additions & 0 deletions discover/test/project_gvt/vendor/manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"generator": "github.com/FiloSottile/gvt",
"dependencies": [
{
"importpath": "github.com/wadey/gocovmerge",
"repository": "https://github.com/wadey/gocovmerge",
"vcs": "git",
"revision": "b5bfa59ec0adc420475f97f89b58045c721d761c",
"branch": "master",
"notests": true
}
]
}

0 comments on commit 17add77

Please sign in to comment.