diff --git a/github/dependency_graph_snapshots.go b/github/dependency_graph_snapshots.go index 0606b981510..ed1a752f463 100644 --- a/github/dependency_graph_snapshots.go +++ b/github/dependency_graph_snapshots.go @@ -72,6 +72,7 @@ type DependencyGraphSnapshot struct { Job *DependencyGraphSnapshotJob `json:"job,omitempty"` Detector *DependencyGraphSnapshotDetector `json:"detector,omitempty"` Scanned *Timestamp `json:"scanned,omitempty"` + Metadata map[string]any `json:"metadata,omitempty"` Manifests map[string]*DependencyGraphSnapshotManifest `json:"manifests,omitempty"` } diff --git a/github/dependency_graph_snapshots_test.go b/github/dependency_graph_snapshots_test.go index 40d73a6733f..24a6230a184 100644 --- a/github/dependency_graph_snapshots_test.go +++ b/github/dependency_graph_snapshots_test.go @@ -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","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"},"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") fmt.Fprint(w, `{"id":12345,"created_at":"2022-06-14T20:25:01Z","message":"Dependency results for the repo have been successfully updated.","result":"SUCCESS"}`) }) @@ -41,6 +41,10 @@ func TestDependencyGraphService_CreateSnapshot(t *testing.T) { URL: Ptr("https://github.com/octo-org/octo-repo"), }, Scanned: &Timestamp{time.Date(2022, time.June, 14, 20, 25, 00, 0, time.UTC)}, + Metadata: map[string]any{ + "key1": "value1", + "key2": "value2", + }, Manifests: map[string]*DependencyGraphSnapshotManifest{ "package-lock.json": { Name: Ptr("package-lock.json"), diff --git a/github/github-accessors.go b/github/github-accessors.go index 6526a7c6675..6a08cd8fd91 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -7014,6 +7014,14 @@ func (d *DependencyGraphSnapshot) GetJob() *DependencyGraphSnapshotJob { return d.Job } +// GetMetadata returns the Metadata map if it's non-nil, an empty map otherwise. +func (d *DependencyGraphSnapshot) GetMetadata() map[string]any { + if d == nil || d.Metadata == nil { + return map[string]any{} + } + return d.Metadata +} + // GetRef returns the Ref field if it's non-nil, zero value otherwise. func (d *DependencyGraphSnapshot) GetRef() string { if d == nil || d.Ref == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index b0201a7302e..19088ff6356 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -9112,6 +9112,17 @@ func TestDependencyGraphSnapshot_GetJob(tt *testing.T) { d.GetJob() } +func TestDependencyGraphSnapshot_GetMetadata(tt *testing.T) { + tt.Parallel() + zeroValue := map[string]any{} + d := &DependencyGraphSnapshot{Metadata: zeroValue} + d.GetMetadata() + d = &DependencyGraphSnapshot{} + d.GetMetadata() + d = nil + d.GetMetadata() +} + func TestDependencyGraphSnapshot_GetRef(tt *testing.T) { tt.Parallel() var zeroValue string