From 824059cb962035ee6ee68f9c57b26461a59ff93d Mon Sep 17 00:00:00 2001 From: Tomoya Amachi Date: Fri, 27 Dec 2019 04:50:14 +0900 Subject: [PATCH] Time bugfix (#10) * update grouped created at * fill with space --- internal/report/table.go | 16 +++++++++++++++- pkg/provider/dockerhub/dockerhub.go | 5 +++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/internal/report/table.go b/internal/report/table.go index 9042f08..a5bec16 100644 --- a/internal/report/table.go +++ b/internal/report/table.go @@ -25,8 +25,9 @@ func (w TableWriter) Write(tags types.ImageTags) (err error) { targets := utils.StrByLen(tag.Tags) sort.Sort(targets) + // filled with whitespace table.Append([]string{ - strings.Join(targets, tablewriter.NEWLINE), + strings.Join(fillWithSpaces(targets), tablewriter.NEWLINE), getBytesize(tag.Byte), ttos(tag.CreatedAt), ttos(tag.UploadedAt), @@ -39,6 +40,19 @@ func (w TableWriter) Write(tags types.ImageTags) (err error) { return nil } +func fillWithSpaces(tagNames []string) []string { + fillWithSpaces := []string{} + for _, tag := range tagNames { + tagStr := tag + whitespaceCnt := tablewriter.MAX_ROW_WIDTH - len(tag) + if whitespaceCnt > 0 { + tagStr = tag + strings.Repeat(tablewriter.SPACE, whitespaceCnt) + } + fillWithSpaces = append(fillWithSpaces, tagStr) + } + return fillWithSpaces +} + func getBytesize(b int) string { if b == 0 { return "-" diff --git a/pkg/provider/dockerhub/dockerhub.go b/pkg/provider/dockerhub/dockerhub.go index 7e0bd7e..811347d 100644 --- a/pkg/provider/dockerhub/dockerhub.go +++ b/pkg/provider/dockerhub/dockerhub.go @@ -121,6 +121,11 @@ func (p *DockerHub) convertResultToTag(summaries []ImageSummary) types.ImageTags } // update exist ImageTag target.Tags = append(target.Tags, imageSummary.Name) + // TODO : write test codes + createdAt, _ := time.Parse(time.RFC3339Nano, imageSummary.LastUpdated) + if createdAt.After(target.CreatedAt) { + target.CreatedAt = createdAt + } pools[firstHash] = target }