From c7c050c877e2f863e192c12110e73d658f7ef167 Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Fri, 28 Jul 2017 08:12:22 +0200 Subject: [PATCH] Feature/timetracker (#65) * Adding time tracker api * Adding swagger support * Adding GetMyTrackedTimes * Adding swagger support * Fixed package collision * Adding documentation * Replacing []*TrackedTime with TrackedTimes * Adding GetRepoTrackedTimes * Changing endpoint of GetUserTrackedTimes See go-gitea/gitea/pull/2211 Signed-off-by: Jonas Franz --- gitea/issue_tracked_time.go | 68 +++++++++++++++++++++++++++++++++++++ gitea/status.go | 2 +- gitea/user_app.go | 2 +- 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 gitea/issue_tracked_time.go diff --git a/gitea/issue_tracked_time.go b/gitea/issue_tracked_time.go new file mode 100644 index 0000000..8b8b766 --- /dev/null +++ b/gitea/issue_tracked_time.go @@ -0,0 +1,68 @@ +// 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 +// swagger:response TrackedTime +type TrackedTime struct { + ID int64 `json:"id"` + Created time.Time `json:"created"` + // Time in seconds + Time int64 `json:"time"` + UserID int64 `json:"user_id"` + IssueID int64 `json:"issue_id"` +} + +// TrackedTimes represent a list of tracked times +// swagger:response TrackedTimes +type TrackedTimes []*TrackedTime + +// 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, ×) +} + +// AddTimeOption adds time manually to an issue +// swagger:response AddTimeOption +type AddTimeOption struct { + Time int64 `json:"time" binding:"Required"` +} + +// 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 +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, ×) +} diff --git a/gitea/status.go b/gitea/status.go index e694add..d5cdcd5 100644 --- a/gitea/status.go +++ b/gitea/status.go @@ -21,7 +21,7 @@ const ( // StatusSuccess is for when the Status is Success StatusSuccess StatusState = "success" // StatusError is for when the Status is Error - StatusError StatusState = "error" + StatusError StatusState = "error" // StatusFailure is for when the Status is Failure StatusFailure StatusState = "failure" // StatusWarning is for when the Status is Warning diff --git a/gitea/user_app.go b/gitea/user_app.go index 82d2a40..08e9851 100644 --- a/gitea/user_app.go +++ b/gitea/user_app.go @@ -26,7 +26,7 @@ type AccessToken struct { // AccessTokenList represents a list of API access token. // swagger:response AccessTokenList -type AccessTokenList []*AccessToken +type AccessTokenList []*AccessToken // ListAccessTokens lista all the access tokens of user func (c *Client) ListAccessTokens(user, pass string) ([]*AccessToken, error) {