mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WIP
This commit is contained in:
committed by
Chris Cummer
parent
0472e8edec
commit
8d131907a2
79
jira/client.go
Normal file
79
jira/client.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package jira
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"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 ""
|
||||
}
|
||||
|
||||
func IssuesFor(username string) ([]JiraIssue, error) {
|
||||
url := fmt.Sprintf("/rest/api/2/search?jql=assignee=%s", username)
|
||||
|
||||
resp, err := jiraRequest(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
issues := []JiraIssue{}
|
||||
parseJson(issues, resp.Body)
|
||||
|
||||
return issues, nil
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
func jiraRequest(path string) (*http.Response, error) {
|
||||
url := fmt.Sprintf("%s%s", Config.UString("wtf.mods.jira.domain"), path)
|
||||
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.SetBasicAuth(Config.UString("wtf.mods.jira.email"), os.Getenv("WTF_JIRA_API_KEY"))
|
||||
|
||||
httpClient := &http.Client{}
|
||||
resp, err := httpClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.StatusCode < 200 || resp.StatusCode > 299 {
|
||||
return nil, fmt.Errorf(resp.Status)
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func parseJson(obj interface{}, text io.Reader) {
|
||||
jsonStream, err := ioutil.ReadAll(text)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
decoder := json.NewDecoder(bytes.NewReader(jsonStream))
|
||||
|
||||
for {
|
||||
if err := decoder.Decode(obj); err == io.EOF {
|
||||
break
|
||||
} else if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
140
jira/structs.go
Normal file
140
jira/structs.go
Normal file
@@ -0,0 +1,140 @@
|
||||
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,11 +33,20 @@ func (widget *Widget) Refresh() {
|
||||
return
|
||||
}
|
||||
|
||||
issues, err := IssuesFor(Config.UString("wtf.mods.jira.username"))
|
||||
|
||||
widget.View.SetTitle(fmt.Sprintf(" %s ", widget.Name))
|
||||
widget.RefreshedAt = time.Now()
|
||||
|
||||
widget.View.Clear()
|
||||
fmt.Fprintf(widget.View, "%s", "jira")
|
||||
|
||||
if err != nil {
|
||||
widget.View.SetWrap(true)
|
||||
fmt.Fprintf(widget.View, "%v", err)
|
||||
} else {
|
||||
widget.View.SetWrap(false)
|
||||
fmt.Fprintf(widget.View, "%v", issues)
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
Reference in New Issue
Block a user