Files
accounting/pkg/invoice/issue/resource.go

36 lines
622 B
Go

package issue
import (
"fmt"
"regexp"
"strings"
"time"
"code.gitea.io/sdk/gitea"
)
type Issue struct {
gitea.Issue
Duration time.Duration
}
func (i Issue) Shorthand() string {
str := i.Repository.Name
if strings.Contains(str, "-") {
s := strings.Split(str, "-")
str = s[len(s)-1]
} else if len(str) > 3 {
str = str[:3]
}
return fmt.Sprintf("%s-%d", strings.ToUpper(str), i.Index)
}
func (i Issue) CleanBody() string {
reBlock := regexp.MustCompile("(?s)```info(.*?)```(.*)")
block := reBlock.FindStringSubmatch(i.Body)
if len(block) < 3 {
return i.Body
}
return strings.TrimSpace(block[2])
}