Some cleanup

This commit is contained in:
Olivier Tremblay 2025-11-26 11:34:13 -05:00
parent d3386d4a58
commit 4f44943d90
7 changed files with 90 additions and 19 deletions

View file

@ -33,22 +33,39 @@ type PullRequest struct {
URL string
}
// String returns a formatted string representation of the PullRequest
func (pr PullRequest) String() string {
tmpl := template.Must(template.New("pr").Parse(`- Title: {{.Title}}
var prtmpl = template.Must(template.New("pr").Parse(`- Title: {{.Title}}
Body: {{.Body}}
`))
// String returns a formatted string representation of the PullRequest
func (pr PullRequest) String() string {
var buf bytes.Buffer
err := tmpl.Execute(&buf, pr)
err := prtmpl.Execute(&buf, pr)
if err != nil {
return "" // Return empty string on error
}
return buf.String()
}
func GetPRs(org, username string, from string, to string) (map[string][]PullRequest, error) {
type PRMap map[string][]PullRequest
var prlisttmpl = template.Must(template.New("prlist").Parse(`{{range $k, $v := .}}
{{$k}}:
{{$v}}
{{end}}`))
func (p PRMap) String() string {
var buf bytes.Buffer
err := prlisttmpl.Execute(&buf, p)
if err != nil {
return "" // Return empty string on error
}
return buf.String()
}
func GetPRs(org, username string, from string, to string) (PRMap, error) {
req, err := http.NewRequest(
http.MethodGet,
fmt.Sprintf(
@ -81,7 +98,7 @@ func GetPRs(org, username string, from string, to string) (map[string][]PullRequ
return nil, fmt.Errorf("error decoding response: %w", err)
}
allthings := map[string][]PullRequest{}
allthings := PRMap{}
for _, pr := range r.Items {
reponameparts := strings.Split(pr.RepositoryUrl, "/")