[times] Don't panic when failing to get time track logs

This commit is contained in:
Noah 2024-03-17 17:59:42 -05:00
parent 651e6ac7dc
commit dfeef3e271

View File

@ -5,20 +5,20 @@ import (
"os" "os"
"time" "time"
"github.com/charmbracelet/bubbles/table"
"github.com/charmbracelet/bubbles/spinner" "github.com/charmbracelet/bubbles/spinner"
"github.com/charmbracelet/bubbles/table"
tea "github.com/charmbracelet/bubbletea" tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss" "github.com/charmbracelet/lipgloss"
"code.gitea.io/sdk/gitea" "code.gitea.io/sdk/gitea"
) )
var helpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#626262")).Render var helpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#626262")).Render
type timesviewer struct { type timesviewer struct {
table table.Model table table.Model
} }
func (m timesviewer) Init() tea.Cmd { func (m timesviewer) Init() tea.Cmd {
return nil return nil
} }
@ -45,10 +45,11 @@ func (m timesviewer) View() string {
} }
type indicator struct { type indicator struct {
spinner spinner.Model spinner spinner.Model
quitting bool quitting bool
err error err error
} }
func initialIndicator() indicator { func initialIndicator() indicator {
s := spinner.New() s := spinner.New()
s.Spinner = spinner.Dot s.Spinner = spinner.Dot
@ -105,10 +106,14 @@ func times() {
if repo.Fork { if repo.Fork {
continue continue
} }
repo_times, _, err := client.ListRepoTrackedTimes(repo.Owner.UserName, repo.Name, gitea.ListTrackedTimesOptions{User: user.UserName, Since: since}) repo_times, _, _ := client.ListRepoTrackedTimes(
if err != nil { repo.Owner.UserName,
panic(err) repo.Name,
} gitea.ListTrackedTimesOptions{
User: user.UserName,
Since: since,
},
)
for _, t := range repo_times { for _, t := range repo_times {
times = append(times, *t) times = append(times, *t)
} }
@ -125,7 +130,7 @@ func times() {
} }
rows := []table.Row{} rows := []table.Row{}
for _, t := range times { for _, t := range times {
dur, err := time.ParseDuration(fmt.Sprint(t.Time)+"s") dur, err := time.ParseDuration(fmt.Sprint(t.Time) + "s")
if err != nil { if err != nil {
panic(err) panic(err)
} }