Skip to content

Commit

Permalink
Add README to Jira API version
Browse files Browse the repository at this point in the history
  • Loading branch information
berlam committed Oct 4, 2019
1 parent afef57f commit ffe64fe
Show file tree
Hide file tree
Showing 11 changed files with 372 additions and 419 deletions.
34 changes: 31 additions & 3 deletions pkg/jira/jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@ func getApiVersion(client *http.Client, server *url.URL, userinfo *url.Userinfo)
}
// There are "Cloud" and "Server" deployment types.
if strings.ToLower(result.DeploymentType) == "cloud" {
path, _ := server.Parse(v3.BasePath)
return &v3.Api{
Client: client,
Server: server,
Server: path,
Userinfo: userinfo,
}, nil
}
path, _ := server.Parse(v2.BasePath)
return &v2.Api{
Client: client,
Server: server,
Server: path,
Userinfo: userinfo,
}, nil
}
Expand Down Expand Up @@ -121,7 +123,7 @@ func GetBulkTimesheet(client *http.Client, server *url.URL, userinfo *url.Userin
}

if users != nil && len(users) > 0 {
accounts, err := api.Accounts(projects, users)
accounts, err := accounts(api, projects, users)
if err != nil {
log.Println("Could not get user.", err)
return pkg.Timesheet{}
Expand Down Expand Up @@ -170,6 +172,32 @@ func GetBulkTimesheet(client *http.Client, server *url.URL, userinfo *url.Userin
return timesheet
}

func accounts(api model.Api, projects []pkg.Project, users []pkg.User) (map[pkg.User]model.Account, error) {
result := make(map[pkg.User]model.Account, len(users))
c := make(chan error)
var wg sync.WaitGroup
wg.Add(len(users))
for _, user := range users {
go func(user pkg.User) {
defer wg.Done()
account, err := api.User(user, projects)
if err != nil {
c <- err
return
}
result[user] = account
}(user)
}
go func() {
defer close(c)
wg.Wait()
}()
for err := range c {
return nil, err
}
return result, nil
}

type serverInfo struct {
VersionNumbers []int `json:"versionNumbers"`
DeploymentType string `json:"deploymentType"`
Expand Down
5 changes: 0 additions & 5 deletions pkg/jira/model/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type IssueKey string

type Api interface {
ProjectAccessor
AccountAccessor
UserAccessor
IssueAccessor
WorklogAccessor
Expand All @@ -25,10 +24,6 @@ type ProjectAccessor interface {
Projects(startAt int) ([]pkg.Project, error)
}

type AccountAccessor interface {
Accounts(projects []pkg.Project, users []pkg.User) (map[pkg.User]Account, error)
}

type UserAccessor interface {
User(user pkg.User, projects []pkg.Project) (Account, error)
}
Expand Down
8 changes: 0 additions & 8 deletions pkg/jira/test-fixtures/v2_post_worklog_list_request_test.json

This file was deleted.

26 changes: 0 additions & 26 deletions pkg/jira/test-fixtures/v2_post_worklog_list_response_test.json

This file was deleted.

26 changes: 0 additions & 26 deletions pkg/jira/test-fixtures/v2_search_request.schema.json

This file was deleted.

4 changes: 4 additions & 0 deletions pkg/jira/v2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
https://docs.atlassian.com/software/jira/docs/api/REST/7.12.0/#api/2/user-findBulkAssignableUsers
https://docs.atlassian.com/software/jira/docs/api/REST/7.12.0/#api/2/project-getAllProjects
https://docs.atlassian.com/software/jira/docs/api/REST/7.12.0/#api/2/search-searchUsingSearchRequest
https://docs.atlassian.com/software/jira/docs/api/REST/7.12.0/#api/2/issue-getWorklog
Loading

0 comments on commit ffe64fe

Please sign in to comment.