initial commit
This commit is contained in:
commit
c215536745
5 changed files with 298 additions and 0 deletions
66
cmd/acb/summarize.go
Normal file
66
cmd/acb/summarize.go
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 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) {
|
||||
// Build a prompt string
|
||||
prompt := "Summarize the following GitHub PRs and Jira issues:\n\n"
|
||||
for repo, prList := range prs {
|
||||
prompt += fmt.Sprintf("Repository: %s\n", repo)
|
||||
for _, pr := range prList {
|
||||
prompt += fmt.Sprintf("- Title: %s\n", pr.Title)
|
||||
prompt += fmt.Sprintf(" Body: %s\n", pr.Body)
|
||||
}
|
||||
}
|
||||
for _, issue := range issues {
|
||||
prompt += fmt.Sprintf("\nJira Issue: %s\n", issue.Key)
|
||||
prompt += fmt.Sprintf("Summary: %s\n", issue.Summary)
|
||||
prompt += fmt.Sprintf("Description: %s\n", issue.Description)
|
||||
}
|
||||
|
||||
// Get OpenAI endpoint and token from environment variables
|
||||
openaiEndpoint := os.Getenv("OPENAI_ENDPOINT")
|
||||
openaiToken := os.Getenv("OPENAI_TOKEN")
|
||||
|
||||
if openaiEndpoint == "" || openaiToken == "" {
|
||||
return "", fmt.Errorf("OPENAI_ENDPOINT and OPENAI_TOKEN must be set in environment variables")
|
||||
}
|
||||
|
||||
// Create a JSON payload for the OpenAI API
|
||||
payload := map[string]string{"prompt": prompt}
|
||||
jsonPayload, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Create a POST request to the OpenAI endpoint with JSON body
|
||||
req, err := http.NewRequest("POST", openaiEndpoint, bytes.NewBuffer(jsonPayload))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", openaiToken))
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(body), nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue