feat(times): Display server name in times table (fix #11)
This commit is contained in:
parent
98788aeede
commit
6c914738a2
@ -16,7 +16,7 @@ type Server struct {
|
|||||||
|
|
||||||
// Configuration holds data retrieved from a Lua script.
|
// Configuration holds data retrieved from a Lua script.
|
||||||
type Configuration struct {
|
type Configuration struct {
|
||||||
servers []*Server
|
servers map[string]*Server
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseText parses a text value from the configuration file.
|
// 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.
|
// Configuration.Parse parses a Lua configuration file into a Configuration struct.
|
||||||
func (config *Configuration) Parse(fname string) error {
|
func (config *Configuration) Parse(fname string) error {
|
||||||
|
config.servers = make(map[string]*Server)
|
||||||
L := lua.NewState()
|
L := lua.NewState()
|
||||||
defer L.Close()
|
defer L.Close()
|
||||||
|
|
||||||
@ -60,7 +61,7 @@ func (config *Configuration) Parse(fname string) error {
|
|||||||
for i := 1; i <= L.ObjLen(table); i++ {
|
for i := 1; i <= L.ObjLen(table); i++ {
|
||||||
lserver := L.GetTable(table, lua.LNumber(i))
|
lserver := L.GetTable(table, lua.LNumber(i))
|
||||||
if server, err := parseServerFromTable(L, lserver); err == nil {
|
if server, err := parseServerFromTable(L, lserver); err == nil {
|
||||||
config.servers = append(config.servers, &server)
|
config.servers[server.servername] = &server
|
||||||
} else {
|
} else {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type summaryviewer struct {
|
type summaryviewer struct {
|
||||||
times []gitea.TrackedTime
|
times []TrackedTime
|
||||||
total_time time.Duration
|
total_time time.Duration
|
||||||
quitting bool
|
quitting bool
|
||||||
}
|
}
|
||||||
|
22
times.go
22
times.go
@ -13,10 +13,16 @@ import (
|
|||||||
"code.gitea.io/sdk/gitea"
|
"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.
|
// getTimeLogs gets every single time log possible.
|
||||||
func getTimeLogs(since time.Time, on_process_repo func(repo gitea.Repository, took time.Duration)) []gitea.TrackedTime {
|
func getTimeLogs(since time.Time, on_process_repo func(repo gitea.Repository, took time.Duration)) []TrackedTime {
|
||||||
var times []gitea.TrackedTime
|
var times []TrackedTime
|
||||||
for _, client := range Servers {
|
for server_name, client := range Servers {
|
||||||
page := 1
|
page := 1
|
||||||
user, _, err := client.GetMyUserInfo()
|
user, _, err := client.GetMyUserInfo()
|
||||||
if err != nil {
|
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 {
|
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))
|
on_process_repo(*repo, time.Now().Sub(duration_start))
|
||||||
}
|
}
|
||||||
@ -125,9 +131,10 @@ func times() {
|
|||||||
var total_time time.Duration
|
var total_time time.Duration
|
||||||
|
|
||||||
columns := []table.Column{
|
columns := []table.Column{
|
||||||
{Title: "User", Width: 10},
|
{Title: "Server", Width: 10},
|
||||||
|
{Title: "User", Width: 8},
|
||||||
{Title: "Time", Width: 8},
|
{Title: "Time", Width: 8},
|
||||||
{Title: "Created at", Width: 15},
|
{Title: "Created at", Width: 11},
|
||||||
}
|
}
|
||||||
rows := []table.Row{}
|
rows := []table.Row{}
|
||||||
for _, t := range times {
|
for _, t := range times {
|
||||||
@ -136,9 +143,10 @@ func times() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
rows = append(rows, table.Row{
|
rows = append(rows, table.Row{
|
||||||
|
t.server.servername,
|
||||||
t.UserName,
|
t.UserName,
|
||||||
dur.String(),
|
dur.String(),
|
||||||
t.Created.String(),
|
t.Created.Format(time.DateOnly),
|
||||||
})
|
})
|
||||||
total_time += dur
|
total_time += dur
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user