feat: config

This commit is contained in:
2025-08-24 14:23:51 +02:00
parent 0f3da902dc
commit 958979c62b
9 changed files with 159 additions and 86 deletions

96
main.go
View File

@@ -1,40 +1,39 @@
package main
import (
"os"
"time"
"code.gitea.io/sdk/gitea"
"git.schreifuchs.ch/lou-taylor/accounting/issue"
"git.schreifuchs.ch/lou-taylor/accounting/mailer"
"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
Owner string `json:"owner"`
Repo string `json:"repo"`
}
func main() {
cfg, err := LoadConfig("config.json")
if err != nil {
panic(err)
}
client, err := gitea.NewClient(
"https://git.schreifuchs.ch",
gitea.SetToken("6a8ea8f9de039b0950c634bfea40c6f97f94b06b"),
cfg.GiteaURL,
gitea.SetToken(cfg.GiteaToken),
)
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"},
} {
for _, repo := range cfg.Repos {
iss, _, err := client.ListRepoIssues(
repo.owner,
repo.repo,
repo.Owner,
repo.Repo,
gitea.ListIssueOption{
ListOptions: gitea.ListOptions{Page: 0, PageSize: 99999},
Since: time.Now().AddDate(0, -1, 0),
@@ -55,46 +54,16 @@ func main() {
return i.Closed != nil && i.Closed.After(time.Now().AddDate(0, -1, 0))
},
)
issues := issue.FromGiteas(is, time.Minute*15)
issues := issue.FromGiteas(is, time.Duration(cfg.MinDuration))
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,
cfg.FromEntity,
cfg.ToEntity,
cfg.Hourly,
)
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")
pdfs, err := pdf.New(cfg.PdfGeneratorURL)
if err != nil {
panic(err)
}
@@ -104,30 +73,21 @@ func main() {
panic(err)
}
mlr, err := mailer.New(mailer.Config{
SMTP: mailer.SMTPConfig{
Host: "mail.your-server.de",
Port: "465",
User: "test@schreifuchs.ch",
Password: "xV27D1nj33dNz8B4",
},
From: "test@schreifuchs.ch",
})
mlr, err := mailer.New(cfg.Mailer)
if err != nil {
panic(err)
}
err = mlr.Send(mailer.Mail{
TO: "kontakt@schreifuchs.ch",
Subject: "test",
Body: "Hallo",
Attachments: []mailer.Attachment{
{
Name: "invoice.pdf",
MimeType: "pdf",
Content: document,
},
mail := cfg.Mail
mail.Attachments = []mailer.Attachment{
{
Name: "invoice.pdf",
MimeType: "pdf",
Content: document,
},
})
}
err = mlr.Send(mail)
if err != nil {
panic(err)
}