1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package gitlab
18
19 import (
20 "fmt"
21 "net/http"
22 )
23
24
25
26
27
28 type timeStatsService struct {
29 client *Client
30 }
31
32
33
34
35 type TimeStats struct {
36 HumanTimeEstimate string `json:"human_time_estimate"`
37 HumanTotalTimeSpent string `json:"human_total_time_spent"`
38 TimeEstimate int `json:"time_estimate"`
39 TotalTimeSpent int `json:"total_time_spent"`
40 }
41
42 func (t TimeStats) String() string {
43 return Stringify(t)
44 }
45
46
47
48
49
50 type SetTimeEstimateOptions struct {
51 Duration *string `url:"duration,omitempty" json:"duration,omitempty"`
52 }
53
54
55
56
57 func (s *timeStatsService) setTimeEstimate(pid interface{}, entity string, issue int, opt *SetTimeEstimateOptions, options ...RequestOptionFunc) (*TimeStats, *Response, error) {
58 project, err := parseID(pid)
59 if err != nil {
60 return nil, nil, err
61 }
62 u := fmt.Sprintf("projects/%s/%s/%d/time_estimate", PathEscape(project), entity, issue)
63
64 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
65 if err != nil {
66 return nil, nil, err
67 }
68
69 t := new(TimeStats)
70 resp, err := s.client.Do(req, t)
71 if err != nil {
72 return nil, resp, err
73 }
74
75 return t, resp, nil
76 }
77
78
79
80
81 func (s *timeStatsService) resetTimeEstimate(pid interface{}, entity string, issue int, options ...RequestOptionFunc) (*TimeStats, *Response, error) {
82 project, err := parseID(pid)
83 if err != nil {
84 return nil, nil, err
85 }
86 u := fmt.Sprintf("projects/%s/%s/%d/reset_time_estimate", PathEscape(project), entity, issue)
87
88 req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
89 if err != nil {
90 return nil, nil, err
91 }
92
93 t := new(TimeStats)
94 resp, err := s.client.Do(req, t)
95 if err != nil {
96 return nil, resp, err
97 }
98
99 return t, resp, nil
100 }
101
102
103
104
105 type AddSpentTimeOptions struct {
106 Duration *string `url:"duration,omitempty" json:"duration,omitempty"`
107 Summary *string `url:"summary,omitempty" json:"summary,omitempty"`
108 }
109
110
111
112
113 func (s *timeStatsService) addSpentTime(pid interface{}, entity string, issue int, opt *AddSpentTimeOptions, options ...RequestOptionFunc) (*TimeStats, *Response, error) {
114 project, err := parseID(pid)
115 if err != nil {
116 return nil, nil, err
117 }
118 u := fmt.Sprintf("projects/%s/%s/%d/add_spent_time", PathEscape(project), entity, issue)
119
120 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
121 if err != nil {
122 return nil, nil, err
123 }
124
125 t := new(TimeStats)
126 resp, err := s.client.Do(req, t)
127 if err != nil {
128 return nil, resp, err
129 }
130
131 return t, resp, nil
132 }
133
134
135
136
137 func (s *timeStatsService) resetSpentTime(pid interface{}, entity string, issue int, options ...RequestOptionFunc) (*TimeStats, *Response, error) {
138 project, err := parseID(pid)
139 if err != nil {
140 return nil, nil, err
141 }
142 u := fmt.Sprintf("projects/%s/%s/%d/reset_spent_time", PathEscape(project), entity, issue)
143
144 req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
145 if err != nil {
146 return nil, nil, err
147 }
148
149 t := new(TimeStats)
150 resp, err := s.client.Do(req, t)
151 if err != nil {
152 return nil, resp, err
153 }
154
155 return t, resp, nil
156 }
157
158
159
160
161 func (s *timeStatsService) getTimeSpent(pid interface{}, entity string, issue int, options ...RequestOptionFunc) (*TimeStats, *Response, error) {
162 project, err := parseID(pid)
163 if err != nil {
164 return nil, nil, err
165 }
166 u := fmt.Sprintf("projects/%s/%s/%d/time_stats", PathEscape(project), entity, issue)
167
168 req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
169 if err != nil {
170 return nil, nil, err
171 }
172
173 t := new(TimeStats)
174 resp, err := s.client.Do(req, t)
175 if err != nil {
176 return nil, resp, err
177 }
178
179 return t, resp, nil
180 }
181
View as plain text