Merge pull request #11030 from cli/bdehamer/release-asset-digest

Add Digest to ReleaseAsset struct
This commit is contained in:
Andy Feller 2025-05-29 15:11:16 -04:00 committed by GitHub
commit 79fc854814
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 8 deletions

View file

@ -71,6 +71,7 @@ type ReleaseAsset struct {
Name string
Label string
Size int64
Digest *string
State string
APIURL string `json:"url"`
@ -107,6 +108,7 @@ func (rel *Release) ExportData(fields []string) map[string]interface{} {
"name": a.Name,
"label": a.Label,
"size": a.Size,
"digest": a.Digest,
"state": a.State,
"createdAt": a.CreatedAt,
"updatedAt": a.UpdatedAt,

View file

@ -154,10 +154,14 @@ func renderReleaseTTY(io *iostreams.IOStreams, release *shared.Release) error {
if len(release.Assets) > 0 {
fmt.Fprintln(w, cs.Bold("Assets"))
//nolint:staticcheck // SA1019: Showing NAME|SIZE headers adds nothing to table.
table := tableprinter.New(io, tableprinter.NoHeader)
table := tableprinter.New(io, tableprinter.WithHeader("Name", "Digest", "Size"))
for _, a := range release.Assets {
table.AddField(a.Name)
if a.Digest == nil {
table.AddField("")
} else {
table.AddField(*a.Digest)
}
table.AddField(humanFileSize(a.Size))
table.EndRow()
}

View file

@ -150,8 +150,9 @@ func Test_viewRun(t *testing.T) {
Assets
windows.zip 12 B
linux.tgz 34 B
NAME DIGEST SIZE
windows.zip sha256:deadc0de 12 B
linux.tgz 34 B
View on GitHub: https://github.com/OWNER/REPO/releases/tags/v1.2.3
`),
@ -174,8 +175,9 @@ func Test_viewRun(t *testing.T) {
Assets
windows.zip 12 B
linux.tgz 34 B
NAME DIGEST SIZE
windows.zip sha256:deadc0de 12 B
linux.tgz 34 B
View on GitHub: https://github.com/OWNER/REPO/releases/tags/v1.2.3
`),
@ -248,8 +250,8 @@ func Test_viewRun(t *testing.T) {
"published_at": "%[1]s",
"html_url": "https://github.com/OWNER/REPO/releases/tags/v1.2.3",
"assets": [
{ "name": "windows.zip", "size": 12 },
{ "name": "linux.tgz", "size": 34 }
{ "name": "windows.zip", "size": 12, "digest": "sha256:deadc0de" },
{ "name": "linux.tgz", "size": 34, "digest": null }
]
}`, tt.releasedAt.Format(time.RFC3339), tt.releaseBody))