118 lines
2.2 KiB
Go
118 lines
2.2 KiB
Go
package main
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
"time"
|
|
|
|
"code.gitea.io/sdk/gitea"
|
|
"git.schreifuchs.ch/lou-taylor/accounting/issue"
|
|
"git.schreifuchs.ch/lou-taylor/accounting/model"
|
|
"git.schreifuchs.ch/lou-taylor/accounting/pdf"
|
|
"git.schreifuchs.ch/lou-taylor/accounting/report"
|
|
)
|
|
|
|
type Repo struct {
|
|
owner string
|
|
repo string
|
|
}
|
|
|
|
func main() {
|
|
client, err := gitea.NewClient(
|
|
"https://git.schreifuchs.ch",
|
|
gitea.SetToken("6a8ea8f9de039b0950c634bfea40c6f97f94b06b"),
|
|
)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
var is []*gitea.Issue
|
|
for _, repo := range []Repo{
|
|
{"lou-taylor", "lou-taylor-web"},
|
|
{"lou-taylor", "lou-taylor-api"},
|
|
{"lou-taylor", "accounting"},
|
|
} {
|
|
iss, _, err := client.ListRepoIssues(
|
|
repo.owner,
|
|
repo.repo,
|
|
gitea.ListIssueOption{
|
|
ListOptions: gitea.ListOptions{Page: 0, PageSize: 99999},
|
|
Since: time.Now().AddDate(0, -1, 0),
|
|
Before: time.Now(),
|
|
State: gitea.StateClosed,
|
|
},
|
|
)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
is = append(is, iss...)
|
|
}
|
|
|
|
is = Filter(
|
|
is,
|
|
func(i *gitea.Issue) bool {
|
|
return i.Closed != nil && i.Closed.After(time.Now().AddDate(0, -1, 0))
|
|
},
|
|
)
|
|
issues := issue.FromGiteas(is, time.Minute*15)
|
|
r := report.New(
|
|
issues,
|
|
model.Entity{
|
|
Name: "schreifuchs.ch",
|
|
IBAN: "CH06 0079 0042 5877 0443 7",
|
|
Address: model.Address{
|
|
Street: "Kilchbergerweg",
|
|
Number: "1",
|
|
ZIPCode: "3052",
|
|
Place: "Zollikofen",
|
|
Country: "Schweiz",
|
|
},
|
|
Contact: "Niklas Breitenstein",
|
|
},
|
|
model.Entity{
|
|
Name: "Lou Taylor",
|
|
Address: model.Address{
|
|
Street: "Alpenstrasse",
|
|
Number: "22",
|
|
ZIPCode: "4950",
|
|
Place: "Huttwil",
|
|
Country: "Schweiz",
|
|
},
|
|
Contact: "Loana Groux",
|
|
},
|
|
16,
|
|
)
|
|
html := r.ToHTML()
|
|
|
|
file, err := os.Create("index.html")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer file.Close()
|
|
|
|
file.Write([]byte(html))
|
|
|
|
// fmt.Print(html)
|
|
pdfs, err := pdf.New("http://localhost:3030")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
ducument, err := pdfs.HtmlToPdf(html)
|
|
|
|
io.Copy(os.Stdout, ducument)
|
|
}
|
|
|
|
func Filter[T any](slice []T, ok func(T) bool) []T {
|
|
out := make([]T, 0, len(slice))
|
|
|
|
for _, item := range slice {
|
|
if ok(item) {
|
|
out = append(out, item)
|
|
}
|
|
}
|
|
|
|
return out
|
|
}
|