Skip to content

Commit cdecead

Browse files
authored
Change all fields from time.Time to github.Timestamp (#2646)
1 parent d386e49 commit cdecead

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+351
-335
lines changed

.golangci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ linters:
2121
- staticcheck
2222
- ineffassign
2323
- unused
24-
issues:
24+
issues:
25+
exclude:
26+
- composites
2527
exclude-rules:
2628
- linters:
2729
- dogsled

example/commitpr/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func pushCommit(ref *github.Reference, tree *github.Tree) (err error) {
133133

134134
// Create the commit using the tree.
135135
date := time.Now()
136-
author := &github.CommitAuthor{Date: &date, Name: authorName, Email: authorEmail}
136+
author := &github.CommitAuthor{Date: &github.Timestamp{date}, Name: authorName, Email: authorEmail}
137137
commit := &github.Commit{Author: author, Message: commitMessage, Tree: tree, Parents: []*github.Commit{parent.Commit}}
138138
newCommit, _, err := client.Git.CreateCommit(ctx, *sourceOwner, *sourceRepo, commit)
139139
if err != nil {

github/activity_notifications.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ type Notification struct {
2323
Reason *string `json:"reason,omitempty"`
2424

2525
Unread *bool `json:"unread,omitempty"`
26-
UpdatedAt *time.Time `json:"updated_at,omitempty"`
27-
LastReadAt *time.Time `json:"last_read_at,omitempty"`
26+
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
27+
LastReadAt *Timestamp `json:"last_read_at,omitempty"`
2828
URL *string `json:"url,omitempty"`
2929
}
3030

@@ -97,13 +97,13 @@ func (s *ActivityService) ListRepositoryNotifications(ctx context.Context, owner
9797
}
9898

9999
type markReadOptions struct {
100-
LastReadAt time.Time `json:"last_read_at,omitempty"`
100+
LastReadAt Timestamp `json:"last_read_at,omitempty"`
101101
}
102102

103103
// MarkNotificationsRead marks all notifications up to lastRead as read.
104104
//
105105
// GitHub API docs: https://docs.github.com/en/rest/activity#mark-as-read
106-
func (s *ActivityService) MarkNotificationsRead(ctx context.Context, lastRead time.Time) (*Response, error) {
106+
func (s *ActivityService) MarkNotificationsRead(ctx context.Context, lastRead Timestamp) (*Response, error) {
107107
opts := &markReadOptions{
108108
LastReadAt: lastRead,
109109
}
@@ -119,7 +119,7 @@ func (s *ActivityService) MarkNotificationsRead(ctx context.Context, lastRead ti
119119
// the specified repository as read.
120120
//
121121
// GitHub API docs: https://docs.github.com/en/rest/activity/notifications#mark-repository-notifications-as-read
122-
func (s *ActivityService) MarkRepositoryNotificationsRead(ctx context.Context, owner, repo string, lastRead time.Time) (*Response, error) {
122+
func (s *ActivityService) MarkRepositoryNotificationsRead(ctx context.Context, owner, repo string, lastRead Timestamp) (*Response, error) {
123123
opts := &markReadOptions{
124124
LastReadAt: lastRead,
125125
}

github/activity_notifications_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ func TestActivityService_MarkNotificationsRead(t *testing.T) {
107107
})
108108

109109
ctx := context.Background()
110-
_, err := client.Activity.MarkNotificationsRead(ctx, time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC))
110+
_, err := client.Activity.MarkNotificationsRead(ctx, Timestamp{time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC)})
111111
if err != nil {
112112
t.Errorf("Activity.MarkNotificationsRead returned error: %v", err)
113113
}
114114

115115
const methodName = "MarkNotificationsRead"
116116
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
117-
return client.Activity.MarkNotificationsRead(ctx, time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC))
117+
return client.Activity.MarkNotificationsRead(ctx, Timestamp{time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC)})
118118
})
119119
}
120120

@@ -131,19 +131,19 @@ func TestActivityService_MarkRepositoryNotificationsRead(t *testing.T) {
131131
})
132132

133133
ctx := context.Background()
134-
_, err := client.Activity.MarkRepositoryNotificationsRead(ctx, "o", "r", time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC))
134+
_, err := client.Activity.MarkRepositoryNotificationsRead(ctx, "o", "r", Timestamp{time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC)})
135135
if err != nil {
136136
t.Errorf("Activity.MarkRepositoryNotificationsRead returned error: %v", err)
137137
}
138138

139139
const methodName = "MarkRepositoryNotificationsRead"
140140
testBadOptions(t, methodName, func() (err error) {
141-
_, err = client.Activity.MarkRepositoryNotificationsRead(ctx, "\n", "\n", time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC))
141+
_, err = client.Activity.MarkRepositoryNotificationsRead(ctx, "\n", "\n", Timestamp{time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC)})
142142
return err
143143
})
144144

145145
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
146-
return client.Activity.MarkRepositoryNotificationsRead(ctx, "o", "r", time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC))
146+
return client.Activity.MarkRepositoryNotificationsRead(ctx, "o", "r", Timestamp{time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC)})
147147
})
148148
}
149149

@@ -331,8 +331,8 @@ func TestNotification_Marshal(t *testing.T) {
331331
},
332332
Reason: String("r"),
333333
Unread: Bool(true),
334-
UpdatedAt: &referenceTime,
335-
LastReadAt: &referenceTime,
334+
UpdatedAt: &Timestamp{referenceTime},
335+
LastReadAt: &Timestamp{referenceTime},
336336
URL: String("u"),
337337
}
338338

@@ -383,7 +383,7 @@ func TestMarkReadOptions_Marshal(t *testing.T) {
383383
testJSONMarshal(t, &markReadOptions{}, "{}")
384384

385385
u := &markReadOptions{
386-
LastReadAt: referenceTime,
386+
LastReadAt: Timestamp{referenceTime},
387387
}
388388

389389
want := `{

github/apps.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package github
88
import (
99
"context"
1010
"fmt"
11-
"time"
1211
)
1312

1413
// AppsService provides access to the installation related functions
@@ -36,7 +35,7 @@ type App struct {
3635
// InstallationToken represents an installation token.
3736
type InstallationToken struct {
3837
Token *string `json:"token,omitempty"`
39-
ExpiresAt *time.Time `json:"expires_at,omitempty"`
38+
ExpiresAt *Timestamp `json:"expires_at,omitempty"`
4039
Permissions *InstallationPermissions `json:"permissions,omitempty"`
4140
Repositories []*Repository `json:"repositories,omitempty"`
4241
}

github/apps_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ func TestInstallationToken_Marshal(t *testing.T) {
997997

998998
u := &InstallationToken{
999999
Token: String("t"),
1000-
ExpiresAt: &referenceTime,
1000+
ExpiresAt: &Timestamp{referenceTime},
10011001
Permissions: &InstallationPermissions{
10021002
Actions: String("a"),
10031003
Administration: String("ad"),

github/event.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package github
77

88
import (
99
"encoding/json"
10-
"time"
1110
)
1211

1312
// Event represents a GitHub event.
@@ -18,7 +17,7 @@ type Event struct {
1817
Repo *Repository `json:"repo,omitempty"`
1918
Actor *User `json:"actor,omitempty"`
2019
Org *Organization `json:"org,omitempty"`
21-
CreatedAt *time.Time `json:"created_at,omitempty"`
20+
CreatedAt *Timestamp `json:"created_at,omitempty"`
2221
ID *string `json:"id,omitempty"`
2322
}
2423

github/event_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestEvent_Marshal(t *testing.T) {
7878
MembersCanCreatePublicPages: Bool(false),
7979
MembersCanCreatePrivatePages: Bool(true),
8080
},
81-
CreatedAt: &referenceTime,
81+
CreatedAt: &Timestamp{referenceTime},
8282
ID: String("id"),
8383
}
8484

github/event_types_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4855,8 +4855,8 @@ func TestCommitCommentEvent_Marshal(t *testing.T) {
48554855
Eyes: Int(1),
48564856
URL: String("url"),
48574857
},
4858-
CreatedAt: &referenceTime,
4859-
UpdatedAt: &referenceTime,
4858+
CreatedAt: &Timestamp{referenceTime},
4859+
UpdatedAt: &Timestamp{referenceTime},
48604860
Body: String("b"),
48614861
Path: String("path"),
48624862
Position: Int(1),
@@ -6224,8 +6224,8 @@ func TestPingEvent_Marshal(t *testing.T) {
62246224
Zen: String("z"),
62256225
HookID: Int64(1),
62266226
Hook: &Hook{
6227-
CreatedAt: &referenceTime,
6228-
UpdatedAt: &referenceTime,
6227+
CreatedAt: &Timestamp{referenceTime},
6228+
UpdatedAt: &Timestamp{referenceTime},
62296229
URL: String("url"),
62306230
ID: Int64(1),
62316231
Type: String("t"),
@@ -10698,8 +10698,8 @@ func TestMetaEvent_Marshal(t *testing.T) {
1069810698
Action: String("a"),
1069910699
HookID: Int64(1),
1070010700
Hook: &Hook{
10701-
CreatedAt: &referenceTime,
10702-
UpdatedAt: &referenceTime,
10701+
CreatedAt: &Timestamp{referenceTime},
10702+
UpdatedAt: &Timestamp{referenceTime},
1070310703
URL: String("u"),
1070410704
ID: Int64(1),
1070510705
Type: String("t"),
@@ -11745,7 +11745,7 @@ func TestHeadCommit_Marshal(t *testing.T) {
1174511745
u := &HeadCommit{
1174611746
Message: String("m"),
1174711747
Author: &CommitAuthor{
11748-
Date: &referenceTime,
11748+
Date: &Timestamp{referenceTime},
1174911749
Name: String("n"),
1175011750
Email: String("e"),
1175111751
Login: String("u"),
@@ -11757,7 +11757,7 @@ func TestHeadCommit_Marshal(t *testing.T) {
1175711757
TreeID: String("tid"),
1175811758
Timestamp: &Timestamp{referenceTime},
1175911759
Committer: &CommitAuthor{
11760-
Date: &referenceTime,
11760+
Date: &Timestamp{referenceTime},
1176111761
Name: String("n"),
1176211762
Email: String("e"),
1176311763
Login: String("u"),

github/gists.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ type Gist struct {
2828
HTMLURL *string `json:"html_url,omitempty"`
2929
GitPullURL *string `json:"git_pull_url,omitempty"`
3030
GitPushURL *string `json:"git_push_url,omitempty"`
31-
CreatedAt *time.Time `json:"created_at,omitempty"`
32-
UpdatedAt *time.Time `json:"updated_at,omitempty"`
31+
CreatedAt *Timestamp `json:"created_at,omitempty"`
32+
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
3333
NodeID *string `json:"node_id,omitempty"`
3434
}
3535

0 commit comments

Comments
 (0)