2017-07-28 09:12:22 +03:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package gitea
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2019-05-11 18:38:52 +03:00
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/structs"
|
2017-07-28 09:12:22 +03:00
|
|
|
)
|
|
|
|
|
2019-05-11 18:38:52 +03:00
|
|
|
// TrackedTime is equal to structs.TrackedTime
|
|
|
|
type TrackedTime = structs.TrackedTime
|
2017-07-28 09:12:22 +03:00
|
|
|
|
2019-05-11 18:38:52 +03:00
|
|
|
// TrackedTimes is equal to structs.TrackedTimes
|
|
|
|
type TrackedTimes = structs.TrackedTimes
|
2017-07-28 09:12:22 +03:00
|
|
|
|
|
|
|
// GetUserTrackedTimes list tracked times of a user
|
|
|
|
func (c *Client) GetUserTrackedTimes(owner, repo, user string) (TrackedTimes, error) {
|
|
|
|
times := make(TrackedTimes, 0, 10)
|
|
|
|
return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times/%s", owner, repo, user), nil, nil, ×)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetRepoTrackedTimes list tracked times of a repository
|
|
|
|
func (c *Client) GetRepoTrackedTimes(owner, repo string) (TrackedTimes, error) {
|
|
|
|
times := make(TrackedTimes, 0, 10)
|
|
|
|
return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times", owner, repo), nil, nil, ×)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetMyTrackedTimes list tracked times of the current user
|
|
|
|
func (c *Client) GetMyTrackedTimes() (TrackedTimes, error) {
|
|
|
|
times := make(TrackedTimes, 0, 10)
|
|
|
|
return times, c.getParsedResponse("GET", "/user/times", nil, nil, ×)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddTime adds time to issue with the given index
|
2019-05-11 18:38:52 +03:00
|
|
|
func (c *Client) AddTime(owner, repo string, index int64, opt structs.AddTimeOption) (*TrackedTime, error) {
|
2017-07-28 09:12:22 +03:00
|
|
|
body, err := json.Marshal(&opt)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
t := new(TrackedTime)
|
|
|
|
return t, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/times", owner, repo, index),
|
|
|
|
jsonHeader, bytes.NewReader(body), t)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListTrackedTimes get tracked times of one issue via issue id
|
|
|
|
func (c *Client) ListTrackedTimes(owner, repo string, index int64) (TrackedTimes, error) {
|
|
|
|
times := make(TrackedTimes, 0, 5)
|
|
|
|
return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/times", owner, repo, index), nil, nil, ×)
|
|
|
|
}
|