Skip to content

Commit

Permalink
Added a deps.dev command to get repository information
Browse files Browse the repository at this point in the history
  • Loading branch information
garethr committed May 20, 2023
1 parent 0964586 commit 0eaa75f
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 0 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.20
require (
github.com/CycloneDX/cyclonedx-go v0.7.1
github.com/deepmap/oapi-codegen v1.12.4
github.com/edoardottt/depsdev v0.0.3
github.com/google/uuid v1.3.0
github.com/jarcoal/httpmock v1.3.0
github.com/package-url/packageurl-go v0.1.0
Expand All @@ -17,6 +18,7 @@ require (

require (
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/avast/retry-go v3.0.0+incompatible // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ github.com/CycloneDX/cyclonedx-go v0.7.1/go.mod h1:N/nrdWQI2SIjaACyyDs/u7+ddCkyl
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ=
github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk=
github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHSxpiH9JdtuBj0=
github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY=
github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w=
github.com/bradleyjkemp/cupaloy/v2 v2.8.0 h1:any4BmKE+jGIaMpnU8YgH/I2LPiLBufr6oMMlVBbn9M=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand All @@ -60,6 +62,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deepmap/oapi-codegen v1.12.4 h1:pPmn6qI9MuOtCz82WY2Xaw46EQjgvxednXXrP7g5Q2s=
github.com/deepmap/oapi-codegen v1.12.4/go.mod h1:3lgHGMu6myQ2vqbbTXH2H1o4eXFTGnFiDaOaKKl5yas=
github.com/edoardottt/depsdev v0.0.3 h1:QqTZGjdvrq8aZ0qhlPxUHiDrB+LadqUVsHX9a03pWO0=
github.com/edoardottt/depsdev v0.0.3/go.mod h1:IQTpYyqJbheAt6AXD/96CUMSGHha5r6rMLNKD8CXkiY=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand Down
2 changes: 2 additions & 0 deletions internal/commands/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/snyk/parlay/internal/commands/ecosystems"
"github.com/snyk/parlay/internal/commands/snyk"
"github.com/snyk/parlay/internal/commands/deps"

"github.com/rs/zerolog"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -38,6 +39,7 @@ func NewDefaultCommand() *cobra.Command {

cmd.AddCommand(ecosystems.NewEcosystemsRootCommand(logger))
cmd.AddCommand(snyk.NewSnykRootCommand(logger))
cmd.AddCommand(deps.NewDepsRootCommand(logger))

return &cmd
}
28 changes: 28 additions & 0 deletions internal/commands/deps/repos.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package deps

import (
"fmt"
"encoding/json"

"github.com/snyk/parlay/lib/deps"

"github.com/rs/zerolog"
"github.com/spf13/cobra"
)

func NewRepoCommand(logger zerolog.Logger) *cobra.Command {
cmd := cobra.Command{
Use: "repo <repo>",
Short: "Return repo info from deps.dev",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
proj, err := deps.GetRepoData(args[0])
if err != nil {
logger.Fatal().Err(err).Msg("An error occured")
}
b, err := json.Marshal(proj)
fmt.Print(string(b))
},
}
return &cmd
}
23 changes: 23 additions & 0 deletions internal/commands/deps/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package deps

import (
"github.com/rs/zerolog"
"github.com/spf13/cobra"
)

func NewDepsRootCommand(logger zerolog.Logger) *cobra.Command {
cmd := cobra.Command{
Use: "deps",
Short: "Commands for using parlay with deps.dev",
Aliases: []string{"d"},
DisableFlagsInUseLine: true,
SilenceUsage: true,
Run: func(cmd *cobra.Command, args []string) {
_ = cmd.Help()
},
}

cmd.AddCommand(NewRepoCommand(logger))

return &cmd
}
13 changes: 13 additions & 0 deletions lib/deps/repo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package deps

import (
"github.com/edoardottt/depsdev/pkg/depsdev"
)

func GetRepoData(url string) (*depsdev.Project, error) {
proj, err := depsdev.GetProject(url)
if err != nil {
return nil, err
}
return &proj, nil
}

0 comments on commit 0eaa75f

Please sign in to comment.