Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
go-gitlab
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
go-gitlab
Commits
3acf8d75
Commit
3acf8d75
authored
Feb 03, 2017
by
Rob Warner
Committed by
Sander van Harmelen
Feb 03, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Time Tracking API (#119)
parent
e3c86bb0
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
185 additions
and
0 deletions
+185
-0
gitlab.go
gitlab.go
+2
-0
time_stats.go
time_stats.go
+183
-0
No files found.
gitlab.go
View file @
3acf8d75
...
...
@@ -137,6 +137,7 @@ type Client struct {
Settings
*
SettingsService
SystemHooks
*
SystemHooksService
Tags
*
TagsService
TimeStats
*
TimeStatsService
Users
*
UsersService
}
...
...
@@ -197,6 +198,7 @@ func newClient(httpClient *http.Client, tokenType tokenType, token string) *Clie
c
.
Settings
=
&
SettingsService
{
client
:
c
}
c
.
SystemHooks
=
&
SystemHooksService
{
client
:
c
}
c
.
Tags
=
&
TagsService
{
client
:
c
}
c
.
TimeStats
=
&
TimeStatsService
{
client
:
c
}
c
.
Users
=
&
UsersService
{
client
:
c
}
return
c
...
...
time_stats.go
0 → 100644
View file @
3acf8d75
package
gitlab
import
(
"fmt"
"net/url"
)
// TimeStatsService handles communication with the time tracking related
// methods of the GitLab API.
//
// GitLab docs: https://docs.gitlab.com/ce/workflow/time_tracking.html
// GitLab API docs: https://docs.gitlab.com/ce/api/issues.html
type
TimeStatsService
struct
{
client
*
Client
}
// Times represents the time estimates and time spent for an issue.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/issues.html
type
TimeStats
struct
{
TimeEstimate
int
`json:"time_estimate"`
TotalTimeSpent
int
`json:"total_time_spent"`
HumanTimeEstimate
string
`json:"human_time_estimate"`
HumanTotalTimeSpent
string
`json:"human_total_time_spent"`
}
func
(
t
TimeStats
)
String
()
string
{
return
Stringify
(
t
)
}
// SetTimeEstimateOptions represents the available SetTimeEstimate()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/issues.html#set-a-time-estimate-for-an-issue
type
SetTimeEstimateOptions
struct
{
Duration
*
string
`url:"duration,omitempty" json:"duration,omitempty"`
}
// SetTimeEstimate sets the time estimate for a single project issue.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/issues.html#set-a-time-estimate-for-an-issue
func
(
s
*
TimeStatsService
)
SetTimeEstimate
(
pid
interface
{},
issue
int
,
opt
*
SetTimeEstimateOptions
)
(
*
TimeStats
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/issues/%d/time_estimate"
,
url
.
QueryEscape
(
project
),
issue
)
req
,
err
:=
s
.
client
.
NewRequest
(
"POST"
,
u
,
opt
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
t
:=
new
(
TimeStats
)
resp
,
err
:=
s
.
client
.
Do
(
req
,
t
)
if
err
!=
nil
{
return
nil
,
resp
,
err
}
return
t
,
resp
,
err
}
// ResetTimeEstimate resets the time estimate for a single project issue.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/issues.html#reset-the-time-estimate-for-an-issue
func
(
s
*
TimeStatsService
)
ResetTimeEstimate
(
pid
interface
{},
issue
int
)
(
*
TimeStats
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/issues/%d/reset_time_estimate"
,
url
.
QueryEscape
(
project
),
issue
)
req
,
err
:=
s
.
client
.
NewRequest
(
"POST"
,
u
,
nil
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
t
:=
new
(
TimeStats
)
resp
,
err
:=
s
.
client
.
Do
(
req
,
t
)
if
err
!=
nil
{
return
nil
,
resp
,
err
}
return
t
,
resp
,
err
}
// AddSpentTimeOptions represents the available AddSpentTime() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/issues.html#add-spent-time-for-an-issue
type
AddSpentTimeOptions
struct
{
Duration
*
string
`url:"duration,omitempty" json:"duration,omitempty"`
}
// AddSpentTime adds spent time for a single project issue.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/issues.html#add-spent-time-for-an-issue
func
(
s
*
TimeStatsService
)
AddSpentTime
(
pid
interface
{},
issue
int
,
opt
*
AddSpentTimeOptions
)
(
*
TimeStats
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/issues/%d/add_spent_time"
,
url
.
QueryEscape
(
project
),
issue
)
req
,
err
:=
s
.
client
.
NewRequest
(
"POST"
,
u
,
opt
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
t
:=
new
(
TimeStats
)
resp
,
err
:=
s
.
client
.
Do
(
req
,
t
)
if
err
!=
nil
{
return
nil
,
resp
,
err
}
return
t
,
resp
,
err
}
// ResetSpentTime resets the spent time for a single project issue.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/issues.html#reset-spent-time-for-an-issue
func
(
s
*
TimeStatsService
)
ResetSpentTime
(
pid
interface
{},
issue
int
)
(
*
TimeStats
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/issues/%d/reset_spent_time"
,
url
.
QueryEscape
(
project
),
issue
)
req
,
err
:=
s
.
client
.
NewRequest
(
"POST"
,
u
,
nil
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
t
:=
new
(
TimeStats
)
resp
,
err
:=
s
.
client
.
Do
(
req
,
t
)
if
err
!=
nil
{
return
nil
,
resp
,
err
}
return
t
,
resp
,
err
}
// GetTimeSpent gets the spent time for a single project issue.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/issues.html#get-time-tracking-stats
func
(
s
*
TimeStatsService
)
GetTimeSpent
(
pid
interface
{},
issue
int
)
(
*
TimeStats
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/issues/%d/time_stats"
,
url
.
QueryEscape
(
project
),
issue
)
req
,
err
:=
s
.
client
.
NewRequest
(
"GET"
,
u
,
nil
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
t
:=
new
(
TimeStats
)
resp
,
err
:=
s
.
client
.
Do
(
req
,
t
)
if
err
!=
nil
{
return
nil
,
resp
,
err
}
return
t
,
resp
,
err
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment