Skip to content
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
10 changes: 10 additions & 0 deletions github/dependency_graph_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ import (
// GitHub API docs: https://docs.github.com/rest/dependency-graph/dependency-submission#create-a-snapshot-of-dependencies-for-a-repository
type DependencyGraphSnapshotResolvedDependency struct {
PackageURL *string `json:"package_url,omitempty"`
// User-defined metadata to store domain-specific information limited to 8 keys with scalar values.
// This metadata overrides auto-detected values from the package URL and GitHub's database.
// Common fields include:
// - "licenses": license information (e.g., "MIT", "Apache-2.0")
// - "name": package name
// - "version": package version
// - "manager": package manager (e.g., "npm", "pip", "maven")
// - "description": package description
Metadata map[string]any `json:"metadata,omitempty"`
// Represents whether the dependency is requested directly by the manifest or is a dependency of another dependency.
// Can have the following values:
// - "direct": indicates that the dependency is requested directly by the manifest.
Expand Down Expand Up @@ -59,6 +68,7 @@ type DependencyGraphSnapshotManifestFile struct {
type DependencyGraphSnapshotManifest struct {
Name *string `json:"name,omitempty"`
File *DependencyGraphSnapshotManifestFile `json:"file,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
Resolved map[string]*DependencyGraphSnapshotResolvedDependency `json:"resolved,omitempty"`
}

Expand Down
9 changes: 8 additions & 1 deletion github/dependency_graph_snapshots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestDependencyGraphService_CreateSnapshot(t *testing.T) {

mux.HandleFunc("/repos/o/r/dependency-graph/snapshots", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
testBody(t, r, `{"version":0,"sha":"ce587453ced02b1526dfb4cb910479d431683101","ref":"refs/heads/main","job":{"correlator":"yourworkflowname_youractionname","id":"yourrunid","html_url":"https://example.com"},"detector":{"name":"octo-detector","version":"0.0.1","url":"https://github.com/octo-org/octo-repo"},"scanned":"2022-06-14T20:25:00Z","metadata":{"key1":"value1","key2":"value2"},"manifests":{"package-lock.json":{"name":"package-lock.json","file":{"source_location":"src/package-lock.json"},"resolved":{"@actions/core":{"package_url":"pkg:/npm/%40actions/core@1.1.9","relationship":"direct","scope":"runtime","dependencies":["@actions/http-client"]},"@actions/http-client":{"package_url":"pkg:/npm/%40actions/http-client@1.0.7","relationship":"indirect","scope":"runtime","dependencies":["tunnel"]},"tunnel":{"package_url":"pkg:/npm/tunnel@0.0.6","relationship":"indirect","scope":"runtime"}}}}}`+"\n")
testBody(t, r, `{"version":0,"sha":"ce587453ced02b1526dfb4cb910479d431683101","ref":"refs/heads/main","job":{"correlator":"yourworkflowname_youractionname","id":"yourrunid","html_url":"https://example.com"},"detector":{"name":"octo-detector","version":"0.0.1","url":"https://github.com/octo-org/octo-repo"},"scanned":"2022-06-14T20:25:00Z","metadata":{"key1":"value1","key2":"value2"},"manifests":{"package-lock.json":{"name":"package-lock.json","file":{"source_location":"src/package-lock.json"},"metadata":{"key1":"value1","key2":"value2"},"resolved":{"@actions/core":{"package_url":"pkg:/npm/%40actions/core@1.1.9","metadata":{"licenses":"MIT"},"relationship":"direct","scope":"runtime","dependencies":["@actions/http-client"]},"@actions/http-client":{"package_url":"pkg:/npm/%40actions/http-client@1.0.7","relationship":"indirect","scope":"runtime","dependencies":["tunnel"]},"tunnel":{"package_url":"pkg:/npm/tunnel@0.0.6","relationship":"indirect","scope":"runtime"}}}}}`+"\n")
fmt.Fprint(w, `{"id":12345,"created_at":"2022-06-14T20:25:01Z","message":"Dependency results for the repo have been successfully updated.","result":"SUCCESS"}`)
})

Expand Down Expand Up @@ -49,11 +49,18 @@ func TestDependencyGraphService_CreateSnapshot(t *testing.T) {
"package-lock.json": {
Name: Ptr("package-lock.json"),
File: &DependencyGraphSnapshotManifestFile{SourceLocation: Ptr("src/package-lock.json")},
Metadata: map[string]any{
"key1": "value1",
"key2": "value2",
},
Resolved: map[string]*DependencyGraphSnapshotResolvedDependency{
"@actions/core": {
PackageURL: Ptr("pkg:/npm/%40actions/core@1.1.9"),
Relationship: Ptr("direct"),
Scope: Ptr("runtime"),
Metadata: map[string]any{
"licenses": "MIT",
},
Dependencies: []string{"@actions/http-client"},
},
"@actions/http-client": {
Expand Down
16 changes: 16 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading