Skip to content

Commit

Permalink
Add Jira API v2 stub
Browse files Browse the repository at this point in the history
  • Loading branch information
berlam committed Oct 4, 2019
1 parent 1efcd60 commit b262ebe
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 83 deletions.
55 changes: 37 additions & 18 deletions pkg/jira/jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ import (
)

const (
headerAccountId = "X-AACCOUNTID"
jiraServerInfo = "/rest/api/latest/serverInfo"
jiraSearchProjectUrl = "/rest/api/3/project/search?startAt=%s"
jiraSearchUserUrl = "/rest/api/3/user/assignable/multiProjectSearch?projectKeys=%s&query=%s&maxResults=2"
jiraSearchIssueUrl = "/rest/api/3/search"
jiraWorklogUrl = "/rest/api/3/issue/%s/worklog?startAt=%s"
headerAccountId = "X-AACCOUNTID"
jiraServerInfo = "/rest/api/latest/serverInfo"
)

func getApiVersion(client *http.Client, server *url.URL, userinfo *url.Userinfo) (Api, error) {
Expand All @@ -29,7 +25,12 @@ func getApiVersion(client *http.Client, server *url.URL, userinfo *url.Userinfo)
if err != nil {
return nil, err
}
defer response.Body.Close()
defer func() {
err := response.Body.Close()
if err != nil {
log.Println("Response could not be closed.", err)
}
}()

data, err := ioutil.ReadAll(response.Body)
if err != nil {
Expand All @@ -52,7 +53,7 @@ func getApiVersion(client *http.Client, server *url.URL, userinfo *url.Userinfo)
userinfo: userinfo,
}, nil
}
return nil, nil
return &v2{}, nil
}

func GetTimesheet(client *http.Client, server *url.URL, userinfo *url.Userinfo, year int, month time.Month, projects []pkg.Project) pkg.Timesheet {
Expand All @@ -75,14 +76,14 @@ func GetTimesheet(client *http.Client, server *url.URL, userinfo *url.Userinfo,
var wg sync.WaitGroup
wg.Add(len(issues))
for _, item := range issues {
go func(item issue) {
go func(item Issue) {
defer wg.Done()
items, err := api.worklog(item.Key, 0)
items, err := api.worklog(item.key(), 0)
if err != nil {
log.Println("Could not get effort for "+item.Key, err)
log.Println("Could not get effort for "+item.key(), err)
return
}
c <- item.getWorklog(items, fromDate, toDate)[accountId]
c <- item.worklog(items, fromDate, toDate)[accountId]
}(item)
}
go func() {
Expand Down Expand Up @@ -139,14 +140,14 @@ func GetBulkTimesheet(client *http.Client, server *url.URL, userinfo *url.Userin
var wg sync.WaitGroup
wg.Add(len(issues))
for _, item := range issues {
go func(item issue) {
go func(item Issue) {
defer wg.Done()
items, err := api.worklog(item.Key, 0)
items, err := api.worklog(item.key(), 0)
if err != nil {
log.Println("Could not get effort for "+item.Key, err)
log.Println("Could not get effort for "+item.key(), err)
return
}
worklog := item.getWorklog(items, fromDate, toDate)
worklog := item.worklog(items, fromDate, toDate)
for _, user := range users {
c <- worklog[Account(user)]
}
Expand Down Expand Up @@ -205,9 +206,27 @@ type UserAccessor interface {
}

type IssueAccessor interface {
issues(jql jql, startAt int) (Account, []issue, error)
issues(jql jql, startAt int) (Account, []Issue, error)
}

type WorklogAccessor interface {
worklog(key IssueKey, startAt int) (worklogItems, error)
worklog(key IssueKey, startAt int) ([]Worklog, error)
}

type Issue interface {
key() IssueKey
worklog(worklog []Worklog, fromDate, toDate time.Time) map[Account]pkg.Timesheet
}

type Worklog interface {
isBetween(fromDate, toDate time.Time) bool
author() Author
date() time.Time
comment() pkg.Description
duration() time.Duration
}

type Author interface {
id() Account
name() string
}
22 changes: 22 additions & 0 deletions pkg/jira/jira_v2.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
package jira

import "eager/pkg"

type v2 struct {
}

func (v2) projects(startAt int) ([]pkg.Project, error) {
panic("implement me")
}

func (v2) accounts(projects []pkg.Project, users []pkg.User) (map[pkg.User]Account, error) {
panic("implement me")
}

func (v2) user(user pkg.User, projects []pkg.Project) (Account, error) {
panic("implement me")
}

func (v2) issues(jql jql, startAt int) (Account, []Issue, error) {
panic("implement me")
}

func (v2) worklog(key IssueKey, startAt int) ([]Worklog, error) {
panic("implement me")
}
Loading

0 comments on commit b262ebe

Please sign in to comment.