Skip to content

Commit

Permalink
update argocd app history command to print group by source
Browse files Browse the repository at this point in the history
Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>
  • Loading branch information
Mangaal committed Mar 13, 2024
1 parent 47bef92 commit 2da370d
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions cmd/argocd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2463,13 +2463,45 @@ func printApplicationHistoryIds(revHistory []argoappv1.RevisionHistory) {
// Print a history table for an application.
func printApplicationHistoryTable(revHistory []argoappv1.RevisionHistory) {
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
_, _ = fmt.Fprintf(w, "ID\tDATE\tREVISION\n")
type history struct {
id int64
date string
revision string
}
varHistory := map[string][]history{}
for _, depInfo := range revHistory {
rev := depInfo.Source.TargetRevision
if len(depInfo.Revision) >= 7 {
rev = fmt.Sprintf("%s (%s)", rev, depInfo.Revision[0:7])
if depInfo.Source.RepoURL != "" {
rev := depInfo.Source.TargetRevision
if len(depInfo.Revision) >= 7 {
rev = fmt.Sprintf("%s (%s)", rev, depInfo.Revision[0:7])
}
varHistory[depInfo.Source.RepoURL] = append(varHistory[depInfo.Source.RepoURL], history{
id: depInfo.ID,
date: fmt.Sprintf("%s", depInfo.DeployedAt),
revision: rev,
})
}
if depInfo.Sources != nil {
for i, sourceInfo := range depInfo.Sources {
rev := sourceInfo.TargetRevision
if len(depInfo.Revisions[i]) >= 7 {
rev = fmt.Sprintf("%s (%s)", rev, depInfo.Revisions[i][0:7])
}
varHistory[sourceInfo.RepoURL] = append(varHistory[sourceInfo.RepoURL], history{
id: depInfo.ID,
date: fmt.Sprintf("%s", depInfo.DeployedAt),
revision: rev,
})
}
}
}
for source, historyEntries := range varHistory {
_, _ = fmt.Fprintf(w, "SOURCE\t%s\n", source)
_, _ = fmt.Fprintf(w, "ID\tDATE\tREVISION\n")
for _, history := range historyEntries {
_, _ = fmt.Fprintf(w, "%d\t%s\t%s\n", history.id, history.date, history.revision)
}
_, _ = fmt.Fprintf(w, "%d\t%s\t%s\n", depInfo.ID, depInfo.DeployedAt, rev)
_, _ = fmt.Fprintf(w, "\n")
}
_ = w.Flush()
}
Expand Down

0 comments on commit 2da370d

Please sign in to comment.