refactor(times): Move Gitea time log API code into getTimeLogs()
This commit is contained in:
parent
f8d6d8f5b2
commit
6b5ad657b6
85
times.go
85
times.go
@ -14,6 +14,53 @@ import (
|
|||||||
"code.gitea.io/sdk/gitea"
|
"code.gitea.io/sdk/gitea"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 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 Clients {
|
||||||
|
page := 1
|
||||||
|
user, _, err := client.GetMyUserInfo()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
for {
|
||||||
|
repos, _, err := client.ListMyRepos(
|
||||||
|
gitea.ListReposOptions{
|
||||||
|
ListOptions: gitea.ListOptions{
|
||||||
|
Page: page,
|
||||||
|
PageSize: 10,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
} else if len(repos) == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
for _, repo := range repos {
|
||||||
|
if repo.Fork {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
duration_start := time.Now()
|
||||||
|
repo_times, _, _ := client.ListRepoTrackedTimes(
|
||||||
|
repo.Owner.UserName,
|
||||||
|
repo.Name,
|
||||||
|
gitea.ListTrackedTimesOptions{
|
||||||
|
User: user.UserName,
|
||||||
|
Since: since,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
for _, t := range repo_times {
|
||||||
|
times = append(times, *t)
|
||||||
|
}
|
||||||
|
on_process_repo(*repo, time.Now().Sub(duration_start))
|
||||||
|
}
|
||||||
|
page++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return times
|
||||||
|
}
|
||||||
|
|
||||||
var textStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#5b6078"))
|
var textStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#5b6078"))
|
||||||
|
|
||||||
type timesviewer struct {
|
type timesviewer struct {
|
||||||
@ -116,45 +163,13 @@ func times() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var times []gitea.TrackedTime
|
|
||||||
since := time.Now().AddDate(0, 0, -7)
|
since := time.Now().AddDate(0, 0, -7)
|
||||||
for _, client := range Clients {
|
times := getTimeLogs(since, func(repo gitea.Repository, took time.Duration) {
|
||||||
page := 1
|
|
||||||
user, _, err := client.GetMyUserInfo()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
for {
|
|
||||||
repos, _, err := client.ListMyRepos(gitea.ListReposOptions{ListOptions: gitea.ListOptions{Page: page, PageSize: 10}})
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
} else if len(repos) == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
for _, repo := range repos {
|
|
||||||
if repo.Fork {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
duration_start := time.Now()
|
|
||||||
repo_times, _, _ := client.ListRepoTrackedTimes(
|
|
||||||
repo.Owner.UserName,
|
|
||||||
repo.Name,
|
|
||||||
gitea.ListTrackedTimesOptions{
|
|
||||||
User: user.UserName,
|
|
||||||
Since: since,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
for _, t := range repo_times {
|
|
||||||
times = append(times, *t)
|
|
||||||
}
|
|
||||||
p.Send(IndicatorInfo{
|
p.Send(IndicatorInfo{
|
||||||
info: fmt.Sprintf("%s / %s", repo.Owner.UserName, repo.Name),
|
info: fmt.Sprintf("%s / %s", repo.Owner.UserName, repo.Name),
|
||||||
duration: time.Now().Sub(duration_start),
|
duration: took,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
|
||||||
page++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
p.Send(IndicatorInfo{
|
p.Send(IndicatorInfo{
|
||||||
info: "Done!",
|
info: "Done!",
|
||||||
quitting: true,
|
quitting: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user