This commit is contained in:
Olivier Tremblay 2025-10-28 12:28:04 -04:00
parent c215536745
commit ef6e0c97d2
3 changed files with 57 additions and 18 deletions

View file

@ -15,11 +15,19 @@ func main() {
ghusername := os.Args[2] ghusername := os.Args[2]
start := os.Args[3] start := os.Args[3]
end := os.Args[4] end := os.Args[4]
DoPrs(proj, ghusername, start, end) employeename := os.Args[5]
DoJira(start, end) prs := DoPrs(proj, ghusername, start, end)
issues := DoJira(start, end)
summ, err := SummarizeData(employeename, prs, issues)
if err != nil {
fmt.Println(fmt.Errorf("error getting PRs: %w", err))
os.Exit(1)
}
fmt.Println(summ)
} }
func DoPrs(proj, ghusername, start, end string) { func DoPrs(proj, ghusername, start, end string) map[string][]contributions.PullRequest {
prs, err := contributions.GetPRs(proj, ghusername, start, end) prs, err := contributions.GetPRs(proj, ghusername, start, end)
if err != nil { if err != nil {
@ -38,11 +46,12 @@ func DoPrs(proj, ghusername, start, end string) {
fmt.Println(fmt.Errorf("error writing out PRs: %w", err)) fmt.Println(fmt.Errorf("error writing out PRs: %w", err))
os.Exit(1) os.Exit(1)
} }
return prs
} }
func DoJira(start, end string) { func DoJira(start, end string) []issues.Issue {
host := os.Getenv("JIRA_HOST") host := os.Getenv("JIRA_HOST")
user := os.Getenv("JIRA_TARGET_USER") user := os.Getenv("JIRA_TARGET_USER")
prs, err := issues.GetIssues(host, user, start, end) issues, err := issues.GetIssues(host, user, start, end)
if err != nil { if err != nil {
fmt.Println(fmt.Errorf("error getting PRs: %w", err)) fmt.Println(fmt.Errorf("error getting PRs: %w", err))
os.Exit(1) os.Exit(1)
@ -52,11 +61,13 @@ func DoJira(start, end string) {
if err != nil { if err != nil {
fmt.Println(fmt.Errorf("error creating PR file: %w", err)) fmt.Println(fmt.Errorf("error creating PR file: %w", err))
os.Exit(1) os.Exit(1)
} }
enc := json.NewEncoder(ghf) enc := json.NewEncoder(ghf)
err = enc.Encode(prs) err = enc.Encode(issues)
if err != nil { if err != nil {
fmt.Println(fmt.Errorf("error writing out PRs: %w", err)) fmt.Println(fmt.Errorf("error writing out PRs: %w", err))
os.Exit(1) os.Exit(1)
} }
return issues
} }

View file

@ -7,13 +7,20 @@ import (
"io" "io"
"net/http" "net/http"
"os" "os"
"strings"
"o5r.ca/autocrossbow/contributions"
"o5r.ca/autocrossbow/issues"
) )
const defaultPrompt = `I will provide you, for a given period, with an employee name and a list of Pull Request titles and summaries split by repository, and a list of Jira Issues an employee has worked on. I may also provide, optionally, the employee's self-assessment. If I do, integrate that.
I'd like you to summarize the employee's accomplishments for the quarter
I'd like the summary for the accomplishments to be in prose form, in a few paragraphs separated based on areas of work. Keep answers to 500 words for the summary.`
// SummarizeData takes GitHub PRs and Jira issues data and sends it to an OpenAI-compatible endpoint for summarization. // SummarizeData takes GitHub PRs and Jira issues data and sends it to an OpenAI-compatible endpoint for summarization.
func SummarizeData(prs map[string][]PullRequest, issues []Issue) (string, error) { func SummarizeData(employeename string, prs map[string][]contributions.PullRequest, issues []issues.Issue) (string, error) {
// Build a prompt string // Build a prompt string
prompt := "Summarize the following GitHub PRs and Jira issues:\n\n" prompt := defaultPrompt + fmt.Sprintf("\n\nHere's the PRs and Tickets for the employee %s:\n\n", employeename)
for repo, prList := range prs { for repo, prList := range prs {
prompt += fmt.Sprintf("Repository: %s\n", repo) prompt += fmt.Sprintf("Repository: %s\n", repo)
for _, pr := range prList { for _, pr := range prList {
@ -21,23 +28,39 @@ func SummarizeData(prs map[string][]PullRequest, issues []Issue) (string, error)
prompt += fmt.Sprintf(" Body: %s\n", pr.Body) prompt += fmt.Sprintf(" Body: %s\n", pr.Body)
} }
} }
prompt += fmt.Sprintf("Issues:")
for _, issue := range issues { for _, issue := range issues {
prompt += fmt.Sprintf("\nJira Issue: %s\n", issue.Key)
prompt += fmt.Sprintf("Summary: %s\n", issue.Summary) prompt += fmt.Sprintf("Summary: %s\n", issue.Summary)
prompt += fmt.Sprintf("Description: %s\n", issue.Description) prompt += fmt.Sprintf("Description: %s\n", issue.Description)
prompt += fmt.Sprintf("--------")
} }
// Get OpenAI endpoint and token from environment variables // Get OpenAI endpoint and token from environment variables
openaiEndpoint := os.Getenv("OPENAI_ENDPOINT") openaiEndpoint := os.Getenv("OPENAI_ENDPOINT")
openaiToken := os.Getenv("OPENAI_TOKEN") openaiToken := os.Getenv("OPENAI_TOKEN")
openaiModel := os.Getenv("OPENAI_MODEL")
if openaiEndpoint == "" || openaiToken == "" { if openaiEndpoint == "" || openaiToken == "" {
return "", fmt.Errorf("OPENAI_ENDPOINT and OPENAI_TOKEN must be set in environment variables") return "", fmt.Errorf("OPENAI_ENDPOINT and OPENAI_TOKEN must be set in environment variables")
} }
// Create a JSON payload for the OpenAI API // Create a JSON payload for the OpenAI API
payload := map[string]string{"prompt": prompt} payload := struct {
Model string `json:"model"`
Messages []struct {
Role string `json:"role"`
Content string `json:"content"`
} `json:"messages"`
}{
Model: openaiModel,
Messages: []struct {
Role string `json:"role"`
Content string `json:"content"`
}{{Role: "system", Content: prompt}},
}
jsonPayload, err := json.Marshal(payload) jsonPayload, err := json.Marshal(payload)
fmt.Println(string(jsonPayload))
if err != nil { if err != nil {
return "", err return "", err
} }
@ -62,5 +85,7 @@ func SummarizeData(prs map[string][]PullRequest, issues []Issue) (string, error)
return "", err return "", err
} }
//parts := strings.Split(body, "think")
return string(body), nil return string(body), nil
} }

View file

@ -39,14 +39,16 @@ type RespIssue struct {
} }
func GetIssues(instance, user, from, to string) ([]Issue, error) { func GetIssues(instance, user, from, to string) ([]Issue, error) {
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("https://%s/rest/api/2/search", instance), nil) req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("https://%s/rest/api/3/search/jql", instance), nil)
if err != nil { if err != nil {
return nil, fmt.Errorf("error building jira search request: %w", err) return nil, fmt.Errorf("error building jira search request: %w", err)
} }
q := req.URL.Query() q := req.URL.Query()
q.Add("jql", fmt.Sprintf("assignee was '%s' and resolved >= %s and resolved <= %s", user, from, to)) q.Add("jql", fmt.Sprintf("assignee was '%s' and resolved >= %s and resolved <= %s", user, from, to))
q.Add("fields", "*all")
req.URL.RawQuery = q.Encode() req.URL.RawQuery = q.Encode()
req.SetBasicAuth(os.Getenv("JIRA_USER"), os.Getenv("JIRA_TOKEN")) req.SetBasicAuth(os.Getenv("JIRA_USER"), os.Getenv("JIRA_TOKEN"))
req.Header.Add("Accept", "application/json")
resp, err := jcl.Do(req) resp, err := jcl.Do(req)
if err != nil { if err != nil {
return nil, fmt.Errorf("error executing jira search request: %w", err) return nil, fmt.Errorf("error executing jira search request: %w", err)
@ -66,17 +68,18 @@ func GetIssues(instance, user, from, to string) ([]Issue, error) {
for _, i := range jsr.Issues { for _, i := range jsr.Issues {
iss := Issue{} iss := Issue{}
if s, ok := i.Fields["summary"]; ok { if s, ok := i.Fields["summary"]; ok {
fmt.Println(s)
iss.Summary, _ = s.(string) iss.Summary, _ = s.(string)
} }
if d, ok := i.Fields["description"]; ok { if d, ok := i.Fields["description"]; ok {
fmt.Println(d)
iss.Description, _ = d.(string) iss.Description, _ = d.(string)
} }
if comms, ok := i.Fields["comment"].(map[string]any); ok { if comms, ok := i.Fields["comment"].([]map[string]any); ok && len(comms) > 0 {
if c := comms["comments"].([]map[string]any); len(c) > 0 { iss.Comments = make([]Comment, 0, len(comms))
iss.Comments = make([]Comment, 0, len(c)) for _, c2 := range comms {
for _, c2 := range c { iss.Comments = append(iss.Comments, Comment{Author{DisplayName: c2["displayName"].(string), EmailAddress: c2["emailAddress"].(string)}, c2["body"].(string)})
iss.Comments = append(iss.Comments, Comment{Author{DisplayName: c2["displayName"].(string), EmailAddress: c2["emailAddress"].(string)}, c2["body"].(string)})
}
} }
} }
out = append(out, iss) out = append(out, iss)