initial commit
yessss feat: add Vikunja issues provider and integrate tasks retrieval Co-authored-by: aider (openai/qwen2.5-coder:32b-instruct-q4_0) <aider@aider.chat> feat: add Vikunja handler to main file Co-authored-by: aider (openai/qwen2.5-coder:32b-instruct-q4_0) <aider@aider.chat> refactor: Move Jira user from positional arg to flag parameter Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) <aider@aider.chat> fix: replace manual argument parsing with Go flags package Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) <aider@aider.chat> feat: replace positional arguments with flags in main function Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) <aider@aider.chat> fix: enforce mandatory start/end dates and at least one identifier flag Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) <aider@aider.chat> fix: only call relevant tools based on flag presence Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) <aider@aider.chat> feat: add vikunja task support to summarize function feat: add flag to pass custom prompt with default prompt as fallback Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) <aider@aider.chat> Minor fix fix: comment out vikunja tasks integration for now fix: check for OpenAI environment variables before calling Summarize Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) <aider@aider.chat> feat: add timestamped prompt file generation for summarization refactor: remove duplicate os.Getenv calls for OpenAI env vars in SummarizeData Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) <aider@aider.chat> refactor: pass OpenAI env vars from main to SummarizeData instead of calling os.Getenv inside the function Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) <aider@aider.chat> feat: add file prompt support with fallback to literal prompt string Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) <aider@aider.chat> fix: remove single quotes around JIRA user assignee and add debug printing feat: implement accountID lookup for Jira user search in GetIssues function Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) <aider@aider.chat> fix: remove debug print statement in Jira user search function fix: Replace user parameter with JIRA_USER environment variable in SetBasicAuth calls Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) <aider@aider.chat> fix: add missing os import in summarize.go refactor: split SummarizeData into buildPrompt and callSummarizationEndpoint functions Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) <aider@aider.chat> fix: always call SummarizeData to ensure prompt file is created for debugging, but only call OpenAI endpoint if env vars are set Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) <aider@aider.chat> refactor: extract callSummarizationEndpoint into Summarizer interface for multiple implementations Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) <aider@aider.chat> refactor: move OpenAI variable checks into OpenAISummarizer's Summarize method and always call the summarizer's method Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) <aider@aider.chat> feat: implement Ollama Summarizer using official SDK as per article example Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) <aider@aider.chat> refactor: simplify OpenAI and Ollama summarizer implementations refactor: simplify Summarizer interface by moving endpoint, token, and model to struct properties Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) <aider@aider.chat> feat: add Ollama summarizer support to main command fix: remove extraneous parameters from SummarizeData call and use properly initialized OllamaSummarizer Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) <aider@aider.chat> feat: add AnthropicSummarizer implementation using anthropic-sdk-go package Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) <aider@aider.chat> fix: change summarizer call condition to check if summarizer is nil instead of environment variables Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) <aider@aider.chat> fix: correct client reference and update Anthropic summarizer implementation 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> Some cleanup
This commit is contained in:
commit
a2c8207998
9 changed files with 726 additions and 0 deletions
152
issues/jira.go
Normal file
152
issues/jira.go
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
package issues
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/eliziario/jira-lib/pkg/adf"
|
||||
)
|
||||
|
||||
var jcl = http.Client{}
|
||||
|
||||
type Issue struct {
|
||||
Summary string
|
||||
Description string
|
||||
Comments []Comment
|
||||
}
|
||||
|
||||
type Comment struct {
|
||||
Author Author
|
||||
Body string
|
||||
}
|
||||
|
||||
type Author struct {
|
||||
DisplayName string
|
||||
EmailAddress string
|
||||
}
|
||||
|
||||
type JiraSearchResp struct {
|
||||
Issues []RespIssue
|
||||
}
|
||||
|
||||
type RespIssue struct {
|
||||
Key string
|
||||
Fields map[string]any
|
||||
}
|
||||
|
||||
type UserSearchResp struct {
|
||||
AccountID string `json:"accountId"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func getUserAccountID(instance, user string) (string, error) {
|
||||
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("https://%s/rest/api/3/user/search?query=%s", instance, user), nil)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error building jira user search request: %w", err)
|
||||
}
|
||||
req.SetBasicAuth(os.Getenv("JIRA_USER"), os.Getenv("JIRA_TOKEN"))
|
||||
req.Header.Add("Accept", "application/json")
|
||||
resp, err := jcl.Do(req)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error executing jira user search request: %w", err)
|
||||
}
|
||||
if resp.StatusCode >= 400 {
|
||||
b := bytes.NewBuffer(nil)
|
||||
io.Copy(b, resp.Body)
|
||||
return "", fmt.Errorf("error talking to jira: %s", b.String())
|
||||
}
|
||||
|
||||
dec := json.NewDecoder(resp.Body)
|
||||
var users []UserSearchResp
|
||||
err = dec.Decode(&users)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error decoding jira user search response: %w", err)
|
||||
}
|
||||
|
||||
if len(users) == 0 {
|
||||
return "", fmt.Errorf("no user found with query %s", user)
|
||||
}
|
||||
|
||||
return users[0].AccountID, nil
|
||||
}
|
||||
|
||||
func GetIssues(instance, user, from, to string) ([]Issue, error) {
|
||||
// First get the user's account ID
|
||||
accountID, err := getUserAccountID(instance, user)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting user account ID: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("https://%s/rest/api/3/search/jql", instance), nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error building jira search request: %w", err)
|
||||
}
|
||||
q := req.URL.Query()
|
||||
q.Add("jql", fmt.Sprintf("assignee was %s and resolved >= %s and resolved <= %s", accountID, from, to))
|
||||
q.Add("fields", "*all")
|
||||
q.Add("expand", "renderedFields")
|
||||
req.URL.RawQuery = q.Encode()
|
||||
req.SetBasicAuth(os.Getenv("JIRA_USER"), os.Getenv("JIRA_TOKEN"))
|
||||
req.Header.Add("Accept", "application/json")
|
||||
resp, err := jcl.Do(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error executing jira search request: %w", err)
|
||||
}
|
||||
if resp.StatusCode >= 400 {
|
||||
b := bytes.NewBuffer(nil)
|
||||
io.Copy(b, resp.Body)
|
||||
return nil, fmt.Errorf("error talking to jira: %s", b.String())
|
||||
}
|
||||
|
||||
dec := json.NewDecoder(resp.Body)
|
||||
var jsr *JiraSearchResp
|
||||
err = dec.Decode(&jsr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error decoding jira search response: %w", err)
|
||||
}
|
||||
|
||||
out := []Issue{}
|
||||
|
||||
for _, i := range jsr.Issues {
|
||||
iss := Issue{}
|
||||
if s, ok := i.Fields["summary"]; ok {
|
||||
iss.Summary, _ = s.(string)
|
||||
}
|
||||
if d, ok := i.Fields["description"]; ok {
|
||||
doc := ifaceToADF(d)
|
||||
iss.Description = adf.NewTranslator(doc, adf.NewMarkdownTranslator()).Translate()
|
||||
}
|
||||
if comms, ok := i.Fields["comment"].([]map[string]any); ok && len(comms) > 0 {
|
||||
iss.Comments = make([]Comment, 0, len(comms))
|
||||
for _, c2 := range comms {
|
||||
iss.Comments = append(iss.Comments, Comment{Author{DisplayName: c2["displayName"].(string), EmailAddress: c2["emailAddress"].(string)}, c2["body"].(string)})
|
||||
|
||||
}
|
||||
}
|
||||
out = append(out, iss)
|
||||
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
func ifaceToADF(v any) *adf.ADF {
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var doc *adf.ADF
|
||||
|
||||
js, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
return nil // ignore invalid data
|
||||
}
|
||||
if err = json.Unmarshal(js, &doc); err != nil {
|
||||
return nil // ignore invalid data
|
||||
}
|
||||
|
||||
return doc
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue