TrackedTime API >= 1.11.x needed (#415)

Merge branch 'master' into more-version-checks

TrackedTime API >= 1.11.x needed

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/415
Reviewed-by: techknowlogick <techknowlogick@gitea.io>
Reviewed-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
6543 2020-09-10 01:37:55 +00:00 committed by Andrew Thornton
parent 87f7b1866d
commit dd1ecd4b3d

View file

@ -27,18 +27,27 @@ type TrackedTime struct {
// GetUserTrackedTimes list tracked times of a user // GetUserTrackedTimes list tracked times of a user
func (c *Client) GetUserTrackedTimes(owner, repo, user string) ([]*TrackedTime, error) { func (c *Client) GetUserTrackedTimes(owner, repo, user string) ([]*TrackedTime, error) {
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
return nil, err
}
times := make([]*TrackedTime, 0, 10) times := make([]*TrackedTime, 0, 10)
return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times/%s", owner, repo, user), nil, nil, &times) return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times/%s", owner, repo, user), nil, nil, &times)
} }
// GetRepoTrackedTimes list tracked times of a repository // GetRepoTrackedTimes list tracked times of a repository
func (c *Client) GetRepoTrackedTimes(owner, repo string) ([]*TrackedTime, error) { func (c *Client) GetRepoTrackedTimes(owner, repo string) ([]*TrackedTime, error) {
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
return nil, err
}
times := make([]*TrackedTime, 0, 10) times := make([]*TrackedTime, 0, 10)
return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times", owner, repo), nil, nil, &times) return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times", owner, repo), nil, nil, &times)
} }
// GetMyTrackedTimes list tracked times of the current user // GetMyTrackedTimes list tracked times of the current user
func (c *Client) GetMyTrackedTimes() ([]*TrackedTime, error) { func (c *Client) GetMyTrackedTimes() ([]*TrackedTime, error) {
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
return nil, err
}
times := make([]*TrackedTime, 0, 10) times := make([]*TrackedTime, 0, 10)
return times, c.getParsedResponse("GET", "/user/times", nil, nil, &times) return times, c.getParsedResponse("GET", "/user/times", nil, nil, &times)
} }
@ -63,6 +72,9 @@ func (opt AddTimeOption) Validate() error {
// AddTime adds time to issue with the given index // AddTime adds time to issue with the given index
func (c *Client) AddTime(owner, repo string, index int64, opt AddTimeOption) (*TrackedTime, error) { func (c *Client) AddTime(owner, repo string, index int64, opt AddTimeOption) (*TrackedTime, error) {
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
return nil, err
}
if err := opt.Validate(); err != nil { if err := opt.Validate(); err != nil {
return nil, err return nil, err
} }
@ -82,6 +94,9 @@ type ListTrackedTimesOptions struct {
// ListTrackedTimes list tracked times of a single issue for a given repository // ListTrackedTimes list tracked times of a single issue for a given repository
func (c *Client) ListTrackedTimes(owner, repo string, index int64, opt ListTrackedTimesOptions) ([]*TrackedTime, error) { func (c *Client) ListTrackedTimes(owner, repo string, index int64, opt ListTrackedTimesOptions) ([]*TrackedTime, error) {
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
return nil, err
}
opt.setDefaults() opt.setDefaults()
times := make([]*TrackedTime, 0, opt.PageSize) times := make([]*TrackedTime, 0, opt.PageSize)
return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/times?%s", owner, repo, index, opt.getURLQuery().Encode()), nil, nil, &times) return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/times?%s", owner, repo, index, opt.getURLQuery().Encode()), nil, nil, &times)
@ -89,12 +104,18 @@ func (c *Client) ListTrackedTimes(owner, repo string, index int64, opt ListTrack
// ResetIssueTime reset tracked time of a single issue for a given repository // ResetIssueTime reset tracked time of a single issue for a given repository
func (c *Client) ResetIssueTime(owner, repo string, index int64) error { func (c *Client) ResetIssueTime(owner, repo string, index int64) error {
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
return err
}
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/times", owner, repo, index), nil, nil) _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/times", owner, repo, index), nil, nil)
return err return err
} }
// DeleteTime delete a specific tracked time by id of a single issue for a given repository // DeleteTime delete a specific tracked time by id of a single issue for a given repository
func (c *Client) DeleteTime(owner, repo string, index, timeID int64) error { func (c *Client) DeleteTime(owner, repo string, index, timeID int64) error {
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
return err
}
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/times/%d", owner, repo, index, timeID), nil, nil) _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/times/%d", owner, repo, index, timeID), nil, nil)
return err return err
} }