Skip to content

Commit

Permalink
Merge pull request #45 from edoardottt/devel
Browse files Browse the repository at this point in the history
Add ProjectPackageVersions #35
  • Loading branch information
edoardottt authored Nov 13, 2023
2 parents d4328a8 + 7931db4 commit fd752ec
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 7 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Available Commands:
graph Generate a Graphviz compatible dependencies graph
help Help about any command
info Get info about a package or a specific version of that
packages Get info about a project's package versions (GitHub, GitLab, or BitBucket)
project Get info about a project (GitHub, GitLab, or BitBucket)
query Get info about multiple package versions using a query
reqs Get info about a package's requirements
Expand Down Expand Up @@ -147,6 +148,14 @@ depsdev reqs npm slice-ansi 6.0.0

<br>

Returns the package versions which attest to being created from the specified source code repository.

```console
depsdev packages github.com/eslint/espree
```

<br>

**Use depsdev as a Go module**

```Go
Expand All @@ -165,6 +174,7 @@ func main() {
fmt.Println(i)
}
```

Read the full [`package documentation here`](https://pkg.go.dev/github.com/edoardottt/depsdev/pkg/depsdev)

Changelog 📌
Expand Down
37 changes: 37 additions & 0 deletions cmd/packages.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package cmd

import (
"fmt"
"log"

"github.com/edoardottt/depsdev/pkg/input"
"github.com/edoardottt/depsdev/pkg/output"
"github.com/spf13/cobra"
)

var packagesCmd = &cobra.Command{
Use: "packages project",
Short: "Get info about a project's package versions (GitHub, GitLab, or BitBucket)",
Long: `Returns the package versions which attest to being created from the specified source code repository.
At most 1500 package versions are returned. (GitHub, GitLab, or BitBucket)`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("%s %w", "one", input.ErrArgumentLeast)
}

return nil
},
Run: func(cmd *cobra.Command, args []string) {
v, err := api.GetPackageVersions(args[0])
if err != nil {
log.Fatal(err)
}

vJSON, err := output.IndentJSON(v)
if err != nil {
log.Fatalf(err.Error())
}

fmt.Println(vJSON)
},
}
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ func init() {
rootCmd.AddCommand(queryCmd)
rootCmd.AddCommand(graphCmd)
rootCmd.AddCommand(reqsCmd)
rootCmd.AddCommand(packagesCmd)
}
14 changes: 14 additions & 0 deletions pkg/depsdev/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,17 @@ func (a *API) GetRequirements(packageManager, packageName, version string) (Requ

return response, nil
}

// GetPackageVersions returns the package versions which attest to being created from the specified
// source code repository (hosted on GitHub, GitLab or BitBucket).
// At most 1500 package versions are returned.
func (a *API) GetPackageVersions(projectName string) (PackageVersions, error) {
var response PackageVersions

var path = fmt.Sprintf(GetProjectPackageVersionsPath, url.PathEscape(projectName))
if err := a.client.Get(path, &response); err != nil {
return PackageVersions{}, err
}

return response, nil
}
19 changes: 19 additions & 0 deletions pkg/depsdev/packageversions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
depsdev - CLI client for deps.dev API.
Free access to dependencies, licenses, advisories, and other critical health and security signals for open source package versions.
@author: edoardottt, https://www.edoardoottavianelli.it/
@repository: https://github.com/edoardottt/depsdev
@license: https://github.com/edoardottt/depsdev/blob/main/LICENSE
*/

package depsdev

type PackageVersions struct {
Versions []Versions `json:"versions,omitempty"`
}
15 changes: 8 additions & 7 deletions pkg/depsdev/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ const (
BasePath = `https://api.deps.dev/v3alpha`

// API routes.
GetPackagePath = `/systems/%s/packages/%s`
GetVersionPath = `/systems/%s/packages/%s/versions/%s`
GetDependenciesPath = `/systems/%s/packages/%s/versions/%s:dependencies`
GetProjectPath = `/projects/%s`
GetAdvisoryPath = `/advisories/%s`
GetQueryPath = `/query`
GetRequirementsPath = `/systems/%s/packages/%s/versions/%s:requirements`
GetPackagePath = `/systems/%s/packages/%s`
GetVersionPath = `/systems/%s/packages/%s/versions/%s`
GetDependenciesPath = `/systems/%s/packages/%s/versions/%s:dependencies`
GetProjectPath = `/projects/%s`
GetAdvisoryPath = `/advisories/%s`
GetQueryPath = `/query`
GetRequirementsPath = `/systems/%s/packages/%s/versions/%s:requirements`
GetProjectPackageVersionsPath = `/projects/%s:packageversions`
)

0 comments on commit fd752ec

Please sign in to comment.