Commit 08995aee authored by Sander van Harmelen's avatar Sander van Harmelen

Small refactor to make things a bit cleaner (#199)

parent 94597a28
......@@ -160,9 +160,6 @@ type Client struct {
// User agent used when communicating with the GitLab API.
UserAgent string
// timeStats is an internal service used by other services.
timeStats *timeStatsService
// Services used for talking to different parts of the GitLab API.
Branches *BranchesService
BuildVariables *BuildVariablesService
......@@ -231,7 +228,7 @@ func newClient(httpClient *http.Client, tokenType tokenType, token string) *Clie
}
// Create the internal timeStats service.
c.timeStats = &timeStatsService{client: c}
timeStats := &timeStatsService{client: c}
// Create all the public services.
c.Branches = &BranchesService{client: c}
......@@ -240,10 +237,10 @@ func newClient(httpClient *http.Client, tokenType tokenType, token string) *Clie
c.DeployKeys = &DeployKeysService{client: c}
c.Features = &FeaturesService{client: c}
c.Groups = &GroupsService{client: c}
c.Issues = &IssuesService{client: c}
c.Issues = &IssuesService{client: c, timeStats: timeStats}
c.Jobs = &JobsService{client: c}
c.Labels = &LabelsService{client: c}
c.MergeRequests = &MergeRequestsService{client: c}
c.MergeRequests = &MergeRequestsService{client: c, timeStats: timeStats}
c.Milestones = &MilestonesService{client: c}
c.Namespaces = &NamespacesService{client: c}
c.Notes = &NotesService{client: c}
......
......@@ -29,7 +29,8 @@ import (
//
// GitLab API docs: https://docs.gitlab.com/ce/api/issues.html
type IssuesService struct {
client *Client
client *Client
timeStats *timeStatsService
}
// Issue represents a GitLab issue.
......@@ -309,7 +310,7 @@ func (s *IssuesService) DeleteIssue(pid interface{}, issue int, options ...Optio
// GitLab API docs:
// https://docs.gitlab.com/ce/api/issues.html#set-a-time-estimate-for-an-issue
func (s *IssuesService) SetTimeEstimate(pid interface{}, issue int, opt *SetTimeEstimateOptions, options ...OptionFunc) (*TimeStats, *Response, error) {
return s.client.timeStats.setTimeEstimate(pid, "issues", issue, opt, options...)
return s.timeStats.setTimeEstimate(pid, "issues", issue, opt, options...)
}
// ResetTimeEstimate resets the time estimate for a single project issue.
......@@ -317,7 +318,7 @@ func (s *IssuesService) SetTimeEstimate(pid interface{}, issue int, opt *SetTime
// GitLab API docs:
// https://docs.gitlab.com/ce/api/issues.html#reset-the-time-estimate-for-an-issue
func (s *IssuesService) ResetTimeEstimate(pid interface{}, issue int, options ...OptionFunc) (*TimeStats, *Response, error) {
return s.client.timeStats.resetTimeEstimate(pid, "issues", issue, options...)
return s.timeStats.resetTimeEstimate(pid, "issues", issue, options...)
}
// AddSpentTime adds spent time for a single project issue.
......@@ -325,7 +326,7 @@ func (s *IssuesService) ResetTimeEstimate(pid interface{}, issue int, options ..
// GitLab API docs:
// https://docs.gitlab.com/ce/api/issues.html#add-spent-time-for-an-issue
func (s *IssuesService) AddSpentTime(pid interface{}, issue int, opt *AddSpentTimeOptions, options ...OptionFunc) (*TimeStats, *Response, error) {
return s.client.timeStats.addSpentTime(pid, "issues", issue, opt, options...)
return s.timeStats.addSpentTime(pid, "issues", issue, opt, options...)
}
// ResetSpentTime resets the spent time for a single project issue.
......@@ -333,7 +334,7 @@ func (s *IssuesService) AddSpentTime(pid interface{}, issue int, opt *AddSpentTi
// GitLab API docs:
// https://docs.gitlab.com/ce/api/issues.html#reset-spent-time-for-an-issue
func (s *IssuesService) ResetSpentTime(pid interface{}, issue int, options ...OptionFunc) (*TimeStats, *Response, error) {
return s.client.timeStats.resetSpentTime(pid, "issues", issue, options...)
return s.timeStats.resetSpentTime(pid, "issues", issue, options...)
}
// GetTimeSpent gets the spent time for a single project issue.
......@@ -341,5 +342,5 @@ func (s *IssuesService) ResetSpentTime(pid interface{}, issue int, options ...Op
// GitLab API docs:
// https://docs.gitlab.com/ce/api/issues.html#get-time-tracking-stats
func (s *IssuesService) GetTimeSpent(pid interface{}, issue int, options ...OptionFunc) (*TimeStats, *Response, error) {
return s.client.timeStats.getTimeSpent(pid, "issues", issue, options...)
return s.timeStats.getTimeSpent(pid, "issues", issue, options...)
}
......@@ -28,7 +28,8 @@ import (
// GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/merge_requests.md
type MergeRequestsService struct {
client *Client
client *Client
timeStats *timeStatsService
}
// MergeRequest represents a GitLab merge request.
......@@ -342,7 +343,7 @@ func (s *MergeRequestsService) AcceptMergeRequest(pid interface{}, mergeRequest
// GitLab API docs:
// https://docs.gitlab.com/ce/api/merge_requests.html#set-a-time-estimate-for-a-merge-request
func (s *MergeRequestsService) SetTimeEstimate(pid interface{}, mergeRequest int, opt *SetTimeEstimateOptions, options ...OptionFunc) (*TimeStats, *Response, error) {
return s.client.timeStats.setTimeEstimate(pid, "merge_requests", mergeRequest, opt, options...)
return s.timeStats.setTimeEstimate(pid, "merge_requests", mergeRequest, opt, options...)
}
// ResetTimeEstimate resets the time estimate for a single project merge request.
......@@ -350,7 +351,7 @@ func (s *MergeRequestsService) SetTimeEstimate(pid interface{}, mergeRequest int
// GitLab API docs:
// https://docs.gitlab.com/ce/api/merge_requests.html#reset-the-time-estimate-for-a-merge-request
func (s *MergeRequestsService) ResetTimeEstimate(pid interface{}, mergeRequest int, options ...OptionFunc) (*TimeStats, *Response, error) {
return s.client.timeStats.resetTimeEstimate(pid, "merge_requests", mergeRequest, options...)
return s.timeStats.resetTimeEstimate(pid, "merge_requests", mergeRequest, options...)
}
// AddSpentTime adds spent time for a single project merge request.
......@@ -358,7 +359,7 @@ func (s *MergeRequestsService) ResetTimeEstimate(pid interface{}, mergeRequest i
// GitLab API docs:
// https://docs.gitlab.com/ce/api/merge_requests.html#add-spent-time-for-a-merge-request
func (s *MergeRequestsService) AddSpentTime(pid interface{}, mergeRequest int, opt *AddSpentTimeOptions, options ...OptionFunc) (*TimeStats, *Response, error) {
return s.client.timeStats.addSpentTime(pid, "merge_requests", mergeRequest, opt, options...)
return s.timeStats.addSpentTime(pid, "merge_requests", mergeRequest, opt, options...)
}
// ResetSpentTime resets the spent time for a single project merge request.
......@@ -366,7 +367,7 @@ func (s *MergeRequestsService) AddSpentTime(pid interface{}, mergeRequest int, o
// GitLab API docs:
// https://docs.gitlab.com/ce/api/merge_requests.html#reset-spent-time-for-a-merge-request
func (s *MergeRequestsService) ResetSpentTime(pid interface{}, mergeRequest int, options ...OptionFunc) (*TimeStats, *Response, error) {
return s.client.timeStats.resetSpentTime(pid, "merge_requests", mergeRequest, options...)
return s.timeStats.resetSpentTime(pid, "merge_requests", mergeRequest, options...)
}
// GetTimeSpent gets the spent time for a single project merge request.
......@@ -374,5 +375,5 @@ func (s *MergeRequestsService) ResetSpentTime(pid interface{}, mergeRequest int,
// GitLab API docs:
// https://docs.gitlab.com/ce/api/merge_requests.html#get-time-tracking-stats
func (s *MergeRequestsService) GetTimeSpent(pid interface{}, mergeRequest int, options ...OptionFunc) (*TimeStats, *Response, error) {
return s.client.timeStats.getTimeSpent(pid, "merge_requests", mergeRequest, options...)
return s.timeStats.getTimeSpent(pid, "merge_requests", mergeRequest, options...)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment