From 6eb01b6ee92a0fc2463535bb322e4c247a13f710 Mon Sep 17 00:00:00 2001 From: hiifong Date: Thu, 12 Dec 2024 01:14:46 +0800 Subject: [PATCH 1/5] Update --- modules/base/tool.go | 8 ++++++++ modules/templates/helper.go | 1 + templates/package/content/container.tmpl | 12 +++++++----- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/modules/base/tool.go b/modules/base/tool.go index 928c80700b828..c18bc1648b366 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -41,6 +41,14 @@ func ShortSha(sha1 string) string { return TruncateString(sha1, 10) } +// ShortSha256 takes 7-17 indexes of sha256 string as short sha256 +func ShortSha256(sha256 string) string { + if utf8.RuneCountInString(sha256) < 17 { + return sha256 + } + return string([]rune(sha256)[7:17]) +} + // BasicAuthDecode decode basic auth string func BasicAuthDecode(encoded string) (string, string, error) { s, err := base64.StdEncoding.DecodeString(encoded) diff --git a/modules/templates/helper.go b/modules/templates/helper.go index ff9673ccef781..13d45b8306f0c 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -162,6 +162,7 @@ func NewFuncMap() template.FuncMap { // ----------------------------------------------------------------- // misc "ShortSha": base.ShortSha, + "ShortSha256": base.ShortSha256, "ActionContent2Commits": ActionContent2Commits, "IsMultilineCommitMessage": isMultilineCommitMessage, "CommentMustAsDiff": gitdiff.CommentMustAsDiff, diff --git a/templates/package/content/container.tmpl b/templates/package/content/container.tmpl index aaed25bfbd61d..d651ec6bb70f5 100644 --- a/templates/package/content/container.tmpl +++ b/templates/package/content/container.tmpl @@ -36,11 +36,13 @@ {{range .PackageDescriptor.Metadata.Manifests}} - - {{.Digest}} - {{.Platform}} - {{FileSize .Size}} - + {{if ne .Platform "unknown/unknown"}} + + {{ShortSha256 .Digest}} + {{.Platform}} + {{FileSize .Size}} + + {{end}} {{end}} From 1c5a28915b6a7dc36ba6eed07bd7d9563a273e9d Mon Sep 17 00:00:00 2001 From: hiifong Date: Sun, 15 Dec 2024 16:27:28 +0800 Subject: [PATCH 2/5] Update templates/package/content/container.tmpl Co-authored-by: silverwind --- templates/package/content/container.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/package/content/container.tmpl b/templates/package/content/container.tmpl index d651ec6bb70f5..0124d0287ce76 100644 --- a/templates/package/content/container.tmpl +++ b/templates/package/content/container.tmpl @@ -38,7 +38,7 @@ {{range .PackageDescriptor.Metadata.Manifests}} {{if ne .Platform "unknown/unknown"}} - {{ShortSha256 .Digest}} + {{ShortSha256 .Digest}} {{.Platform}} {{FileSize .Size}} From e0e3a351aa8c8ab160acb05c48e0cc95cd85de2f Mon Sep 17 00:00:00 2001 From: hiifong Date: Sun, 15 Dec 2024 16:56:02 +0800 Subject: [PATCH 3/5] Update --- modules/base/tool.go | 8 -------- modules/templates/helper.go | 1 - modules/templates/util_string.go | 4 ++++ templates/package/content/container.tmpl | 2 +- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/modules/base/tool.go b/modules/base/tool.go index c18bc1648b366..928c80700b828 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -41,14 +41,6 @@ func ShortSha(sha1 string) string { return TruncateString(sha1, 10) } -// ShortSha256 takes 7-17 indexes of sha256 string as short sha256 -func ShortSha256(sha256 string) string { - if utf8.RuneCountInString(sha256) < 17 { - return sha256 - } - return string([]rune(sha256)[7:17]) -} - // BasicAuthDecode decode basic auth string func BasicAuthDecode(encoded string) (string, string, error) { s, err := base64.StdEncoding.DecodeString(encoded) diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 13d45b8306f0c..ff9673ccef781 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -162,7 +162,6 @@ func NewFuncMap() template.FuncMap { // ----------------------------------------------------------------- // misc "ShortSha": base.ShortSha, - "ShortSha256": base.ShortSha256, "ActionContent2Commits": ActionContent2Commits, "IsMultilineCommitMessage": isMultilineCommitMessage, "CommentMustAsDiff": gitdiff.CommentMustAsDiff, diff --git a/modules/templates/util_string.go b/modules/templates/util_string.go index 2ae27d0833687..382e2de13f1e2 100644 --- a/modules/templates/util_string.go +++ b/modules/templates/util_string.go @@ -60,3 +60,7 @@ func (su *StringUtils) EllipsisString(s string, maxLength int) string { func (su *StringUtils) ToUpper(s string) string { return strings.ToUpper(s) } + +func (su *StringUtils) TrimPrefix(s, prefix string) string { + return strings.TrimPrefix(s, prefix) +} diff --git a/templates/package/content/container.tmpl b/templates/package/content/container.tmpl index 0124d0287ce76..fac07171a50a0 100644 --- a/templates/package/content/container.tmpl +++ b/templates/package/content/container.tmpl @@ -38,7 +38,7 @@ {{range .PackageDescriptor.Metadata.Manifests}} {{if ne .Platform "unknown/unknown"}} - {{ShortSha256 .Digest}} + {{StringUtils.TrimPrefix .Digest "sha256:" | ShortSha}} {{.Platform}} {{FileSize .Size}} From d9aa90453e4e00af2cea72ad6be46a2068f5bc9f Mon Sep 17 00:00:00 2001 From: hiifong Date: Sun, 15 Dec 2024 21:25:42 +0800 Subject: [PATCH 4/5] Update --- templates/package/content/container.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/package/content/container.tmpl b/templates/package/content/container.tmpl index fac07171a50a0..bfc82082f79e8 100644 --- a/templates/package/content/container.tmpl +++ b/templates/package/content/container.tmpl @@ -38,7 +38,7 @@ {{range .PackageDescriptor.Metadata.Manifests}} {{if ne .Platform "unknown/unknown"}} - {{StringUtils.TrimPrefix .Digest "sha256:" | ShortSha}} + {{StringUtils.TrimPrefix .Digest "sha256:" | ShortSha}} {{.Platform}} {{FileSize .Size}} From 0a59e1afdb7831c2382923b1d58f271612e18dc2 Mon Sep 17 00:00:00 2001 From: hiifong Date: Sun, 15 Dec 2024 21:31:56 +0800 Subject: [PATCH 5/5] Update --- templates/package/content/container.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/package/content/container.tmpl b/templates/package/content/container.tmpl index bfc82082f79e8..207774bfefd03 100644 --- a/templates/package/content/container.tmpl +++ b/templates/package/content/container.tmpl @@ -38,7 +38,7 @@ {{range .PackageDescriptor.Metadata.Manifests}} {{if ne .Platform "unknown/unknown"}} - {{StringUtils.TrimPrefix .Digest "sha256:" | ShortSha}} + {{StringUtils.TrimPrefix .Digest "sha256:" | ShortSha}} {{.Platform}} {{FileSize .Size}}