Skip to content

Commit

Permalink
chore(cleanup): log custom tags info
Browse files Browse the repository at this point in the history
Signed-off-by: Alexey Igrychev <alexey.igrychev@flant.com>
  • Loading branch information
alexey-igrychev committed Feb 7, 2022
1 parent e2c3093 commit d7e8f1f
Showing 1 changed file with 45 additions and 21 deletions.
66 changes: 45 additions & 21 deletions pkg/cleaning/cleanup.go
Expand Up @@ -260,8 +260,9 @@ func (m *cleanupManager) gitHistoryBasedCleanup(ctx context.Context) error {
var reachedStageIDs []string
var hitStageIDCommitList map[string][]string
if err := logboek.Context(ctx).LogProcess(logging.ImageLogProcessName(imageName, false)).DoError(func() error {
if logboek.Context(ctx).Streams().Width() > 90 {
if logboek.Context(ctx).Streams().Width() > 120 {
m.printStageIDCommitListTable(ctx, imageName)
m.printStageIDCustomTagListTable(ctx)
}

if err := logboek.Context(ctx).LogProcess("Scanning git references history").DoError(func() error {
Expand Down Expand Up @@ -312,23 +313,58 @@ func (m *cleanupManager) gitHistoryBasedCleanup(ctx context.Context) error {
}

func (m *cleanupManager) printStageIDCommitListTable(ctx context.Context, imageName string) {
if logboek.Context(ctx).Streams().ContentWidth() < 120 {
stageIDCommitList := m.stageManager.GetStageIDCommitListToCleanup(imageName)
if countStageIDCommitList(stageIDCommitList) == 0 {
return
}

stageIDCommitList := m.stageManager.GetStageIDCommitListToCleanup(imageName)
if countStageIDCommitList(stageIDCommitList) == 0 {
rows := m.prepareStageIDTableRows(ctx, stageIDCommitList)
if len(rows) != 0 {
tbl := table.New("Tag", "Commits")
tbl.WithWriter(logboek.Context(ctx).OutStream())
tbl.WithHeaderFormatter(func(format string, a ...interface{}) string {
return logboek.ColorizeF(color.New(color.OpUnderscore), format, a...)
})
for _, row := range rows {
tbl.AddRow(row...)
}
tbl.Print()

logboek.Context(ctx).LogOptionalLn()
}
}

func (m *cleanupManager) printStageIDCustomTagListTable(ctx context.Context) {
stageIDCustomTagList := m.stageManager.GetCustomTagsMetadata()
if len(stageIDCustomTagList) == 0 {
return
}

rows := m.prepareStageIDTableRows(ctx, stageIDCustomTagList)
if len(rows) != 0 {
tbl := table.New("Tag", "Custom tags")
tbl.WithWriter(logboek.Context(ctx).OutStream())
tbl.WithHeaderFormatter(func(format string, a ...interface{}) string {
return logboek.ColorizeF(color.New(color.OpUnderscore), format, a...)
})
for _, row := range rows {
tbl.AddRow(row...)
}
tbl.Print()

logboek.Context(ctx).LogOptionalLn()
}
}

func (m *cleanupManager) prepareStageIDTableRows(ctx context.Context, stageIDAnyList map[string][]string) [][]interface{} {
var rows [][]interface{}
for stageID, commitList := range stageIDCommitList {
for ind, commit := range commitList {
for stageID, anyList := range stageIDAnyList {
for ind, any := range anyList {
var columns []interface{}
if ind == 0 {
stageIDColumn := stageID

space := len(stageID) - len(commit) - 1
space := len(stageID) - len(any) - 1
if logboek.Context(ctx).Streams().ContentWidth() < space {
stageIDColumn = fmt.Sprintf("%s..%s", stageID[:space-5], stageID[space-3:])
}
Expand All @@ -338,24 +374,12 @@ func (m *cleanupManager) printStageIDCommitListTable(ctx context.Context, imageN
columns = append(columns, "")
}

columns = append(columns, commit)
columns = append(columns, any)
rows = append(rows, columns)
}
}

if len(rows) != 0 {
tbl := table.New("Tag", "Commits")
tbl.WithWriter(logboek.Context(ctx).OutStream())
tbl.WithHeaderFormatter(func(format string, a ...interface{}) string {
return logboek.ColorizeF(color.New(color.OpUnderscore), format, a...)
})
for _, row := range rows {
tbl.AddRow(row...)
}
tbl.Print()

logboek.Context(ctx).LogOptionalLn()
}
return rows
}

func (m *cleanupManager) handleSavedStageIDs(ctx context.Context, savedStageIDs []string) {
Expand Down

0 comments on commit d7e8f1f

Please sign in to comment.