Skip to content

Commit

Permalink
pipeline list - add start date and duration
Browse files Browse the repository at this point in the history
  • Loading branch information
3ximus committed Jan 29, 2024
1 parent 79554f1 commit ec08eaa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 5 additions & 2 deletions cmd/pipeline/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bb/api"
"bb/util"
"fmt"
"time"

"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -24,11 +25,13 @@ var ListCmd = &cobra.Command{
}
fmt.Printf(" \033[1;32m#%d\033[m ", pipeline.BuildNumber)
if pipeline.Target.Source != "" {
fmt.Printf("%s \033[1;34m[ %s → %s]\033[m\n", pipeline.Target.PullRequest.Title, pipeline.Target.Source, pipeline.Target.Destination)
fmt.Printf("%s \033[1;34m[ %s → %s]\033[m", pipeline.Target.PullRequest.Title, pipeline.Target.Source, pipeline.Target.Destination)
} else {
fmt.Printf("\033[1;34m[ %s ]\033[m\n", pipeline.Target.RefName)
fmt.Printf("\033[1;34m[ %s ]\033[m", pipeline.Target.RefName)
}

fmt.Printf(" \033[37m%s (%s)\033[m\n", util.TimeDuration(time.Duration(pipeline.DurationInSeconds*1000000000)), util.TimeAgo(pipeline.CreatedOn))

fmt.Printf(" \033[33m%s\033[m \033[37mTrigger: %s\033[m\n", pipeline.Author.DisplayName, pipeline.Trigger.Name) // \033[37mComments: %d\033[m",
}
},
Expand Down
14 changes: 9 additions & 5 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,22 @@ func FormatIssuePriority(id string, name string) string {

func TimeAgo(updatedOn time.Time) string {
duration := time.Since(updatedOn)
return fmt.Sprintf("%s ago", TimeDuration(duration))
}

func TimeDuration(duration time.Duration) string {
if duration.Hours() < 1 {
return fmt.Sprintf("%d minutes ago", int(duration.Minutes()))
return fmt.Sprintf("%d minutes", int(duration.Minutes()))
} else if duration.Hours() < 24 {
return fmt.Sprintf("%d hours ago", int(duration.Hours()))
return fmt.Sprintf("%d hours", int(duration.Hours()))
} else if duration.Hours() < 48 {
return "yesterday"
} else if duration.Hours() < 720 {
return fmt.Sprintf("%d days ago", int(duration.Hours()/24))
return fmt.Sprintf("%d days", int(duration.Hours()/24))
} else if duration.Hours() < 8760 {
return fmt.Sprintf("%d months ago", int(duration.Hours()/720))
return fmt.Sprintf("%d months", int(duration.Hours()/720))
}
return fmt.Sprintf("%d years ago", int(duration.Hours()/8760))
return fmt.Sprintf("%d years", int(duration.Hours()/8760))
}

func ConvertToSeconds(timeStrings []string) (int, error) {
Expand Down

0 comments on commit ec08eaa

Please sign in to comment.