diff --git a/github/actions_artifacts.go b/github/actions_artifacts.go index 99329d989d..441a53910e 100644 --- a/github/actions_artifacts.go +++ b/github/actions_artifacts.go @@ -12,20 +12,34 @@ import ( "net/url" ) -// Artifact reprents a GitHub artifact. Artifacts allow sharing +// ArtifactWorkflowRun represents a GitHub artifact's workflow run. +// +// GitHub API docs: https://docs.github.com/en/rest/actions/artifacts +type ArtifactWorkflowRun struct { + ID *int64 `json:"id,omitempty"` + RepositoryID *int64 `json:"repository_id,omitempty"` + HeadRepositoryID *int64 `json:"head_repository_id,omitempty"` + HeadBranch *string `json:"head_branch,omitempty"` + HeadSHA *string `json:"head_sha,omitempty"` +} + +// Artifact represents a GitHub artifact. Artifacts allow sharing // data between jobs in a workflow and provide storage for data // once a workflow is complete. // // GitHub API docs: https://docs.github.com/en/rest/actions/artifacts type Artifact struct { - ID *int64 `json:"id,omitempty"` - NodeID *string `json:"node_id,omitempty"` - Name *string `json:"name,omitempty"` - SizeInBytes *int64 `json:"size_in_bytes,omitempty"` - ArchiveDownloadURL *string `json:"archive_download_url,omitempty"` - Expired *bool `json:"expired,omitempty"` - CreatedAt *Timestamp `json:"created_at,omitempty"` - ExpiresAt *Timestamp `json:"expires_at,omitempty"` + ID *int64 `json:"id,omitempty"` + NodeID *string `json:"node_id,omitempty"` + Name *string `json:"name,omitempty"` + SizeInBytes *int64 `json:"size_in_bytes,omitempty"` + URL *string `json:"url,omitempty"` + ArchiveDownloadURL *string `json:"archive_download_url,omitempty"` + Expired *bool `json:"expired,omitempty"` + CreatedAt *Timestamp `json:"created_at,omitempty"` + UpdatedAt *Timestamp `json:"updated_at,omitempty"` + ExpiresAt *Timestamp `json:"expires_at,omitempty"` + WorkflowRun *ArtifactWorkflowRun `json:"workflow_run,omitempty"` } // ArtifactList represents a list of GitHub artifacts. diff --git a/github/actions_artifacts_test.go b/github/actions_artifacts_test.go index e35a873bc0..de07c14f84 100644 --- a/github/actions_artifacts_test.go +++ b/github/actions_artifacts_test.go @@ -438,10 +438,19 @@ func TestArtifact_Marshal(t *testing.T) { NodeID: String("nid"), Name: String("n"), SizeInBytes: Int64(1), + URL: String("u"), ArchiveDownloadURL: String("a"), Expired: Bool(false), CreatedAt: &Timestamp{referenceTime}, + UpdatedAt: &Timestamp{referenceTime}, ExpiresAt: &Timestamp{referenceTime}, + WorkflowRun: &ArtifactWorkflowRun{ + ID: Int64(1), + RepositoryID: Int64(1), + HeadRepositoryID: Int64(1), + HeadBranch: String("b"), + HeadSHA: String("s"), + }, } want := `{ @@ -449,10 +458,19 @@ func TestArtifact_Marshal(t *testing.T) { "node_id": "nid", "name": "n", "size_in_bytes": 1, + "url": "u", "archive_download_url": "a", "expired": false, "created_at": ` + referenceTimeStr + `, - "expires_at": ` + referenceTimeStr + ` + "updated_at": ` + referenceTimeStr + `, + "expires_at": ` + referenceTimeStr + `, + "workflow_run": { + "id": 1, + "repository_id": 1, + "head_repository_id": 1, + "head_branch": "b", + "head_sha": "s" + } }` testJSONMarshal(t, u, want) @@ -469,10 +487,19 @@ func TestArtifactList_Marshal(t *testing.T) { NodeID: String("nid"), Name: String("n"), SizeInBytes: Int64(1), + URL: String("u"), ArchiveDownloadURL: String("a"), Expired: Bool(false), CreatedAt: &Timestamp{referenceTime}, + UpdatedAt: &Timestamp{referenceTime}, ExpiresAt: &Timestamp{referenceTime}, + WorkflowRun: &ArtifactWorkflowRun{ + ID: Int64(1), + RepositoryID: Int64(1), + HeadRepositoryID: Int64(1), + HeadBranch: String("b"), + HeadSHA: String("s"), + }, }, }, } @@ -484,10 +511,19 @@ func TestArtifactList_Marshal(t *testing.T) { "node_id": "nid", "name": "n", "size_in_bytes": 1, + "url": "u", "archive_download_url": "a", "expired": false, "created_at": ` + referenceTimeStr + `, - "expires_at": ` + referenceTimeStr + ` + "updated_at": ` + referenceTimeStr + `, + "expires_at": ` + referenceTimeStr + `, + "workflow_run": { + "id": 1, + "repository_id": 1, + "head_repository_id": 1, + "head_branch": "b", + "head_sha": "s" + } }] }` diff --git a/github/github-accessors.go b/github/github-accessors.go index 433d16f303..63b1079cdf 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -902,6 +902,30 @@ func (a *Artifact) GetSizeInBytes() int64 { return *a.SizeInBytes } +// GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise. +func (a *Artifact) GetUpdatedAt() Timestamp { + if a == nil || a.UpdatedAt == nil { + return Timestamp{} + } + return *a.UpdatedAt +} + +// GetURL returns the URL field if it's non-nil, zero value otherwise. +func (a *Artifact) GetURL() string { + if a == nil || a.URL == nil { + return "" + } + return *a.URL +} + +// GetWorkflowRun returns the WorkflowRun field. +func (a *Artifact) GetWorkflowRun() *ArtifactWorkflowRun { + if a == nil { + return nil + } + return a.WorkflowRun +} + // GetTotalCount returns the TotalCount field if it's non-nil, zero value otherwise. func (a *ArtifactList) GetTotalCount() int64 { if a == nil || a.TotalCount == nil { @@ -910,6 +934,46 @@ func (a *ArtifactList) GetTotalCount() int64 { return *a.TotalCount } +// GetHeadBranch returns the HeadBranch field if it's non-nil, zero value otherwise. +func (a *ArtifactWorkflowRun) GetHeadBranch() string { + if a == nil || a.HeadBranch == nil { + return "" + } + return *a.HeadBranch +} + +// GetHeadRepositoryID returns the HeadRepositoryID field if it's non-nil, zero value otherwise. +func (a *ArtifactWorkflowRun) GetHeadRepositoryID() int64 { + if a == nil || a.HeadRepositoryID == nil { + return 0 + } + return *a.HeadRepositoryID +} + +// GetHeadSHA returns the HeadSHA field if it's non-nil, zero value otherwise. +func (a *ArtifactWorkflowRun) GetHeadSHA() string { + if a == nil || a.HeadSHA == nil { + return "" + } + return *a.HeadSHA +} + +// GetID returns the ID field if it's non-nil, zero value otherwise. +func (a *ArtifactWorkflowRun) GetID() int64 { + if a == nil || a.ID == nil { + return 0 + } + return *a.ID +} + +// GetRepositoryID returns the RepositoryID field if it's non-nil, zero value otherwise. +func (a *ArtifactWorkflowRun) GetRepositoryID() int64 { + if a == nil || a.RepositoryID == nil { + return 0 + } + return *a.RepositoryID +} + // GetBody returns the Body field if it's non-nil, zero value otherwise. func (a *Attachment) GetBody() string { if a == nil || a.Body == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index dbe7a8e908..961eba8288 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -1056,6 +1056,33 @@ func TestArtifact_GetSizeInBytes(tt *testing.T) { a.GetSizeInBytes() } +func TestArtifact_GetUpdatedAt(tt *testing.T) { + var zeroValue Timestamp + a := &Artifact{UpdatedAt: &zeroValue} + a.GetUpdatedAt() + a = &Artifact{} + a.GetUpdatedAt() + a = nil + a.GetUpdatedAt() +} + +func TestArtifact_GetURL(tt *testing.T) { + var zeroValue string + a := &Artifact{URL: &zeroValue} + a.GetURL() + a = &Artifact{} + a.GetURL() + a = nil + a.GetURL() +} + +func TestArtifact_GetWorkflowRun(tt *testing.T) { + a := &Artifact{} + a.GetWorkflowRun() + a = nil + a.GetWorkflowRun() +} + func TestArtifactList_GetTotalCount(tt *testing.T) { var zeroValue int64 a := &ArtifactList{TotalCount: &zeroValue} @@ -1066,6 +1093,56 @@ func TestArtifactList_GetTotalCount(tt *testing.T) { a.GetTotalCount() } +func TestArtifactWorkflowRun_GetHeadBranch(tt *testing.T) { + var zeroValue string + a := &ArtifactWorkflowRun{HeadBranch: &zeroValue} + a.GetHeadBranch() + a = &ArtifactWorkflowRun{} + a.GetHeadBranch() + a = nil + a.GetHeadBranch() +} + +func TestArtifactWorkflowRun_GetHeadRepositoryID(tt *testing.T) { + var zeroValue int64 + a := &ArtifactWorkflowRun{HeadRepositoryID: &zeroValue} + a.GetHeadRepositoryID() + a = &ArtifactWorkflowRun{} + a.GetHeadRepositoryID() + a = nil + a.GetHeadRepositoryID() +} + +func TestArtifactWorkflowRun_GetHeadSHA(tt *testing.T) { + var zeroValue string + a := &ArtifactWorkflowRun{HeadSHA: &zeroValue} + a.GetHeadSHA() + a = &ArtifactWorkflowRun{} + a.GetHeadSHA() + a = nil + a.GetHeadSHA() +} + +func TestArtifactWorkflowRun_GetID(tt *testing.T) { + var zeroValue int64 + a := &ArtifactWorkflowRun{ID: &zeroValue} + a.GetID() + a = &ArtifactWorkflowRun{} + a.GetID() + a = nil + a.GetID() +} + +func TestArtifactWorkflowRun_GetRepositoryID(tt *testing.T) { + var zeroValue int64 + a := &ArtifactWorkflowRun{RepositoryID: &zeroValue} + a.GetRepositoryID() + a = &ArtifactWorkflowRun{} + a.GetRepositoryID() + a = nil + a.GetRepositoryID() +} + func TestAttachment_GetBody(tt *testing.T) { var zeroValue string a := &Attachment{Body: &zeroValue}