56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package invoice
|
|
|
|
import (
|
|
"io"
|
|
"log/slog"
|
|
"time"
|
|
|
|
"code.gitea.io/sdk/gitea"
|
|
)
|
|
|
|
var DefaultOptions = Options{
|
|
Mindur: time.Minute * 15,
|
|
Since: time.Now().AddDate(0, -1, 0),
|
|
Before: time.Now(),
|
|
IssueState: gitea.StateClosed,
|
|
IssueFilter: func(i *gitea.Issue) bool {
|
|
return i.Closed != nil && i.Closed.After(time.Now().AddDate(0, -1, 0))
|
|
},
|
|
CustomTemplate: "",
|
|
}
|
|
|
|
type Options struct {
|
|
Mindur time.Duration
|
|
Since time.Time
|
|
Before time.Time
|
|
IssueState gitea.StateType
|
|
IssueFilter func(i *gitea.Issue) bool
|
|
CustomTemplate string // if the length of the CustomTemplate is longer than 0, it get's used
|
|
}
|
|
|
|
type Repo struct {
|
|
Owner string `json:"owner"`
|
|
Repo string `json:"repo"`
|
|
}
|
|
|
|
type Service struct {
|
|
log *slog.Logger
|
|
gitea giteaClient
|
|
pdf pdfGenerator
|
|
}
|
|
|
|
func New(log *slog.Logger, gitea giteaClient, pdf pdfGenerator) *Service {
|
|
return &Service{
|
|
log: log,
|
|
gitea: gitea,
|
|
pdf: pdf,
|
|
}
|
|
}
|
|
|
|
type giteaClient interface {
|
|
ListRepoIssues(owner, repo string, opt gitea.ListIssueOption) ([]*gitea.Issue, *gitea.Response, error)
|
|
}
|
|
type pdfGenerator interface {
|
|
HtmlToPdf(html string) (pdf io.ReadCloser, err error)
|
|
}
|