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
0d7e821f
Commit
0d7e821f
authored
Nov 19, 2017
by
Sander van Harmelen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement a generic ISOTime type
parent
22272f90
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
40 deletions
+39
-40
gitlab.go
gitlab.go
+36
-0
users.go
users.go
+3
-40
No files found.
gitlab.go
View file @
0d7e821f
...
...
@@ -20,6 +20,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
...
...
@@ -28,6 +29,7 @@ import (
"sort"
"strconv"
"strings"
"time"
"github.com/google/go-querystring/query"
)
...
...
@@ -67,6 +69,40 @@ const (
OwnerPermission
AccessLevelValue
=
50
)
// ISOTime represents an ISO 8601 formatted date
type
ISOTime
time
.
Time
// ISO 8901 date format
const
iso8901
=
"2006-01-02"
// MarshalJSON implements the json.Marshaler interface
func
(
t
ISOTime
)
MarshalJSON
()
([]
byte
,
error
)
{
if
y
:=
time
.
Time
(
t
)
.
Year
();
y
<
0
||
y
>=
10000
{
// ISO 8901 uses 4 digits for the years
return
nil
,
errors
.
New
(
"ISOTime.MarshalJSON: year outside of range [0,9999]"
)
}
b
:=
make
([]
byte
,
0
,
len
(
iso8901
)
+
2
)
b
=
append
(
b
,
'"'
)
b
=
time
.
Time
(
t
)
.
AppendFormat
(
b
,
iso8901
)
b
=
append
(
b
,
'"'
)
return
b
,
nil
}
// UnmarshalJSON implements the json.Unmarshaler interface
func
(
t
*
ISOTime
)
UnmarshalJSON
(
data
[]
byte
)
error
{
// Ignore null, like in the main JSON package
if
string
(
data
)
==
"null"
{
return
nil
}
isotime
,
err
:=
time
.
Parse
(
`"`
+
iso8901
+
`"`
,
string
(
data
))
*
t
=
ISOTime
(
isotime
)
return
err
}
// NotificationLevelValue represents a notification level.
type
NotificationLevelValue
int
...
...
users.go
View file @
0d7e821f
...
...
@@ -20,7 +20,6 @@ import (
"errors"
"fmt"
"time"
"strings"
)
// UsersService handles communication with the user related methods of
...
...
@@ -698,52 +697,16 @@ func (s *UsersService) RevokeImpersonationToken(user, token int, options ...Opti
return
s
.
client
.
Do
(
req
,
nil
)
}
// UserActivityTime represents a custom time format
// used by Gitlab in the user/activities response (YYYY-MM-DD)
type
UserActivityTime
struct
{
time
.
Time
}
// User Activity represents an entry in the user/activities response
// LastActivityAt is deprecated and only available for downward compatibility
// UserActivity represents an entry in the user/activities response
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/users.html#get-user-activities-admin-only
type
UserActivity
struct
{
Username
string
`json:"username"`
LastActivityOn
*
UserActivityTime
`json:"last_activity_on"`
LastActivityAt
*
UserActivityTime
`json:"last_activity_at"`
// deprecated!
}
// layout of UserActivityTime for parsing time string
const
uatLayout
=
"2006-01-02"
// custom unmarshaller for for UserActivityTime
func
(
uat
*
UserActivityTime
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
s
:=
strings
.
Trim
(
string
(
b
),
"
\"
"
)
if
s
==
"null"
{
uat
.
Time
=
time
.
Time
{}
return
}
uat
.
Time
,
err
=
time
.
Parse
(
uatLayout
,
s
)
return
}
// custom marshaller for UserActivityTime
func
(
uat
*
UserActivityTime
)
MarshalJSON
()
([]
byte
,
error
)
{
if
uat
.
Time
.
UnixNano
()
==
nilTime
{
return
[]
byte
(
"null"
),
nil
}
return
[]
byte
(
fmt
.
Sprintf
(
"
\"
%s
\"
"
,
uat
.
Time
.
Format
(
uatLayout
))),
nil
}
// helper method to check whether UserActivityTime is set
var
nilTime
=
(
time
.
Time
{})
.
UnixNano
()
func
(
uat
*
UserActivityTime
)
IsSet
()
bool
{
return
uat
.
UnixNano
()
!=
nilTime
LastActivityOn
*
ISOTime
`json:"last_activity_on"`
}
// Get user activities (admin only)
// Get
UserActivities retrieves
user activities (admin only)
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/users.html#get-user-activities-admin-only
...
...
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