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>
This commit is contained in:
parent
3f922ddb35
commit
6b54a09a78
1 changed files with 47 additions and 2 deletions
|
|
@ -38,13 +38,55 @@ type RespIssue struct {
|
|||
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(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", user, from, to))
|
||||
q.Add("jql", fmt.Sprintf("assignee was %s and resolved >= %s and resolved <= %s", accountID, from, to))
|
||||
q.Add("fields", "*all")
|
||||
req.URL.RawQuery = q.Encode()
|
||||
req.SetBasicAuth(user, os.Getenv("JIRA_TOKEN"))
|
||||
|
|
@ -61,7 +103,10 @@ func GetIssues(instance, user, from, to string) ([]Issue, error) {
|
|||
|
||||
dec := json.NewDecoder(resp.Body)
|
||||
var jsr *JiraSearchResp
|
||||
dec.Decode(&jsr)
|
||||
err = dec.Decode(&jsr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error decoding jira search response: %w", err)
|
||||
}
|
||||
|
||||
out := []Issue{}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue