From 2a7aafe74b286ab29d4461a0945beaf688b8e87e Mon Sep 17 00:00:00 2001 From: Christophe de Carvalho Date: Thu, 16 May 2024 16:03:20 +0100 Subject: [PATCH 1/3] fix: update type of some field of Project struct to match response from deps.dev API fixes #70 --- .goreleaser.yaml | 17 ++++++++--------- pkg/depsdev/definitions/project.go | 6 +++--- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 800790d..f652648 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -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: @@ -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 - diff --git a/pkg/depsdev/definitions/project.go b/pkg/depsdev/definitions/project.go index db93763..5d52e25 100644 --- a/pkg/depsdev/definitions/project.go +++ b/pkg/depsdev/definitions/project.go @@ -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"` + 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"` From 226a6dbe4bacfdfdd6b380a57ef462d55edadb74 Mon Sep 17 00:00:00 2001 From: Christophe de Carvalho Date: Thu, 16 May 2024 16:16:58 +0100 Subject: [PATCH 2/3] add test for GetProject --- pkg/depsdev/v3/api_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/depsdev/v3/api_test.go b/pkg/depsdev/v3/api_test.go index bbe25a0..4f70a82 100644 --- a/pkg/depsdev/v3/api_test.go +++ b/pkg/depsdev/v3/api_test.go @@ -21,6 +21,7 @@ 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" ) @@ -28,6 +29,17 @@ var ( api = depsdev.NewV3API() ) +func TestGetProject(t *testing.T) { + 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": { From ea85e26f7bc66dd07d047228e9acf6e5c73823e7 Mon Sep 17 00:00:00 2001 From: Christophe de Carvalho Date: Fri, 17 May 2024 14:25:11 +0100 Subject: [PATCH 3/3] fix other types to match v3 API reference --- pkg/depsdev/definitions/project.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/depsdev/definitions/project.go b/pkg/depsdev/definitions/project.go index 5d52e25..2b7d77c 100644 --- a/pkg/depsdev/definitions/project.go +++ b/pkg/depsdev/definitions/project.go @@ -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"` } @@ -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"` }