Commit 94597a28 authored by Sander van Harmelen's avatar Sander van Harmelen

Pull in the great work of @antony360 and @nicolaszordan (#198)

* add search query into merge requests and issues

* Moved TimeStats to Issues, added time_stats functions to merge_request

Kept time_stats.go for backward compatibility

* add fields to struct UpdateMergeRequestOptions

* Refactor PR #193 a bit
parent b0803b8f
...@@ -160,6 +160,9 @@ type Client struct { ...@@ -160,6 +160,9 @@ type Client struct {
// User agent used when communicating with the GitLab API. // User agent used when communicating with the GitLab API.
UserAgent string UserAgent string
// timeStats is an internal service used by other services.
timeStats *timeStatsService
// Services used for talking to different parts of the GitLab API. // Services used for talking to different parts of the GitLab API.
Branches *BranchesService Branches *BranchesService
BuildVariables *BuildVariablesService BuildVariables *BuildVariablesService
...@@ -187,7 +190,6 @@ type Client struct { ...@@ -187,7 +190,6 @@ type Client struct {
Settings *SettingsService Settings *SettingsService
SystemHooks *SystemHooksService SystemHooks *SystemHooksService
Tags *TagsService Tags *TagsService
TimeStats *TimeStatsService
Todos *TodosService Todos *TodosService
Users *UsersService Users *UsersService
Version *VersionService Version *VersionService
...@@ -224,10 +226,14 @@ func newClient(httpClient *http.Client, tokenType tokenType, token string) *Clie ...@@ -224,10 +226,14 @@ func newClient(httpClient *http.Client, tokenType tokenType, token string) *Clie
c := &Client{client: httpClient, tokenType: tokenType, token: token, UserAgent: userAgent} c := &Client{client: httpClient, tokenType: tokenType, token: token, UserAgent: userAgent}
if err := c.SetBaseURL(defaultBaseURL); err != nil { if err := c.SetBaseURL(defaultBaseURL); err != nil {
// should never happen since defaultBaseURL is our constant // Should never happen since defaultBaseURL is our constant.
panic(err) panic(err)
} }
// Create the internal timeStats service.
c.timeStats = &timeStatsService{client: c}
// Create all the public services.
c.Branches = &BranchesService{client: c} c.Branches = &BranchesService{client: c}
c.BuildVariables = &BuildVariablesService{client: c} c.BuildVariables = &BuildVariablesService{client: c}
c.Commits = &CommitsService{client: c} c.Commits = &CommitsService{client: c}
...@@ -254,7 +260,6 @@ func newClient(httpClient *http.Client, tokenType tokenType, token string) *Clie ...@@ -254,7 +260,6 @@ func newClient(httpClient *http.Client, tokenType tokenType, token string) *Clie
c.Settings = &SettingsService{client: c} c.Settings = &SettingsService{client: c}
c.SystemHooks = &SystemHooksService{client: c} c.SystemHooks = &SystemHooksService{client: c}
c.Tags = &TagsService{client: c} c.Tags = &TagsService{client: c}
c.TimeStats = &TimeStatsService{client: c}
c.Todos = &TodosService{client: c} c.Todos = &TodosService{client: c}
c.Users = &UsersService{client: c} c.Users = &UsersService{client: c}
c.Version = &VersionService{client: c} c.Version = &VersionService{client: c}
...@@ -440,6 +445,7 @@ func (c *Client) Do(req *http.Request, v interface{}) (*Response, error) { ...@@ -440,6 +445,7 @@ func (c *Client) Do(req *http.Request, v interface{}) (*Response, error) {
err = json.NewDecoder(resp.Body).Decode(v) err = json.NewDecoder(resp.Body).Decode(v)
} }
} }
return response, err return response, err
} }
......
...@@ -162,6 +162,7 @@ type ListProjectIssuesOptions struct { ...@@ -162,6 +162,7 @@ type ListProjectIssuesOptions struct {
Milestone *string `url:"milestone,omitempty" json:"milestone,omitempty"` Milestone *string `url:"milestone,omitempty" json:"milestone,omitempty"`
OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"` OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
Sort *string `url:"sort,omitempty" json:"sort,omitempty"` Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
} }
// ListProjectIssues gets a list of project issues. This function accepts // ListProjectIssues gets a list of project issues. This function accepts
...@@ -302,3 +303,43 @@ func (s *IssuesService) DeleteIssue(pid interface{}, issue int, options ...Optio ...@@ -302,3 +303,43 @@ func (s *IssuesService) DeleteIssue(pid interface{}, issue int, options ...Optio
return s.client.Do(req, nil) return s.client.Do(req, nil)
} }
// SetTimeEstimate sets the time estimate for a single project issue.
//
// 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...)
}
// ResetTimeEstimate resets the time estimate for a single project issue.
//
// 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...)
}
// AddSpentTime adds spent time for a single project issue.
//
// 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...)
}
// ResetSpentTime resets the spent time for a single project issue.
//
// 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...)
}
// GetTimeSpent gets the spent time for a single project issue.
//
// 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...)
}
...@@ -267,6 +267,8 @@ type UpdateMergeRequestOptions struct { ...@@ -267,6 +267,8 @@ type UpdateMergeRequestOptions struct {
Description *string `url:"description,omitempty" json:"description,omitempty"` Description *string `url:"description,omitempty" json:"description,omitempty"`
TargetBranch *string `url:"target_branch,omitemtpy" json:"target_branch,omitemtpy"` TargetBranch *string `url:"target_branch,omitemtpy" json:"target_branch,omitemtpy"`
AssigneeID *int `url:"assignee_id,omitempty" json:"assignee_id,omitempty"` AssigneeID *int `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
Labels Labels `url:"labels,comma,omitempty" json:"labels,omitempty"`
MilestoneID *int `url:"milestone_id,omitempty" json:"milestone_id,omitempty"`
StateEvent *string `url:"state_event,omitempty" json:"state_event,omitempty"` StateEvent *string `url:"state_event,omitempty" json:"state_event,omitempty"`
} }
...@@ -334,3 +336,43 @@ func (s *MergeRequestsService) AcceptMergeRequest(pid interface{}, mergeRequest ...@@ -334,3 +336,43 @@ func (s *MergeRequestsService) AcceptMergeRequest(pid interface{}, mergeRequest
return m, resp, err return m, resp, err
} }
// SetTimeEstimate sets the time estimate for a single project merge request.
//
// 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...)
}
// ResetTimeEstimate resets the time estimate for a single project merge request.
//
// 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...)
}
// AddSpentTime adds spent time for a single project merge request.
//
// 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...)
}
// ResetSpentTime resets the spent time for a single project merge request.
//
// 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...)
}
// GetTimeSpent gets the spent time for a single project merge request.
//
// 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...)
}
...@@ -5,20 +5,17 @@ import ( ...@@ -5,20 +5,17 @@ import (
"net/url" "net/url"
) )
// TimeStatsService handles communication with the time tracking related // timeStatsService handles communication with the time tracking related
// methods of the GitLab API. // methods of the GitLab API.
// //
// GitLab docs: https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/workflow/time_tracking.md // GitLab docs: https://docs.gitlab.com/ce/workflow/time_tracking.html
// GitLab API docs: type timeStatsService struct {
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/issues.md
type TimeStatsService struct {
client *Client client *Client
} }
// TimeStats represents the time estimates and time spent for an issue. // TimeStats represents the time estimates and time spent for an issue.
// //
// GitLab API docs: // GitLab docs: https://docs.gitlab.com/ce/workflow/time_tracking.html
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/issues.md
type TimeStats struct { type TimeStats struct {
HumanTimeEstimate string `json:"human_time_estimate"` HumanTimeEstimate string `json:"human_time_estimate"`
HumanTotalTimeSpent string `json:"human_total_time_spent"` HumanTotalTimeSpent string `json:"human_total_time_spent"`
...@@ -33,22 +30,20 @@ func (t TimeStats) String() string { ...@@ -33,22 +30,20 @@ func (t TimeStats) String() string {
// SetTimeEstimateOptions represents the available SetTimeEstimate() // SetTimeEstimateOptions represents the available SetTimeEstimate()
// options. // options.
// //
// GitLab API docs: // GitLab docs: https://docs.gitlab.com/ce/workflow/time_tracking.html
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/issues.md#set-a-time-estimate-for-an-issue
type SetTimeEstimateOptions struct { type SetTimeEstimateOptions struct {
Duration *string `url:"duration,omitempty" json:"duration,omitempty"` Duration *string `url:"duration,omitempty" json:"duration,omitempty"`
} }
// SetTimeEstimate sets the time estimate for a single project issue. // setTimeEstimate sets the time estimate for a single project issue.
// //
// GitLab API docs: // GitLab docs: https://docs.gitlab.com/ce/workflow/time_tracking.html
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/issues.md#set-a-time-estimate-for-an-issue func (s *timeStatsService) setTimeEstimate(pid interface{}, entity string, issue int, opt *SetTimeEstimateOptions, options ...OptionFunc) (*TimeStats, *Response, error) {
func (s *TimeStatsService) SetTimeEstimate(pid interface{}, issue int, opt *SetTimeEstimateOptions, options ...OptionFunc) (*TimeStats, *Response, error) {
project, err := parseID(pid) project, err := parseID(pid)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
u := fmt.Sprintf("projects/%s/issues/%d/time_estimate", url.QueryEscape(project), issue) u := fmt.Sprintf("projects/%s/%s/%d/time_estimate", url.QueryEscape(project), entity, issue)
req, err := s.client.NewRequest("POST", u, opt, options) req, err := s.client.NewRequest("POST", u, opt, options)
if err != nil { if err != nil {
...@@ -64,16 +59,15 @@ func (s *TimeStatsService) SetTimeEstimate(pid interface{}, issue int, opt *SetT ...@@ -64,16 +59,15 @@ func (s *TimeStatsService) SetTimeEstimate(pid interface{}, issue int, opt *SetT
return t, resp, err return t, resp, err
} }
// ResetTimeEstimate resets the time estimate for a single project issue. // resetTimeEstimate resets the time estimate for a single project issue.
// //
// GitLab API docs: // GitLab docs: https://docs.gitlab.com/ce/workflow/time_tracking.html
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/issues.md#reset-the-time-estimate-for-an-issue func (s *timeStatsService) resetTimeEstimate(pid interface{}, entity string, issue int, options ...OptionFunc) (*TimeStats, *Response, error) {
func (s *TimeStatsService) ResetTimeEstimate(pid interface{}, issue int, options ...OptionFunc) (*TimeStats, *Response, error) {
project, err := parseID(pid) project, err := parseID(pid)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
u := fmt.Sprintf("projects/%s/issues/%d/reset_time_estimate", url.QueryEscape(project), issue) u := fmt.Sprintf("projects/%s/%s/%d/reset_time_estimate", url.QueryEscape(project), entity, issue)
req, err := s.client.NewRequest("POST", u, nil, options) req, err := s.client.NewRequest("POST", u, nil, options)
if err != nil { if err != nil {
...@@ -91,22 +85,20 @@ func (s *TimeStatsService) ResetTimeEstimate(pid interface{}, issue int, options ...@@ -91,22 +85,20 @@ func (s *TimeStatsService) ResetTimeEstimate(pid interface{}, issue int, options
// AddSpentTimeOptions represents the available AddSpentTime() options. // AddSpentTimeOptions represents the available AddSpentTime() options.
// //
// GitLab API docs: // GitLab docs: https://docs.gitlab.com/ce/workflow/time_tracking.html
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/issues.md#add-spent-time-for-an-issue
type AddSpentTimeOptions struct { type AddSpentTimeOptions struct {
Duration *string `url:"duration,omitempty" json:"duration,omitempty"` Duration *string `url:"duration,omitempty" json:"duration,omitempty"`
} }
// AddSpentTime adds spent time for a single project issue. // addSpentTime adds spent time for a single project issue.
// //
// GitLab API docs: // GitLab docs: https://docs.gitlab.com/ce/workflow/time_tracking.html
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/issues.md#add-spent-time-for-an-issue func (s *timeStatsService) addSpentTime(pid interface{}, entity string, issue int, opt *AddSpentTimeOptions, options ...OptionFunc) (*TimeStats, *Response, error) {
func (s *TimeStatsService) AddSpentTime(pid interface{}, issue int, opt *AddSpentTimeOptions, options ...OptionFunc) (*TimeStats, *Response, error) {
project, err := parseID(pid) project, err := parseID(pid)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
u := fmt.Sprintf("projects/%s/issues/%d/add_spent_time", url.QueryEscape(project), issue) u := fmt.Sprintf("projects/%s/%s/%d/add_spent_time", url.QueryEscape(project), entity, issue)
req, err := s.client.NewRequest("POST", u, opt, options) req, err := s.client.NewRequest("POST", u, opt, options)
if err != nil { if err != nil {
...@@ -122,16 +114,15 @@ func (s *TimeStatsService) AddSpentTime(pid interface{}, issue int, opt *AddSpen ...@@ -122,16 +114,15 @@ func (s *TimeStatsService) AddSpentTime(pid interface{}, issue int, opt *AddSpen
return t, resp, err return t, resp, err
} }
// ResetSpentTime resets the spent time for a single project issue. // resetSpentTime resets the spent time for a single project issue.
// //
// GitLab API docs: // GitLab docs: https://docs.gitlab.com/ce/workflow/time_tracking.html
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/issues.md#reset-spent-time-for-an-issue func (s *timeStatsService) resetSpentTime(pid interface{}, entity string, issue int, options ...OptionFunc) (*TimeStats, *Response, error) {
func (s *TimeStatsService) ResetSpentTime(pid interface{}, issue int, options ...OptionFunc) (*TimeStats, *Response, error) {
project, err := parseID(pid) project, err := parseID(pid)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
u := fmt.Sprintf("projects/%s/issues/%d/reset_spent_time", url.QueryEscape(project), issue) u := fmt.Sprintf("projects/%s/%s/%d/reset_spent_time", url.QueryEscape(project), entity, issue)
req, err := s.client.NewRequest("POST", u, nil, options) req, err := s.client.NewRequest("POST", u, nil, options)
if err != nil { if err != nil {
...@@ -147,16 +138,15 @@ func (s *TimeStatsService) ResetSpentTime(pid interface{}, issue int, options .. ...@@ -147,16 +138,15 @@ func (s *TimeStatsService) ResetSpentTime(pid interface{}, issue int, options ..
return t, resp, err return t, resp, err
} }
// GetTimeSpent gets the spent time for a single project issue. // getTimeSpent gets the spent time for a single project issue.
// //
// GitLab API docs: // GitLab docs: https://docs.gitlab.com/ce/workflow/time_tracking.html
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/issues.md#get-time-tracking-stats func (s *timeStatsService) getTimeSpent(pid interface{}, entity string, issue int, options ...OptionFunc) (*TimeStats, *Response, error) {
func (s *TimeStatsService) GetTimeSpent(pid interface{}, issue int, options ...OptionFunc) (*TimeStats, *Response, error) {
project, err := parseID(pid) project, err := parseID(pid)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
u := fmt.Sprintf("projects/%s/issues/%d/time_stats", url.QueryEscape(project), issue) u := fmt.Sprintf("projects/%s/%s/%d/time_stats", url.QueryEscape(project), entity, issue)
req, err := s.client.NewRequest("GET", u, nil, options) req, err := s.client.NewRequest("GET", u, nil, options)
if err != nil { if err != nil {
......
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