Skip to content

Commit

Permalink
move things around
Browse files Browse the repository at this point in the history
  • Loading branch information
rsese committed Jan 9, 2023
1 parent 583fce1 commit 0651252
Showing 1 changed file with 42 additions and 54 deletions.
96 changes: 42 additions & 54 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,25 +178,7 @@ func workflowHealth(w workflow) string {
return health
}

func noTerminalRender(repos []*repositoryData, selector string, opts *options) error {
totalBillableMs := 0

for _, r := range repos {
workflows, err := getWorkflows(*r, opts.Last)
if err != nil {
return err
}

r.Workflows = workflows

for _, w := range workflows {
totalBillableMs += w.BillableMs
}
}

fmt.Printf("GitHub Actions dashboard for %s for the past %s\n", selector, util.FuzzyAgo(opts.Last))
fmt.Printf("Total billable time: %s\n", util.PrettyMS(totalBillableMs))

func noTerminalRender(repos []*repositoryData) error {
for _, r := range repos {
if len(r.Workflows) == 0 {
continue
Expand Down Expand Up @@ -228,22 +210,8 @@ func noTerminalRender(repos []*repositoryData, selector string, opts *options) e
return nil
}

func _main(opts *options) error {
selector := opts.Selector
last := opts.Last

repos, err := populateRepos(opts)
if err != nil {
return fmt.Errorf("could not fetch repository data: %w", err)
}

func terminalRender(repos []*repositoryData) error {
columnWidth := defaultWorkflowNameLength + 5 // account for ellipsis and padding/border

if !term.IsTerminal(int(os.Stdout.Fd())) {
noTerminalRender(repos, selector, opts)
return nil
}

cardsPerRow := (getTerminalWidth() / columnWidth) - 1

cardStyle := lipgloss.NewStyle().
Expand All @@ -253,29 +221,9 @@ func _main(opts *options) error {
BorderStyle(lipgloss.DoubleBorder()).
BorderForeground(lipgloss.Color("63"))

titleStyle := lipgloss.NewStyle().Bold(true).Align(lipgloss.Center).Width(getTerminalWidth())
subTitleStyle := lipgloss.NewStyle().Align(lipgloss.Center).Width(getTerminalWidth())
repoNameStyle := lipgloss.NewStyle().Bold(true)
repoHintStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("#808080")).Italic(true)

totalBillableMs := 0

for _, r := range repos {
workflows, err := getWorkflows(*r, last)
if err != nil {
return err
}

r.Workflows = workflows

for _, w := range workflows {
totalBillableMs += w.BillableMs
}
}

fmt.Println(titleStyle.Render(fmt.Sprintf("GitHub Actions dashboard for %s for the past %s", selector, util.FuzzyAgo(opts.Last))))
fmt.Println(subTitleStyle.Render(fmt.Sprintf("Total billable time: %s", util.PrettyMS(totalBillableMs))))

for _, r := range repos {
if len(r.Workflows) == 0 {
continue
Expand Down Expand Up @@ -307,6 +255,46 @@ func _main(opts *options) error {
return nil
}

func _main(opts *options) error {
selector := opts.Selector
last := opts.Last

repos, err := populateRepos(opts)
if err != nil {
return fmt.Errorf("could not fetch repository data: %w", err)
}

totalBillableMs := 0

for _, r := range repos {
workflows, err := getWorkflows(*r, last)
if err != nil {
return err
}

r.Workflows = workflows

for _, w := range workflows {
totalBillableMs += w.BillableMs
}
}

if term.IsTerminal(int(os.Stdout.Fd())) {
titleStyle := lipgloss.NewStyle().Bold(true).Align(lipgloss.Center).Width(getTerminalWidth())
subTitleStyle := lipgloss.NewStyle().Align(lipgloss.Center).Width(getTerminalWidth())

fmt.Println(titleStyle.Render(fmt.Sprintf("GitHub Actions dashboard for %s for the past %s", selector, util.FuzzyAgo(opts.Last))))
fmt.Println(subTitleStyle.Render(fmt.Sprintf("Total billable time: %s", util.PrettyMS(totalBillableMs))))
terminalRender(repos)
} else {
fmt.Printf("GitHub Actions dashboard for %s for the past %s\n", selector, util.FuzzyAgo(opts.Last))
fmt.Printf("Total billable time: %s\n", util.PrettyMS(totalBillableMs))
noTerminalRender(repos)
}

return nil
}

func populateRepos(opts *options) ([]*repositoryData, error) {
result := []*repositoryData{}
if len(opts.Repositories) > 0 {
Expand Down

0 comments on commit 0651252

Please sign in to comment.