diff --git a/.golangci.yml b/.golangci.yml index 0101aaa48d8..cd48ccbf4e1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -216,7 +216,6 @@ linters: - CustomDeploymentProtectionRuleRequest - CustomProperty - DependabotAlertState - - DependencyGraphSnapshot - EncryptedSecret - EnterpriseSecurityAnalysisSettings - Hook @@ -304,7 +303,6 @@ linters: - CommitsSearchResult.Commits - CommitsSearchResult.Total - CreateOrgInvitationOptions.TeamID # TODO: TeamIDs - - DependencyGraphSnapshot.Sha # TODO: SHA - Discussion.DiscussionCategory # TODO: Category ? - EditOwner.OwnerInfo - EnterpriseLicensedUsers.GithubComSamlNameID # TODO: GithubComSAMLNameID diff --git a/github/dependency_graph_snapshots.go b/github/dependency_graph_snapshots.go index 7786c36252a..4354dda1021 100644 --- a/github/dependency_graph_snapshots.go +++ b/github/dependency_graph_snapshots.go @@ -41,8 +41,8 @@ type DependencyGraphSnapshotResolvedDependency struct { // // GitHub API docs: https://docs.github.com/rest/dependency-graph/dependency-submission?apiVersion=2022-11-28#create-a-snapshot-of-dependencies-for-a-repository type DependencyGraphSnapshotJob struct { - Correlator *string `json:"correlator,omitempty"` - ID *string `json:"id,omitempty"` + Correlator string `json:"correlator"` + ID string `json:"id"` HTMLURL *string `json:"html_url,omitempty"` } @@ -50,9 +50,9 @@ type DependencyGraphSnapshotJob struct { // // GitHub API docs: https://docs.github.com/rest/dependency-graph/dependency-submission?apiVersion=2022-11-28#create-a-snapshot-of-dependencies-for-a-repository type DependencyGraphSnapshotDetector struct { - Name *string `json:"name,omitempty"` - Version *string `json:"version,omitempty"` - URL *string `json:"url,omitempty"` + Name string `json:"name"` + Version string `json:"version"` + URL string `json:"url"` } // DependencyGraphSnapshotManifestFile represents the file declaring the repository's dependencies. @@ -66,22 +66,24 @@ type DependencyGraphSnapshotManifestFile struct { // // GitHub API docs: https://docs.github.com/rest/dependency-graph/dependency-submission?apiVersion=2022-11-28#create-a-snapshot-of-dependencies-for-a-repository type DependencyGraphSnapshotManifest struct { - Name *string `json:"name,omitempty"` + Name string `json:"name"` File *DependencyGraphSnapshotManifestFile `json:"file,omitempty"` Metadata map[string]any `json:"metadata,omitempty"` Resolved map[string]*DependencyGraphSnapshotResolvedDependency `json:"resolved,omitempty"` } -// DependencyGraphSnapshot represent a snapshot of a repository's dependencies. +// CreateDependencyGraphSnapshotRequest represents a request to create a snapshot of a repository's dependencies. // // GitHub API docs: https://docs.github.com/rest/dependency-graph/dependency-submission?apiVersion=2022-11-28#create-a-snapshot-of-dependencies-for-a-repository -type DependencyGraphSnapshot struct { +// +//meta:schema request POST /repos/{owner}/{repo}/dependency-graph/snapshots +type CreateDependencyGraphSnapshotRequest struct { Version int `json:"version"` - Sha *string `json:"sha,omitempty"` - Ref *string `json:"ref,omitempty"` - Job *DependencyGraphSnapshotJob `json:"job,omitempty"` - Detector *DependencyGraphSnapshotDetector `json:"detector,omitempty"` - Scanned *Timestamp `json:"scanned,omitempty"` + SHA string `json:"sha"` + Ref string `json:"ref"` + Job DependencyGraphSnapshotJob `json:"job"` + Detector DependencyGraphSnapshotDetector `json:"detector"` + Scanned Timestamp `json:"scanned"` Metadata map[string]any `json:"metadata,omitempty"` Manifests map[string]*DependencyGraphSnapshotManifest `json:"manifests,omitempty"` } @@ -106,7 +108,7 @@ type DependencyGraphSnapshotCreationData struct { // GitHub API docs: https://docs.github.com/rest/dependency-graph/dependency-submission?apiVersion=2022-11-28#create-a-snapshot-of-dependencies-for-a-repository // //meta:operation POST /repos/{owner}/{repo}/dependency-graph/snapshots -func (s *DependencyGraphService) CreateSnapshot(ctx context.Context, owner, repo string, body *DependencyGraphSnapshot) (*DependencyGraphSnapshotCreationData, *Response, error) { +func (s *DependencyGraphService) CreateSnapshot(ctx context.Context, owner, repo string, body CreateDependencyGraphSnapshotRequest) (*DependencyGraphSnapshotCreationData, *Response, error) { url := fmt.Sprintf("repos/%v/%v/dependency-graph/snapshots", owner, repo) req, err := s.client.NewRequest(ctx, "POST", url, body) diff --git a/github/dependency_graph_snapshots_test.go b/github/dependency_graph_snapshots_test.go index b0a40eeafe2..0bc7cfbab29 100644 --- a/github/dependency_graph_snapshots_test.go +++ b/github/dependency_graph_snapshots_test.go @@ -17,28 +17,28 @@ func TestDependencyGraphService_CreateSnapshot(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - snapshot := &DependencyGraphSnapshot{ + snapshot := CreateDependencyGraphSnapshotRequest{ Version: 0, - Sha: new("ce587453ced02b1526dfb4cb910479d431683101"), - Ref: new("refs/heads/main"), - Job: &DependencyGraphSnapshotJob{ - Correlator: new("yourworkflowname_youractionname"), - ID: new("yourrunid"), + SHA: "ce587453ced02b1526dfb4cb910479d431683101", + Ref: "refs/heads/main", + Job: DependencyGraphSnapshotJob{ + Correlator: "yourworkflowname_youractionname", + ID: "yourrunid", HTMLURL: new("https://example.com"), }, - Detector: &DependencyGraphSnapshotDetector{ - Name: new("octo-detector"), - Version: new("0.0.1"), - URL: new("https://github.com/octo-org/octo-repo"), + Detector: DependencyGraphSnapshotDetector{ + Name: "octo-detector", + Version: "0.0.1", + URL: "https://github.com/octo-org/octo-repo", }, - Scanned: &referenceTimestamp, + Scanned: referenceTimestamp, Metadata: map[string]any{ "key1": "value1", "key2": "value2", }, Manifests: map[string]*DependencyGraphSnapshotManifest{ "package-lock.json": { - Name: new("package-lock.json"), + Name: "package-lock.json", File: &DependencyGraphSnapshotManifestFile{SourceLocation: new("src/package-lock.json")}, Metadata: map[string]any{ "key1": "value1", diff --git a/github/github-accessors.go b/github/github-accessors.go index b16d2847e6b..1afefa38238 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -11950,6 +11950,62 @@ func (c *CreateCustomRepoRoleRequest) GetPermissions() []string { return c.Permissions } +// GetDetector returns the Detector field. +func (c *CreateDependencyGraphSnapshotRequest) GetDetector() DependencyGraphSnapshotDetector { + if c == nil { + return DependencyGraphSnapshotDetector{} + } + return c.Detector +} + +// GetJob returns the Job field. +func (c *CreateDependencyGraphSnapshotRequest) GetJob() DependencyGraphSnapshotJob { + if c == nil { + return DependencyGraphSnapshotJob{} + } + return c.Job +} + +// GetMetadata returns the Metadata map if it's non-nil, an empty map otherwise. +func (c *CreateDependencyGraphSnapshotRequest) GetMetadata() map[string]any { + if c == nil || c.Metadata == nil { + return map[string]any{} + } + return c.Metadata +} + +// GetRef returns the Ref field. +func (c *CreateDependencyGraphSnapshotRequest) GetRef() string { + if c == nil { + return "" + } + return c.Ref +} + +// GetScanned returns the Scanned field. +func (c *CreateDependencyGraphSnapshotRequest) GetScanned() Timestamp { + if c == nil { + return Timestamp{} + } + return c.Scanned +} + +// GetSHA returns the SHA field. +func (c *CreateDependencyGraphSnapshotRequest) GetSHA() string { + if c == nil { + return "" + } + return c.SHA +} + +// GetVersion returns the Version field. +func (c *CreateDependencyGraphSnapshotRequest) GetVersion() int { + if c == nil { + return 0 + } + return c.Version +} + // GetKey returns the Key field. func (c *CreateDeployKeyRequest) GetKey() string { if c == nil { @@ -14326,62 +14382,6 @@ func (d *DependencyGraphAutosubmitActionOptions) GetLabeledRunners() bool { return *d.LabeledRunners } -// GetDetector returns the Detector field. -func (d *DependencyGraphSnapshot) GetDetector() *DependencyGraphSnapshotDetector { - if d == nil { - return nil - } - return d.Detector -} - -// GetJob returns the Job field. -func (d *DependencyGraphSnapshot) GetJob() *DependencyGraphSnapshotJob { - if d == nil { - return nil - } - 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 { - return "" - } - return *d.Ref -} - -// GetScanned returns the Scanned field if it's non-nil, zero value otherwise. -func (d *DependencyGraphSnapshot) GetScanned() Timestamp { - if d == nil || d.Scanned == nil { - return Timestamp{} - } - return *d.Scanned -} - -// GetSha returns the Sha field if it's non-nil, zero value otherwise. -func (d *DependencyGraphSnapshot) GetSha() string { - if d == nil || d.Sha == nil { - return "" - } - return *d.Sha -} - -// GetVersion returns the Version field. -func (d *DependencyGraphSnapshot) GetVersion() int { - if d == nil { - return 0 - } - return d.Version -} - // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. func (d *DependencyGraphSnapshotCreationData) GetCreatedAt() Timestamp { if d == nil || d.CreatedAt == nil { @@ -14414,36 +14414,36 @@ func (d *DependencyGraphSnapshotCreationData) GetResult() string { return *d.Result } -// GetName returns the Name field if it's non-nil, zero value otherwise. +// GetName returns the Name field. func (d *DependencyGraphSnapshotDetector) GetName() string { - if d == nil || d.Name == nil { + if d == nil { return "" } - return *d.Name + return d.Name } -// GetURL returns the URL field if it's non-nil, zero value otherwise. +// GetURL returns the URL field. func (d *DependencyGraphSnapshotDetector) GetURL() string { - if d == nil || d.URL == nil { + if d == nil { return "" } - return *d.URL + return d.URL } -// GetVersion returns the Version field if it's non-nil, zero value otherwise. +// GetVersion returns the Version field. func (d *DependencyGraphSnapshotDetector) GetVersion() string { - if d == nil || d.Version == nil { + if d == nil { return "" } - return *d.Version + return d.Version } -// GetCorrelator returns the Correlator field if it's non-nil, zero value otherwise. +// GetCorrelator returns the Correlator field. func (d *DependencyGraphSnapshotJob) GetCorrelator() string { - if d == nil || d.Correlator == nil { + if d == nil { return "" } - return *d.Correlator + return d.Correlator } // GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise. @@ -14454,12 +14454,12 @@ func (d *DependencyGraphSnapshotJob) GetHTMLURL() string { return *d.HTMLURL } -// GetID returns the ID field if it's non-nil, zero value otherwise. +// GetID returns the ID field. func (d *DependencyGraphSnapshotJob) GetID() string { - if d == nil || d.ID == nil { + if d == nil { return "" } - return *d.ID + return d.ID } // GetFile returns the File field. @@ -14478,12 +14478,12 @@ func (d *DependencyGraphSnapshotManifest) GetMetadata() map[string]any { return d.Metadata } -// GetName returns the Name field if it's non-nil, zero value otherwise. +// GetName returns the Name field. func (d *DependencyGraphSnapshotManifest) GetName() string { - if d == nil || d.Name == nil { + if d == nil { return "" } - return *d.Name + return d.Name } // GetSourceLocation returns the SourceLocation field if it's non-nil, zero value otherwise. diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 83103ef47b6..68e004cbaf5 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -15089,6 +15089,65 @@ func TestCreateCustomRepoRoleRequest_GetPermissions(tt *testing.T) { c.GetPermissions() } +func TestCreateDependencyGraphSnapshotRequest_GetDetector(tt *testing.T) { + tt.Parallel() + c := &CreateDependencyGraphSnapshotRequest{} + c.GetDetector() + c = nil + c.GetDetector() +} + +func TestCreateDependencyGraphSnapshotRequest_GetJob(tt *testing.T) { + tt.Parallel() + c := &CreateDependencyGraphSnapshotRequest{} + c.GetJob() + c = nil + c.GetJob() +} + +func TestCreateDependencyGraphSnapshotRequest_GetMetadata(tt *testing.T) { + tt.Parallel() + zeroValue := map[string]any{} + c := &CreateDependencyGraphSnapshotRequest{Metadata: zeroValue} + c.GetMetadata() + c = &CreateDependencyGraphSnapshotRequest{} + c.GetMetadata() + c = nil + c.GetMetadata() +} + +func TestCreateDependencyGraphSnapshotRequest_GetRef(tt *testing.T) { + tt.Parallel() + c := &CreateDependencyGraphSnapshotRequest{} + c.GetRef() + c = nil + c.GetRef() +} + +func TestCreateDependencyGraphSnapshotRequest_GetScanned(tt *testing.T) { + tt.Parallel() + c := &CreateDependencyGraphSnapshotRequest{} + c.GetScanned() + c = nil + c.GetScanned() +} + +func TestCreateDependencyGraphSnapshotRequest_GetSHA(tt *testing.T) { + tt.Parallel() + c := &CreateDependencyGraphSnapshotRequest{} + c.GetSHA() + c = nil + c.GetSHA() +} + +func TestCreateDependencyGraphSnapshotRequest_GetVersion(tt *testing.T) { + tt.Parallel() + c := &CreateDependencyGraphSnapshotRequest{} + c.GetVersion() + c = nil + c.GetVersion() +} + func TestCreateDeployKeyRequest_GetKey(tt *testing.T) { tt.Parallel() c := &CreateDeployKeyRequest{} @@ -18086,74 +18145,6 @@ func TestDependencyGraphAutosubmitActionOptions_GetLabeledRunners(tt *testing.T) d.GetLabeledRunners() } -func TestDependencyGraphSnapshot_GetDetector(tt *testing.T) { - tt.Parallel() - d := &DependencyGraphSnapshot{} - d.GetDetector() - d = nil - d.GetDetector() -} - -func TestDependencyGraphSnapshot_GetJob(tt *testing.T) { - tt.Parallel() - d := &DependencyGraphSnapshot{} - d.GetJob() - d = nil - 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 - d := &DependencyGraphSnapshot{Ref: &zeroValue} - d.GetRef() - d = &DependencyGraphSnapshot{} - d.GetRef() - d = nil - d.GetRef() -} - -func TestDependencyGraphSnapshot_GetScanned(tt *testing.T) { - tt.Parallel() - var zeroValue Timestamp - d := &DependencyGraphSnapshot{Scanned: &zeroValue} - d.GetScanned() - d = &DependencyGraphSnapshot{} - d.GetScanned() - d = nil - d.GetScanned() -} - -func TestDependencyGraphSnapshot_GetSha(tt *testing.T) { - tt.Parallel() - var zeroValue string - d := &DependencyGraphSnapshot{Sha: &zeroValue} - d.GetSha() - d = &DependencyGraphSnapshot{} - d.GetSha() - d = nil - d.GetSha() -} - -func TestDependencyGraphSnapshot_GetVersion(tt *testing.T) { - tt.Parallel() - d := &DependencyGraphSnapshot{} - d.GetVersion() - d = nil - d.GetVersion() -} - func TestDependencyGraphSnapshotCreationData_GetCreatedAt(tt *testing.T) { tt.Parallel() var zeroValue Timestamp @@ -18197,10 +18188,7 @@ func TestDependencyGraphSnapshotCreationData_GetResult(tt *testing.T) { func TestDependencyGraphSnapshotDetector_GetName(tt *testing.T) { tt.Parallel() - var zeroValue string - d := &DependencyGraphSnapshotDetector{Name: &zeroValue} - d.GetName() - d = &DependencyGraphSnapshotDetector{} + d := &DependencyGraphSnapshotDetector{} d.GetName() d = nil d.GetName() @@ -18208,10 +18196,7 @@ func TestDependencyGraphSnapshotDetector_GetName(tt *testing.T) { func TestDependencyGraphSnapshotDetector_GetURL(tt *testing.T) { tt.Parallel() - var zeroValue string - d := &DependencyGraphSnapshotDetector{URL: &zeroValue} - d.GetURL() - d = &DependencyGraphSnapshotDetector{} + d := &DependencyGraphSnapshotDetector{} d.GetURL() d = nil d.GetURL() @@ -18219,10 +18204,7 @@ func TestDependencyGraphSnapshotDetector_GetURL(tt *testing.T) { func TestDependencyGraphSnapshotDetector_GetVersion(tt *testing.T) { tt.Parallel() - var zeroValue string - d := &DependencyGraphSnapshotDetector{Version: &zeroValue} - d.GetVersion() - d = &DependencyGraphSnapshotDetector{} + d := &DependencyGraphSnapshotDetector{} d.GetVersion() d = nil d.GetVersion() @@ -18230,10 +18212,7 @@ func TestDependencyGraphSnapshotDetector_GetVersion(tt *testing.T) { func TestDependencyGraphSnapshotJob_GetCorrelator(tt *testing.T) { tt.Parallel() - var zeroValue string - d := &DependencyGraphSnapshotJob{Correlator: &zeroValue} - d.GetCorrelator() - d = &DependencyGraphSnapshotJob{} + d := &DependencyGraphSnapshotJob{} d.GetCorrelator() d = nil d.GetCorrelator() @@ -18252,10 +18231,7 @@ func TestDependencyGraphSnapshotJob_GetHTMLURL(tt *testing.T) { func TestDependencyGraphSnapshotJob_GetID(tt *testing.T) { tt.Parallel() - var zeroValue string - d := &DependencyGraphSnapshotJob{ID: &zeroValue} - d.GetID() - d = &DependencyGraphSnapshotJob{} + d := &DependencyGraphSnapshotJob{} d.GetID() d = nil d.GetID() @@ -18282,10 +18258,7 @@ func TestDependencyGraphSnapshotManifest_GetMetadata(tt *testing.T) { func TestDependencyGraphSnapshotManifest_GetName(tt *testing.T) { tt.Parallel() - var zeroValue string - d := &DependencyGraphSnapshotManifest{Name: &zeroValue} - d.GetName() - d = &DependencyGraphSnapshotManifest{} + d := &DependencyGraphSnapshotManifest{} d.GetName() d = nil d.GetName()