You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

issue_tracked_time.go 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. package gitea
  5. import (
  6. "bytes"
  7. "encoding/json"
  8. "fmt"
  9. "time"
  10. )
  11. // TrackedTime worked time for an issue / pr
  12. type TrackedTime struct {
  13. ID int64 `json:"id"`
  14. // swagger:strfmt date-time
  15. Created time.Time `json:"created"`
  16. // Time in seconds
  17. Time int64 `json:"time"`
  18. UserID int64 `json:"user_id"`
  19. IssueID int64 `json:"issue_id"`
  20. }
  21. // TrackedTimes represent a list of tracked times
  22. type TrackedTimes []*TrackedTime
  23. // GetUserTrackedTimes list tracked times of a user
  24. func (c *Client) GetUserTrackedTimes(owner, repo, user string) (TrackedTimes, error) {
  25. times := make(TrackedTimes, 0, 10)
  26. return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times/%s", owner, repo, user), nil, nil, &times)
  27. }
  28. // GetRepoTrackedTimes list tracked times of a repository
  29. func (c *Client) GetRepoTrackedTimes(owner, repo string) (TrackedTimes, error) {
  30. times := make(TrackedTimes, 0, 10)
  31. return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times", owner, repo), nil, nil, &times)
  32. }
  33. // GetMyTrackedTimes list tracked times of the current user
  34. func (c *Client) GetMyTrackedTimes() (TrackedTimes, error) {
  35. times := make(TrackedTimes, 0, 10)
  36. return times, c.getParsedResponse("GET", "/user/times", nil, nil, &times)
  37. }
  38. // AddTimeOption options for adding time to an issue
  39. type AddTimeOption struct {
  40. // time in seconds
  41. // required: true
  42. Time int64 `json:"time" binding:"Required"`
  43. }
  44. // AddTime adds time to issue with the given index
  45. func (c *Client) AddTime(owner, repo string, index int64, opt AddTimeOption) (*TrackedTime, error) {
  46. body, err := json.Marshal(&opt)
  47. if err != nil {
  48. return nil, err
  49. }
  50. t := new(TrackedTime)
  51. return t, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/times", owner, repo, index),
  52. jsonHeader, bytes.NewReader(body), t)
  53. }
  54. // ListTrackedTimes get tracked times of one issue via issue id
  55. func (c *Client) ListTrackedTimes(owner, repo string, index int64) (TrackedTimes, error) {
  56. times := make(TrackedTimes, 0, 5)
  57. return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/times", owner, repo, index), nil, nil, &times)
  58. }