|
| 1 | +// Copyright 2017 The Gitea Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a MIT-style |
| 3 | +// license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +package gitea |
| 6 | + |
| 7 | +import ( |
| 8 | + "bytes" |
| 9 | + "encoding/json" |
| 10 | + "fmt" |
| 11 | + "time" |
| 12 | +) |
| 13 | + |
| 14 | +// TrackedTime worked time for an issue / pr |
| 15 | +// swagger:response TrackedTime |
| 16 | +type TrackedTime struct { |
| 17 | + ID int64 `json:"id"` |
| 18 | + Created time.Time `json:"created"` |
| 19 | + // Time in seconds |
| 20 | + Time int64 `json:"time"` |
| 21 | + UserID int64 `json:"user_id"` |
| 22 | + IssueID int64 `json:"issue_id"` |
| 23 | +} |
| 24 | + |
| 25 | +// TrackedTimes represent a list of tracked times |
| 26 | +// swagger:response TrackedTimes |
| 27 | +type TrackedTimes []*TrackedTime |
| 28 | + |
| 29 | +// GetUserTrackedTimes list tracked times of a user |
| 30 | +func (c *Client) GetUserTrackedTimes(owner, repo, user string) (TrackedTimes, error) { |
| 31 | + times := make(TrackedTimes, 0, 10) |
| 32 | + return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times/%s", owner, repo, user), nil, nil, ×) |
| 33 | +} |
| 34 | + |
| 35 | +// GetRepoTrackedTimes list tracked times of a repository |
| 36 | +func (c *Client) GetRepoTrackedTimes(owner, repo string) (TrackedTimes, error) { |
| 37 | + times := make(TrackedTimes, 0, 10) |
| 38 | + return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times", owner, repo), nil, nil, ×) |
| 39 | +} |
| 40 | + |
| 41 | +// GetMyTrackedTimes list tracked times of the current user |
| 42 | +func (c *Client) GetMyTrackedTimes() (TrackedTimes, error) { |
| 43 | + times := make(TrackedTimes, 0, 10) |
| 44 | + return times, c.getParsedResponse("GET", "/user/times", nil, nil, ×) |
| 45 | +} |
| 46 | + |
| 47 | +// AddTimeOption adds time manually to an issue |
| 48 | +// swagger:response AddTimeOption |
| 49 | +type AddTimeOption struct { |
| 50 | + Time int64 `json:"time" binding:"Required"` |
| 51 | +} |
| 52 | + |
| 53 | +// AddTime adds time to issue with the given index |
| 54 | +func (c *Client) AddTime(owner, repo string, index int64, opt AddTimeOption) (*TrackedTime, error) { |
| 55 | + body, err := json.Marshal(&opt) |
| 56 | + if err != nil { |
| 57 | + return nil, err |
| 58 | + } |
| 59 | + t := new(TrackedTime) |
| 60 | + return t, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/times", owner, repo, index), |
| 61 | + jsonHeader, bytes.NewReader(body), t) |
| 62 | +} |
| 63 | + |
| 64 | +// ListTrackedTimes get tracked times of one issue via issue id |
| 65 | +func (c *Client) ListTrackedTimes(owner, repo string, index int64) (TrackedTimes, error) { |
| 66 | + times := make(TrackedTimes, 0, 5) |
| 67 | + return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/times", owner, repo, index), nil, nil, ×) |
| 68 | +} |
0 commit comments