feat(times): Display server name in times table (fix #11)

This commit is contained in:
Noah 2024-03-21 18:28:19 -05:00
parent 98788aeede
commit 6c914738a2
3 changed files with 19 additions and 10 deletions

View File

@ -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
}

View File

@ -9,7 +9,7 @@ import (
)
type summaryviewer struct {
times []gitea.TrackedTime
times []TrackedTime
total_time time.Duration
quitting bool
}

View File

@ -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
}