feat: extract PR rendering to String() method using text/template

Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) <aider@aider.chat>
This commit is contained in:
Olivier Tremblay 2025-11-25 12:46:54 -05:00
parent 9a71cf44bc
commit d3386d4a58
2 changed files with 17 additions and 2 deletions

View file

@ -165,8 +165,7 @@ func buildPrompt(employeename string, prs map[string][]contributions.PullRequest
for repo, prList := range prs { for repo, prList := range prs {
fullPrompt += fmt.Sprintf("Repository: %s\n", repo) fullPrompt += fmt.Sprintf("Repository: %s\n", repo)
for _, pr := range prList { for _, pr := range prList {
fullPrompt += fmt.Sprintf("- Title: %s\n", pr.Title) fullPrompt += pr.String()
fullPrompt += fmt.Sprintf(" Body: %s\n", pr.Body)
} }
} }
fullPrompt += "Issues:\n" fullPrompt += "Issues:\n"

View file

@ -8,6 +8,7 @@ import (
"net/http" "net/http"
"os" "os"
"strings" "strings"
"text/template"
) )
var ghc = http.Client{} var ghc = http.Client{}
@ -32,6 +33,21 @@ type PullRequest struct {
URL string 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}}
Body: {{.Body}}
`))
var buf bytes.Buffer
err := tmpl.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) { func GetPRs(org, username string, from string, to string) (map[string][]PullRequest, error) {
req, err := http.NewRequest( req, err := http.NewRequest(
http.MethodGet, http.MethodGet,