From 6c914738a25376abbee4081d627875eba50b594e Mon Sep 17 00:00:00 2001 From: Noah Date: Thu, 21 Mar 2024 18:28:19 -0500 Subject: [PATCH] feat(times): Display server name in times table (fix #11) --- config.go | 5 +++-- summary.go | 2 +- times.go | 22 +++++++++++++++------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/config.go b/config.go index 5fc56fc..0d8f02e 100644 --- a/config.go +++ b/config.go @@ -16,7 +16,7 @@ type Server struct { // Configuration holds data retrieved from a Lua script. type Configuration struct { - servers []*Server + servers map[string]*Server } // parseText parses a text value from the configuration file. @@ -51,6 +51,7 @@ func parseServerFromTable(L *lua.LState, table lua.LValue) (Server, error) { // Configuration.Parse parses a Lua configuration file into a Configuration struct. func (config *Configuration) Parse(fname string) error { + config.servers = make(map[string]*Server) L := lua.NewState() defer L.Close() @@ -60,7 +61,7 @@ func (config *Configuration) Parse(fname string) error { for i := 1; i <= L.ObjLen(table); i++ { lserver := L.GetTable(table, lua.LNumber(i)) if server, err := parseServerFromTable(L, lserver); err == nil { - config.servers = append(config.servers, &server) + config.servers[server.servername] = &server } else { return err } diff --git a/summary.go b/summary.go index eff2c9f..f8faa19 100644 --- a/summary.go +++ b/summary.go @@ -9,7 +9,7 @@ import ( ) type summaryviewer struct { - times []gitea.TrackedTime + times []TrackedTime total_time time.Duration quitting bool } diff --git a/times.go b/times.go index 0deefe5..e8e7116 100644 --- a/times.go +++ b/times.go @@ -13,10 +13,16 @@ import ( "code.gitea.io/sdk/gitea" ) +// TrackedTime is an extended gitea.TrackedTime struct +type TrackedTime struct { + gitea.TrackedTime + server Server +} + // getTimeLogs gets every single time log possible. -func getTimeLogs(since time.Time, on_process_repo func(repo gitea.Repository, took time.Duration)) []gitea.TrackedTime { - var times []gitea.TrackedTime - for _, client := range Servers { +func getTimeLogs(since time.Time, on_process_repo func(repo gitea.Repository, took time.Duration)) []TrackedTime { + var times []TrackedTime + for server_name, client := range Servers { page := 1 user, _, err := client.GetMyUserInfo() if err != nil { @@ -50,7 +56,7 @@ func getTimeLogs(since time.Time, on_process_repo func(repo gitea.Repository, to }, ) for _, t := range repo_times { - times = append(times, *t) + times = append(times, TrackedTime{TrackedTime: *t, server: *config.servers[server_name]}) } on_process_repo(*repo, time.Now().Sub(duration_start)) } @@ -125,9 +131,10 @@ func times() { var total_time time.Duration columns := []table.Column{ - {Title: "User", Width: 10}, + {Title: "Server", Width: 10}, + {Title: "User", Width: 8}, {Title: "Time", Width: 8}, - {Title: "Created at", Width: 15}, + {Title: "Created at", Width: 11}, } rows := []table.Row{} for _, t := range times { @@ -136,9 +143,10 @@ func times() { panic(err) } rows = append(rows, table.Row{ + t.server.servername, t.UserName, dur.String(), - t.Created.String(), + t.Created.Format(time.DateOnly), }) total_time += dur }