Skip to content

Commit

Permalink
bubble powered gojiraaaaa
Browse files Browse the repository at this point in the history
  • Loading branch information
jzyinq committed Mar 29, 2024
1 parent aeaab3d commit 7af582d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 33 deletions.
2 changes: 1 addition & 1 deletion gojira/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
40 changes: 9 additions & 31 deletions gojira/jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"github.com/sirupsen/logrus"
"strings"
"time"
)
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion gojira/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := ""
Expand Down

0 comments on commit 7af582d

Please sign in to comment.