Skip to content

Commit

Permalink
Add URL, UpdateAt, and WorkflowRun fields to Artifacts (#2660)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryancallahan committed Feb 6, 2023
1 parent 0af462f commit c855eb5
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 11 deletions.
32 changes: 23 additions & 9 deletions github/actions_artifacts.go
Expand Up @@ -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.
Expand Down
40 changes: 38 additions & 2 deletions github/actions_artifacts_test.go
Expand Up @@ -438,21 +438,39 @@ 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 := `{
"id": 1,
"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)
Expand All @@ -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"),
},
},
},
}
Expand All @@ -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"
}
}]
}`

Expand Down
64 changes: 64 additions & 0 deletions github/github-accessors.go

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

77 changes: 77 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.

0 comments on commit c855eb5

Please sign in to comment.