2019-04-25 13:06:53 -04: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"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TrackedTime worked time for an issue / pr
|
|
|
|
type TrackedTime struct {
|
2019-10-13 11:13:33 -04:00
|
|
|
ID int64 `json:"id"`
|
2019-04-25 13:06:53 -04:00
|
|
|
Created time.Time `json:"created"`
|
|
|
|
// Time in seconds
|
2020-01-03 20:44:33 -05:00
|
|
|
Time int64 `json:"time"`
|
|
|
|
// deprecated (only for backwards compatibility)
|
|
|
|
UserID int64 `json:"user_id"`
|
|
|
|
UserName string `json:"user_name"`
|
|
|
|
// deprecated (only for backwards compatibility)
|
|
|
|
IssueID int64 `json:"issue_id"`
|
|
|
|
Issue *Issue `json:"issue"`
|
2019-04-25 13:06:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetUserTrackedTimes list tracked times of a user
|
2019-10-13 11:13:33 -04:00
|
|
|
func (c *Client) GetUserTrackedTimes(owner, repo, user string) ([]*TrackedTime, error) {
|
|
|
|
times := make([]*TrackedTime, 0, 10)
|
2019-04-25 13:06:53 -04:00
|
|
|
return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times/%s", owner, repo, user), nil, nil, ×)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetRepoTrackedTimes list tracked times of a repository
|
2019-10-13 11:13:33 -04:00
|
|
|
func (c *Client) GetRepoTrackedTimes(owner, repo string) ([]*TrackedTime, error) {
|
|
|
|
times := make([]*TrackedTime, 0, 10)
|
2019-04-25 13:06:53 -04:00
|
|
|
return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times", owner, repo), nil, nil, ×)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetMyTrackedTimes list tracked times of the current user
|
2019-10-13 11:13:33 -04:00
|
|
|
func (c *Client) GetMyTrackedTimes() ([]*TrackedTime, error) {
|
|
|
|
times := make([]*TrackedTime, 0, 10)
|
2019-04-25 13:06:53 -04:00
|
|
|
return times, c.getParsedResponse("GET", "/user/times", nil, nil, ×)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddTimeOption options for adding time to an issue
|
|
|
|
type AddTimeOption struct {
|
|
|
|
// time in seconds
|
2020-01-03 20:44:33 -05:00
|
|
|
Time int64 `json:"time" binding:"Required"`
|
|
|
|
// optional
|
|
|
|
Created time.Time `json:"created"`
|
|
|
|
// optional
|
|
|
|
User string `json:"user_name"`
|
2019-04-25 13:06:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddTime adds time to issue with the given index
|
|
|
|
func (c *Client) AddTime(owner, repo string, index int64, opt AddTimeOption) (*TrackedTime, error) {
|
|
|
|
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
|
2019-10-13 11:13:33 -04:00
|
|
|
func (c *Client) ListTrackedTimes(owner, repo string, index int64) ([]*TrackedTime, error) {
|
|
|
|
times := make([]*TrackedTime, 0, 5)
|
2019-04-25 13:06:53 -04:00
|
|
|
return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/times", owner, repo, index), nil, nil, ×)
|
|
|
|
}
|