diff --git a/gojira/cli.go b/gojira/cli.go index 0579075..b9549d0 100644 --- a/gojira/cli.go +++ b/gojira/cli.go @@ -101,7 +101,7 @@ var IssuesCommand = &cli.Command{ for _, worklog := range app.workLogs.logs { alreadyLoggedIssues = append(alreadyLoggedIssues, worklog.Issue.Key) } - todaysIssues, err := GetIssuesByKeys(alreadyLoggedIssues) + todaysIssues, err := NewJiraClient().GetIssuesByKeys(alreadyLoggedIssues) if err != nil { return } diff --git a/gojira/jira.go b/gojira/jira.go index 6e2f36d..6b4d918 100644 --- a/gojira/jira.go +++ b/gojira/jira.go @@ -5,7 +5,6 @@ import ( "encoding/base64" "encoding/json" "fmt" - "github.com/sirupsen/logrus" "strings" "time" ) @@ -81,12 +80,11 @@ type JiraWorklogUpdate struct { TimeSpentSeconds int `json:"timeSpentSeconds"` } -// FIXME create GetIssuesByJQL instead GetLatestIssues and GetIssuesByKeys -func (jc *JiraClient) GetLatestIssues() (JQLResponse, error) { +func (jc *JiraClient) GetIssuesByJQL(jql string, maxResults int) (JQLResponse, error) { payload := &JQLSearch{ Expand: []string{"names"}, - Jql: "assignee in (currentUser()) ORDER BY updated DESC, created DESC", - MaxResults: 10, + Jql: jql, + MaxResults: maxResults, FieldsByKeys: false, Fields: []string{"summary", "status"}, StartAt: 0, @@ -109,33 +107,13 @@ func (jc *JiraClient) GetLatestIssues() (JQLResponse, error) { return jqlResponse, nil } -func GetIssuesByKeys(issueKeys []string) (JQLResponse, error) { +func (jc *JiraClient) GetLatestIssues() (JQLResponse, error) { + return jc.GetIssuesByJQL("assignee in (currentUser()) ORDER BY updated DESC, created DESC", 10) +} + +func (jc *JiraClient) GetIssuesByKeys(issueKeys []string) (JQLResponse, error) { issueKeysJQL := fmt.Sprintf("key in (%s) ORDER BY updated DESC, created DESC", strings.Join(issueKeys, ",")) - logrus.Info(issueKeysJQL) - payload := &JQLSearch{ - Expand: []string{"names"}, - Jql: issueKeysJQL, - MaxResults: len(issueKeys), - FieldsByKeys: false, - Fields: []string{"summary", "status"}, - StartAt: 0, - } - payloadJson, err := json.Marshal(payload) - if err != nil { - return JQLResponse{}, err - } - requestBody := bytes.NewBuffer(payloadJson) - requestUrl := fmt.Sprintf("%s/rest/api/2/search", Config.JiraUrl) - response, err := SendHttpRequest("POST", requestUrl, requestBody, NewJiraClient().getHttpHeaders(), 200) - if err != nil { - return JQLResponse{}, err - } - var jqlResponse JQLResponse - err = json.Unmarshal(response, &jqlResponse) - if err != nil { - return JQLResponse{}, err - } - return jqlResponse, nil + return jc.GetIssuesByJQL(issueKeysJQL, len(issueKeys)) } func (jc *JiraClient) GetIssue(issueKey string) (Issue, error) { diff --git a/gojira/prompt.go b/gojira/prompt.go index 2255bce..5e358c1 100644 --- a/gojira/prompt.go +++ b/gojira/prompt.go @@ -35,7 +35,12 @@ func SelectActionForm(actions []string) (string, error) { func IssueWorklogForm(issues []Issue) (Issue, string, error) { formOptions := make([]huh.Option[Issue], len(issues)) for i, issue := range issues { - formOptions[i] = huh.NewOption(fmt.Sprintf("%s - %s", issue.Key, issue.Fields.Summary), issue) + timeSpent := "" + worklog := findWorklogByIssueKey(issue.Key) + if worklog != nil { + timeSpent = FormatTimeSpent(worklog.TimeSpentSeconds) + } + formOptions[i] = huh.NewOption(fmt.Sprintf("%-8s %-10s - %s", timeSpent, issue.Key, issue.Fields.Summary), issue) } chosenIssue := Issue{} timeSpent := ""