Skip to content
This repository was archived by the owner on Jun 8, 2019. It is now read-only.

Commit c7c050c

Browse files
jonasfranzlafriks
authored andcommitted
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 <[email protected]>
1 parent 9990008 commit c7c050c

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

gitea/issue_tracked_time.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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, &times)
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, &times)
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, &times)
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, &times)
68+
}

gitea/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const (
2121
// StatusSuccess is for when the Status is Success
2222
StatusSuccess StatusState = "success"
2323
// StatusError is for when the Status is Error
24-
StatusError StatusState = "error"
24+
StatusError StatusState = "error"
2525
// StatusFailure is for when the Status is Failure
2626
StatusFailure StatusState = "failure"
2727
// StatusWarning is for when the Status is Warning

gitea/user_app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type AccessToken struct {
2626

2727
// AccessTokenList represents a list of API access token.
2828
// swagger:response AccessTokenList
29-
type AccessTokenList []*AccessToken
29+
type AccessTokenList []*AccessToken
3030

3131
// ListAccessTokens lista all the access tokens of user
3232
func (c *Client) ListAccessTokens(user, pass string) ([]*AccessToken, error) {

0 commit comments

Comments
 (0)