diff --git a/jira/client.go b/jira/client.go index 3bd5859b..b8b5665b 100644 --- a/jira/client.go +++ b/jira/client.go @@ -10,31 +10,51 @@ import ( "os" ) -func Fetch() string { - resp, err := jiraRequest("/rest/api/2/project/CORE") - if err != nil { - return err.Error() - } - - project := &JiraProject{} - parseJson(project, resp.Body) - //fmt.Printf("%#v\n", project) - - return "" +type SearchResult struct { + StartAt int `json:"startAt"` + MaxResults int `json:"maxResults"` + Total int `json:"total"` + Issues []Issue `json:"issues"` } -func IssuesFor(username string) ([]JiraIssue, error) { +type Issue struct { + Expand string `json:"expand"` + ID string `json:"id"` + Self string `json:"self"` + Key string `json:"key"` + + IssueFields *IssueFields `json:"fields"` +} + +type IssueFields struct { + Summary string `json:"summary"` + + IssueType *IssueType `json:"issuetype"` +} + +type IssueType struct { + Self string `json:"self"` + ID string `json:"id"` + Description string `json:"description"` + IconURL string `json:"iconUrl"` + Name string `json:"name"` + Subtask bool `json:"subtask"` +} + +/* -------------------- -------------------- */ + +func IssuesFor(username string) (*SearchResult, error) { url := fmt.Sprintf("/rest/api/2/search?jql=assignee=%s", username) resp, err := jiraRequest(url) if err != nil { - return nil, err + return &SearchResult{}, err } - issues := []JiraIssue{} - parseJson(issues, resp.Body) + searchResult := &SearchResult{} + parseJson(searchResult, resp.Body) - return issues, nil + return searchResult, nil } /* -------------------- Unexported Functions -------------------- */ diff --git a/jira/structs.go b/jira/structs.go deleted file mode 100644 index 8f3b6bd2..00000000 --- a/jira/structs.go +++ /dev/null @@ -1,140 +0,0 @@ -package jira - -import () - -type JiraIssue struct { - Fields JiraIssueFields - Id string - Key string - Self string -} - -type JiraIssueFields struct { - Comment JiraIssueComment - Description string - Project JiraIssueProject - SubTasks []JiraIssueSubTask - TimeTracking JiraIssueTimetracking - Updated string - Watcher JiraIssueWatcher -} - -type JiraIssueWatcher struct { - IsWatching bool - Self string - WatchCount int - Watchers []JiraAttribute -} - -type JiraIssueSubTask struct { - Id string - Type struct { - Id string - Name string - Inward string - Outward string - } - OutwardIssue struct { - Id string - Key string - Self string - Fields struct { - Status struct { - IconUrl string - Name string - } - } - } -} - -type JiraIssueProject struct { - Id string - Key string - Name string - ProjectCategory JiraAttribute - Self string - Simplified bool -} - -type JiraIssueComment struct { - Author JiraAttribute - Body string - Created string - Id string - Self string - UpdateAuthor JiraAttribute - Updated string - Visibility struct { - Type string - Value string - } -} - -type JiraAttribute struct { - Active bool - DisplayName string - Name string - Self string -} - -type JiraIssueTimetracking struct { - OriginalEstimate string - OriginalEstimateSeconds int - RemainingEstimate string - RemainingEstimateSeconds int - TimeSpent string - TimeSpentSeconds int -} - -type JiraProject struct { - AssigneeType string - Components []JiraProjectComponent - Email string - IssueTypes []JiraProjectIssueType - Lead JiraProjectMember - Name string - ProjectCategory JiraProjectCategory - Simplified bool - Url string - - JiraAttribute -} - -type JiraProjectCategory struct { - Description string - Id string - Name string - Self string -} - -type JiraProjectComponent struct { - Assignee JiraProjectMember - AssigneeType string - IsAssigneeTypeValid bool - Lead JiraProjectMember - Project string - ProjectId int - RealAssigne JiraProjectMember - RealAssigneeType string - - JiraAttribute -} - -type JiraProjectIssueType struct { - AvatarId int - Description string - IconUrl string - Id string - Name string - Self string - SubTask bool -} - -type JiraProjectMember struct { - AccountId string - Active bool - DisplayName string - Key string - Name string - Self string -} diff --git a/jira/widget.go b/jira/widget.go index 5d1b97c7..ee12e510 100644 --- a/jira/widget.go +++ b/jira/widget.go @@ -33,19 +33,27 @@ func (widget *Widget) Refresh() { return } - issues, err := IssuesFor(Config.UString("wtf.mods.jira.username")) + searchResult, err := IssuesFor(Config.UString("wtf.mods.jira.username")) - widget.View.SetTitle(fmt.Sprintf(" %s ", widget.Name)) widget.RefreshedAt = time.Now() widget.View.Clear() if err != nil { widget.View.SetWrap(true) + widget.View.SetTitle(fmt.Sprintf(" %s ", widget.Name)) fmt.Fprintf(widget.View, "%v", err) } else { widget.View.SetWrap(false) - fmt.Fprintf(widget.View, "%v", issues) + widget.View.SetTitle( + fmt.Sprintf( + " %s: [green]%s[white] (%d)", + widget.Name, + Config.UString("wtf.mods.jira.project"), + len(searchResult.Issues), + ), + ) + fmt.Fprintf(widget.View, "%s", widget.contentFrom(searchResult)) } } @@ -61,3 +69,36 @@ func (widget *Widget) addView() { widget.View = view } + +func (widget *Widget) contentFrom(searchResult *SearchResult) string { + str := " [red]Assigned Issues[white]\n" + + for _, issue := range searchResult.Issues { + str = str + fmt.Sprintf( + " [%s]%-6s[white] [green]%-10s[white] %s\n", + widget.issueTypeColor(&issue), + issue.IssueFields.IssueType.Name, + issue.Key, + issue.IssueFields.Summary, + ) + } + + return str +} + +func (widget *Widget) issueTypeColor(issue *Issue) string { + var color string + + switch issue.IssueFields.IssueType.Name { + case "Bug": + color = "red" + case "Story": + color = "blue" + case "Task": + color = "orange" + default: + color = "white" + } + + return color +}