initial commit
This commit is contained in:
commit
c215536745
5 changed files with 298 additions and 0 deletions
62
cmd/acb/main.go
Normal file
62
cmd/acb/main.go
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"o5r.ca/autocrossbow/contributions"
|
||||
"o5r.ca/autocrossbow/issues"
|
||||
)
|
||||
|
||||
func main() {
|
||||
proj := os.Args[1]
|
||||
ghusername := os.Args[2]
|
||||
start := os.Args[3]
|
||||
end := os.Args[4]
|
||||
DoPrs(proj, ghusername, start, end)
|
||||
DoJira(start, end)
|
||||
}
|
||||
|
||||
func DoPrs(proj, ghusername, start, end string) {
|
||||
|
||||
prs, err := contributions.GetPRs(proj, ghusername, start, end)
|
||||
if err != nil {
|
||||
fmt.Println(fmt.Errorf("error getting PRs: %w", err))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
ghf, err := os.Create(fmt.Sprintf("gh-%s-%s-%s-%s-%d.json", proj, ghusername, start, end, time.Now().Unix()))
|
||||
if err != nil {
|
||||
fmt.Println(fmt.Errorf("error creating PR file: %w", err))
|
||||
os.Exit(1)
|
||||
}
|
||||
enc := json.NewEncoder(ghf)
|
||||
err = enc.Encode(prs)
|
||||
if err != nil {
|
||||
fmt.Println(fmt.Errorf("error writing out PRs: %w", err))
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
func DoJira(start, end string) {
|
||||
host := os.Getenv("JIRA_HOST")
|
||||
user := os.Getenv("JIRA_TARGET_USER")
|
||||
prs, err := issues.GetIssues(host, user, start, end)
|
||||
if err != nil {
|
||||
fmt.Println(fmt.Errorf("error getting PRs: %w", err))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
ghf, err := os.Create(fmt.Sprintf("jira-%s-%s-%s-%s-%d.json", host, user, start, end, time.Now().Unix()))
|
||||
if err != nil {
|
||||
fmt.Println(fmt.Errorf("error creating PR file: %w", err))
|
||||
os.Exit(1)
|
||||
}
|
||||
enc := json.NewEncoder(ghf)
|
||||
err = enc.Encode(prs)
|
||||
if err != nil {
|
||||
fmt.Println(fmt.Errorf("error writing out PRs: %w", err))
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
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