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

@ -39,14 +39,16 @@ type RespIssue struct {
}
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 {
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", user, from, to))
q.Add("fields", "*all")
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)
@ -66,17 +68,18 @@ func GetIssues(instance, user, from, to string) ([]Issue, error) {
for _, i := range jsr.Issues {
iss := Issue{}
if s, ok := i.Fields["summary"]; ok {
fmt.Println(s)
iss.Summary, _ = s.(string)
}
if d, ok := i.Fields["description"]; ok {
fmt.Println(d)
iss.Description, _ = d.(string)
}
if comms, ok := i.Fields["comment"].(map[string]any); ok {
if c := comms["comments"].([]map[string]any); len(c) > 0 {
iss.Comments = make([]Comment, 0, len(c))
for _, c2 := range c {
iss.Comments = append(iss.Comments, Comment{Author{DisplayName: c2["displayName"].(string), EmailAddress: c2["emailAddress"].(string)}, c2["body"].(string)})
}
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)