From 774d5acbd21f9546aec6f3862126e33c768bbdfd Mon Sep 17 00:00:00 2001 From: schreifuchs Date: Wed, 3 Dec 2025 20:45:48 +0100 Subject: [PATCH] feat: better debug logs --- pkg/invoice/invoice.go | 27 +++++++++++++++++++-------- pkg/invoice/invoice_test.go | 13 +++++++------ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/pkg/invoice/invoice.go b/pkg/invoice/invoice.go index e707da0..7ac0224 100644 --- a/pkg/invoice/invoice.go +++ b/pkg/invoice/invoice.go @@ -9,7 +9,7 @@ import ( "git.schreifuchs.ch/lou-taylor/accounting/pkg/invoice/report" ) -func (s *Service) Generate(creditor model.Entity, deptor *model.Entity, rate float64, repos []Repo, config *Options) (document io.ReadCloser, r report.Report, err error) { +func (s *Service) Generate(creditor model.Entity, debtor *model.Entity, rate float64, repos []Repo, config *Options) (document io.ReadCloser, r report.Report, err error) { if config == nil { config = &DefaultOptions } @@ -32,12 +32,21 @@ func (s *Service) Generate(creditor model.Entity, deptor *model.Entity, rate flo is = append(is, iss...) } - is = filter(is, config.IssueFilter) + { + issueURLs := make([]string, 0, len(is)) + for _, issue := range is { + issueURLs = append(issueURLs, issue.HTMLURL) + } + s.log.Debug("loaded all issues", "issueURLs", issueURLs) + } + + is = s.filterIssues(is, config.IssueFilter) + issues := issue.FromGiteas(is, config.Mindur) r = report.New( issues, creditor, - deptor, + debtor, rate, ) @@ -53,12 +62,14 @@ func (s *Service) Generate(creditor model.Entity, deptor *model.Entity, rate flo return document, r, err } -func filter[T any](slice []T, ok func(T) bool) []T { - out := make([]T, 0, len(slice)) +func (s *Service) filterIssues(slice []*gitea.Issue, ok func(*gitea.Issue) bool) []*gitea.Issue { + out := make([]*gitea.Issue, 0, len(slice)) - for _, item := range slice { - if ok(item) { - out = append(out, item) + for _, issue := range slice { + if ok(issue) { + out = append(out, issue) + } else { + s.log.Debug("filter out issue", "issueURL", issue.HTMLURL) } } diff --git a/pkg/invoice/invoice_test.go b/pkg/invoice/invoice_test.go index 6a536eb..fd125b6 100644 --- a/pkg/invoice/invoice_test.go +++ b/pkg/invoice/invoice_test.go @@ -41,7 +41,7 @@ func TestGenerate(t *testing.T) { creditor := model.Entity{ Name: "creditor", } - deptor := model.Entity{ + debtor := model.Entity{ Name: "deptor", } rate := 100.0 @@ -135,12 +135,12 @@ func TestGenerate(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { giteaClient := new(MockGiteaClient) - -pdfGenerator := new(MockPdfGenerator) - tc.setupMocks(giteaClient, pdfGenerator) + + pdfGenerator := new(MockPdfGenerator) + tc.setupMocks(giteaClient, pdfGenerator) service := New(slog.Default(), giteaClient, pdfGenerator) - doc, _, err := service.Generate(creditor, &deptor, rate, repos, tc.config) + doc, _, err := service.Generate(creditor, &debtor, rate, repos, tc.config) if tc.expectedError != "" { if err == nil { @@ -159,4 +159,5 @@ pdfGenerator := new(MockPdfGenerator) } }) } -} \ No newline at end of file +} +