Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update type of some field of Project struct to match response from deps.dev API #71

Merged
merged 3 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ release:
*CLI client (and Golang module) for deps.dev API. Free access to dependencies, licenses, advisories, and other critical health and security signals for open source package versions.*

footer: |
If you encounter a problem, just open an [issue](https://github.com/edoardottt/depsdev/issues)
If you encounter a problem, just open an [issue](https://github.com/edoardottt/depsdev/issues)

before:
hooks:
Expand All @@ -24,18 +24,17 @@ builds:
- arm64
ignore:
- goos: darwin
goarch: '386'
goarch: "386"
- goos: windows
goarch: 'arm'
goarch: "arm"
- goos: windows
goarch: 'arm64'
binary: '{{ .ProjectName }}'
main: ./cmd/depsdev/
goarch: "arm64"
binary: "{{ .ProjectName }}"
main: ./main.go

archives:
- format: zip
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ if eq .Os "darwin" }}macOS{{ else }}{{ .Os }}{{ end }}_{{ .Arch }}'
- format: zip
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ if eq .Os "darwin" }}macOS{{ else }}{{ .Os }}{{ end }}_{{ .Arch }}'

checksum:
algorithm: sha256

14 changes: 7 additions & 7 deletions pkg/depsdev/definitions/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import "time"

type Project struct {
ProjectKey ProjectKey `json:"projectKey,omitempty"`
OpenIssuesCount string `json:"openIssuesCount,omitempty"`
StarsCount string `json:"starsCount,omitempty"`
ForksCount string `json:"forksCount,omitempty"`
OpenIssuesCount int `json:"openIssuesCount,omitempty"`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to change all the occurences of this issue. For example,

Score string `json:"score,omitempty"`
should be a number as far as I can see in the docs.
What do you think?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added some other type fixe I could find. Any other I've missed?

StarsCount int `json:"starsCount,omitempty"`
ForksCount int `json:"forksCount,omitempty"`
License string `json:"license,omitempty"`
Description string `json:"description,omitempty"`
Homepage string `json:"homepage,omitempty"`
Expand Down Expand Up @@ -50,7 +50,7 @@ type Documentation struct {
type Checks struct {
Name string `json:"name,omitempty"`
Documentation Documentation `json:"documentation,omitempty"`
Score string `json:"score,omitempty"`
Score float64 `json:"score,omitempty"`
Reason string `json:"reason,omitempty"`
Details []string `json:"details,omitempty"`
}
Expand All @@ -65,9 +65,9 @@ type Scorecard struct {
}

type OssFuzz struct {
LineCount string `json:"lineCount,omitempty"`
LineCoverCount string `json:"lineCoverCount,omitempty"`
LineCoverPercent string `json:"lineCoverPercent,omitempty"`
LineCount int `json:"lineCount,omitempty"`
LineCoverCount int `json:"lineCoverCount,omitempty"`
LineCoverPercent float64 `json:"lineCoverPercent,omitempty"`
Date time.Time `json:"date,omitempty"`
ConfigURL string `json:"configUrl,omitempty"`
}
12 changes: 12 additions & 0 deletions pkg/depsdev/v3/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,25 @@ import (

def "github.com/edoardottt/depsdev/pkg/depsdev/definitions"
"github.com/edoardottt/depsdev/pkg/depsdev/v3"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

var (
api = depsdev.NewV3API()
)

func TestGetProject(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unreliable. If someone stars the repo or fork it the test will fail

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense, I've updated the test to skip comparing actual value.

t.Run("GetInfo npm defangjs", func(t *testing.T) {
got, err := api.GetProject("github.com/edoardottt/defangjs")
require.Nil(t, err)

// no checking of the actual value because they can change over time
// we just ensure the call to the API and unmarshaling of the response works properly
assert.NotEmpty(t, got)
})
}

func TestGetInfo(t *testing.T) {
result := `{
"packageKey": {
Expand Down
Loading