mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Rough JIRA implementation. Currently gets all issues assigned to user
This commit is contained in:
parent
8d131907a2
commit
dd170c0ab3
@ -10,31 +10,51 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Fetch() string {
|
type SearchResult struct {
|
||||||
resp, err := jiraRequest("/rest/api/2/project/CORE")
|
StartAt int `json:"startAt"`
|
||||||
if err != nil {
|
MaxResults int `json:"maxResults"`
|
||||||
return err.Error()
|
Total int `json:"total"`
|
||||||
|
Issues []Issue `json:"issues"`
|
||||||
}
|
}
|
||||||
|
|
||||||
project := &JiraProject{}
|
type Issue struct {
|
||||||
parseJson(project, resp.Body)
|
Expand string `json:"expand"`
|
||||||
//fmt.Printf("%#v\n", project)
|
ID string `json:"id"`
|
||||||
|
Self string `json:"self"`
|
||||||
|
Key string `json:"key"`
|
||||||
|
|
||||||
return ""
|
IssueFields *IssueFields `json:"fields"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func IssuesFor(username string) ([]JiraIssue, error) {
|
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)
|
url := fmt.Sprintf("/rest/api/2/search?jql=assignee=%s", username)
|
||||||
|
|
||||||
resp, err := jiraRequest(url)
|
resp, err := jiraRequest(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return &SearchResult{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
issues := []JiraIssue{}
|
searchResult := &SearchResult{}
|
||||||
parseJson(issues, resp.Body)
|
parseJson(searchResult, resp.Body)
|
||||||
|
|
||||||
return issues, nil
|
return searchResult, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
140
jira/structs.go
140
jira/structs.go
@ -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
|
|
||||||
}
|
|
@ -33,19 +33,27 @@ func (widget *Widget) Refresh() {
|
|||||||
return
|
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.RefreshedAt = time.Now()
|
||||||
|
|
||||||
widget.View.Clear()
|
widget.View.Clear()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
widget.View.SetWrap(true)
|
widget.View.SetWrap(true)
|
||||||
|
widget.View.SetTitle(fmt.Sprintf(" %s ", widget.Name))
|
||||||
fmt.Fprintf(widget.View, "%v", err)
|
fmt.Fprintf(widget.View, "%v", err)
|
||||||
} else {
|
} else {
|
||||||
widget.View.SetWrap(false)
|
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
|
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
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user