Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ linters:
- staticcheck
- ineffassign
- unused
issues:
issues:
exclude:
- composites
Comment on lines +24 to +26
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the examples project was having a type error, it was fixed by using github.Timestamp, which caused another error in go vet relating to unkeyed fields. excluding composites fixes the error

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious what we were missing by excluding composites, I ran across these issues:

in case anyone in the future finds this and wonders about it.

exclude-rules:
- linters:
- dogsled
Expand Down
2 changes: 1 addition & 1 deletion example/commitpr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func pushCommit(ref *github.Reference, tree *github.Tree) (err error) {

// Create the commit using the tree.
date := time.Now()
author := &github.CommitAuthor{Date: &date, Name: authorName, Email: authorEmail}
author := &github.CommitAuthor{Date: &github.Timestamp{date}, Name: authorName, Email: authorEmail}
commit := &github.Commit{Author: author, Message: commitMessage, Tree: tree, Parents: []*github.Commit{parent.Commit}}
newCommit, _, err := client.Git.CreateCommit(ctx, *sourceOwner, *sourceRepo, commit)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions github/activity_notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ type Notification struct {
Reason *string `json:"reason,omitempty"`

Unread *bool `json:"unread,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
LastReadAt *time.Time `json:"last_read_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
LastReadAt *Timestamp `json:"last_read_at,omitempty"`
URL *string `json:"url,omitempty"`
}

Expand Down Expand Up @@ -97,13 +97,13 @@ func (s *ActivityService) ListRepositoryNotifications(ctx context.Context, owner
}

type markReadOptions struct {
LastReadAt time.Time `json:"last_read_at,omitempty"`
LastReadAt Timestamp `json:"last_read_at,omitempty"`
}

// MarkNotificationsRead marks all notifications up to lastRead as read.
//
// GitHub API docs: https://docs.github.com/en/rest/activity#mark-as-read
func (s *ActivityService) MarkNotificationsRead(ctx context.Context, lastRead time.Time) (*Response, error) {
func (s *ActivityService) MarkNotificationsRead(ctx context.Context, lastRead Timestamp) (*Response, error) {
opts := &markReadOptions{
LastReadAt: lastRead,
}
Expand All @@ -119,7 +119,7 @@ func (s *ActivityService) MarkNotificationsRead(ctx context.Context, lastRead ti
// the specified repository as read.
//
// GitHub API docs: https://docs.github.com/en/rest/activity/notifications#mark-repository-notifications-as-read
func (s *ActivityService) MarkRepositoryNotificationsRead(ctx context.Context, owner, repo string, lastRead time.Time) (*Response, error) {
func (s *ActivityService) MarkRepositoryNotificationsRead(ctx context.Context, owner, repo string, lastRead Timestamp) (*Response, error) {
opts := &markReadOptions{
LastReadAt: lastRead,
}
Expand Down
16 changes: 8 additions & 8 deletions github/activity_notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ func TestActivityService_MarkNotificationsRead(t *testing.T) {
})

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

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

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

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

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

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

Expand Down Expand Up @@ -331,8 +331,8 @@ func TestNotification_Marshal(t *testing.T) {
},
Reason: String("r"),
Unread: Bool(true),
UpdatedAt: &referenceTime,
LastReadAt: &referenceTime,
UpdatedAt: &Timestamp{referenceTime},
LastReadAt: &Timestamp{referenceTime},
URL: String("u"),
}

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

u := &markReadOptions{
LastReadAt: referenceTime,
LastReadAt: Timestamp{referenceTime},
}

want := `{
Expand Down
3 changes: 1 addition & 2 deletions github/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package github
import (
"context"
"fmt"
"time"
)

// AppsService provides access to the installation related functions
Expand Down Expand Up @@ -36,7 +35,7 @@ type App struct {
// InstallationToken represents an installation token.
type InstallationToken struct {
Token *string `json:"token,omitempty"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
ExpiresAt *Timestamp `json:"expires_at,omitempty"`
Permissions *InstallationPermissions `json:"permissions,omitempty"`
Repositories []*Repository `json:"repositories,omitempty"`
}
Expand Down
2 changes: 1 addition & 1 deletion github/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ func TestInstallationToken_Marshal(t *testing.T) {

u := &InstallationToken{
Token: String("t"),
ExpiresAt: &referenceTime,
ExpiresAt: &Timestamp{referenceTime},
Permissions: &InstallationPermissions{
Actions: String("a"),
Administration: String("ad"),
Expand Down
3 changes: 1 addition & 2 deletions github/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package github

import (
"encoding/json"
"time"
)

// Event represents a GitHub event.
Expand All @@ -18,7 +17,7 @@ type Event struct {
Repo *Repository `json:"repo,omitempty"`
Actor *User `json:"actor,omitempty"`
Org *Organization `json:"org,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
ID *string `json:"id,omitempty"`
}

Expand Down
2 changes: 1 addition & 1 deletion github/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestEvent_Marshal(t *testing.T) {
MembersCanCreatePublicPages: Bool(false),
MembersCanCreatePrivatePages: Bool(true),
},
CreatedAt: &referenceTime,
CreatedAt: &Timestamp{referenceTime},
ID: String("id"),
}

Expand Down
16 changes: 8 additions & 8 deletions github/event_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4855,8 +4855,8 @@ func TestCommitCommentEvent_Marshal(t *testing.T) {
Eyes: Int(1),
URL: String("url"),
},
CreatedAt: &referenceTime,
UpdatedAt: &referenceTime,
CreatedAt: &Timestamp{referenceTime},
UpdatedAt: &Timestamp{referenceTime},
Body: String("b"),
Path: String("path"),
Position: Int(1),
Expand Down Expand Up @@ -6224,8 +6224,8 @@ func TestPingEvent_Marshal(t *testing.T) {
Zen: String("z"),
HookID: Int64(1),
Hook: &Hook{
CreatedAt: &referenceTime,
UpdatedAt: &referenceTime,
CreatedAt: &Timestamp{referenceTime},
UpdatedAt: &Timestamp{referenceTime},
URL: String("url"),
ID: Int64(1),
Type: String("t"),
Expand Down Expand Up @@ -10698,8 +10698,8 @@ func TestMetaEvent_Marshal(t *testing.T) {
Action: String("a"),
HookID: Int64(1),
Hook: &Hook{
CreatedAt: &referenceTime,
UpdatedAt: &referenceTime,
CreatedAt: &Timestamp{referenceTime},
UpdatedAt: &Timestamp{referenceTime},
URL: String("u"),
ID: Int64(1),
Type: String("t"),
Expand Down Expand Up @@ -11745,7 +11745,7 @@ func TestHeadCommit_Marshal(t *testing.T) {
u := &HeadCommit{
Message: String("m"),
Author: &CommitAuthor{
Date: &referenceTime,
Date: &Timestamp{referenceTime},
Name: String("n"),
Email: String("e"),
Login: String("u"),
Expand All @@ -11757,7 +11757,7 @@ func TestHeadCommit_Marshal(t *testing.T) {
TreeID: String("tid"),
Timestamp: &Timestamp{referenceTime},
Committer: &CommitAuthor{
Date: &referenceTime,
Date: &Timestamp{referenceTime},
Name: String("n"),
Email: String("e"),
Login: String("u"),
Expand Down
4 changes: 2 additions & 2 deletions github/gists.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ type Gist struct {
HTMLURL *string `json:"html_url,omitempty"`
GitPullURL *string `json:"git_pull_url,omitempty"`
GitPushURL *string `json:"git_push_url,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
NodeID *string `json:"node_id,omitempty"`
}

Expand Down
3 changes: 1 addition & 2 deletions github/gists_comments.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package github
import (
"context"
"fmt"
"time"
)

// GistComment represents a Gist comment.
Expand All @@ -17,7 +16,7 @@ type GistComment struct {
URL *string `json:"url,omitempty"`
Body *string `json:"body,omitempty"`
User *User `json:"user,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
}

func (g GistComment) String() string {
Expand Down
2 changes: 1 addition & 1 deletion github/gists_comments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestGistComments_Marshal(t *testing.T) {
CreatedAt: &Timestamp{referenceTime},
URL: String("u"),
},
CreatedAt: &createdAt,
CreatedAt: &Timestamp{createdAt},
}

want := `{
Expand Down
4 changes: 2 additions & 2 deletions github/gists_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func TestGist_Marshal(t *testing.T) {
HTMLURL: String("html-url"),
GitPullURL: String("gitpull-url"),
GitPushURL: String("gitpush-url"),
CreatedAt: &createdAt,
UpdatedAt: &updatedAt,
CreatedAt: &Timestamp{createdAt},
UpdatedAt: &Timestamp{updatedAt},
NodeID: String("node"),
}

Expand Down
3 changes: 1 addition & 2 deletions github/git_commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"errors"
"fmt"
"strings"
"time"

"golang.org/x/crypto/openpgp"
)
Expand Down Expand Up @@ -56,7 +55,7 @@ func (c Commit) String() string {
// CommitAuthor represents the author or committer of a commit. The commit
// author may not correspond to a GitHub User.
type CommitAuthor struct {
Date *time.Time `json:"date,omitempty"`
Date *Timestamp `json:"date,omitempty"`
Name *string `json:"name,omitempty"`
Email *string `json:"email,omitempty"`

Expand Down
24 changes: 12 additions & 12 deletions github/git_commits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ func TestCommit_Marshal(t *testing.T) {
u := &Commit{
SHA: String("s"),
Author: &CommitAuthor{
Date: &referenceTime,
Date: &Timestamp{referenceTime},
Name: String("n"),
Email: String("e"),
Login: String("u"),
},
Committer: &CommitAuthor{
Date: &referenceTime,
Date: &Timestamp{referenceTime},
Name: String("n"),
Email: String("e"),
Login: String("u"),
Expand Down Expand Up @@ -313,7 +313,7 @@ func TestGitService_CreateSignedCommitWithKey(t *testing.T) {
author := CommitAuthor{
Name: String("go-github"),
Email: String("go-github@github.com"),
Date: &date,
Date: &Timestamp{date},
}
input := &Commit{
Message: String("Commit Message."),
Expand Down Expand Up @@ -417,7 +417,7 @@ func TestGitService_createSignature_invalidKey(t *testing.T) {
Author: &CommitAuthor{
Name: String("go-github"),
Email: String("go-github@github.com"),
Date: &date,
Date: &Timestamp{date},
},
})

Expand All @@ -442,7 +442,7 @@ func TestGitService_createSignatureMessage_nilMessage(t *testing.T) {
Author: &CommitAuthor{
Name: String("go-github"),
Email: String("go-github@github.com"),
Date: &date,
Date: &Timestamp{date},
},
})
if err == nil {
Expand All @@ -459,7 +459,7 @@ func TestGitService_createSignatureMessage_emptyMessage(t *testing.T) {
Author: &CommitAuthor{
Name: String("go-github"),
Email: String("go-github@github.com"),
Date: &date,
Date: &Timestamp{date},
},
})
if err == nil {
Expand Down Expand Up @@ -487,7 +487,7 @@ func TestGitService_createSignatureMessage_withoutTree(t *testing.T) {
Author: &CommitAuthor{
Name: String("go-github"),
Email: String("go-github@github.com"),
Date: &date,
Date: &Timestamp{date},
},
})
expected := `parent p
Expand All @@ -509,12 +509,12 @@ func TestGitService_createSignatureMessage_withoutCommitter(t *testing.T) {
Author: &CommitAuthor{
Name: String("go-github"),
Email: String("go-github@github.com"),
Date: &date,
Date: &Timestamp{date},
},
Committer: &CommitAuthor{
Name: String("foo"),
Email: String("foo@bar.com"),
Date: &date,
Date: &Timestamp{date},
},
})
expected := `parent p
Expand Down Expand Up @@ -619,7 +619,7 @@ func TestCommitAuthor_Marshal(t *testing.T) {
testJSONMarshal(t, &CommitAuthor{}, "{}")

u := &CommitAuthor{
Date: &referenceTime,
Date: &Timestamp{referenceTime},
Name: String("name"),
Email: String("email"),
Login: String("login"),
Expand All @@ -640,13 +640,13 @@ func TestCreateCommit_Marshal(t *testing.T) {

u := &createCommit{
Author: &CommitAuthor{
Date: &referenceTime,
Date: &Timestamp{referenceTime},
Name: String("name"),
Email: String("email"),
Login: String("login"),
},
Committer: &CommitAuthor{
Date: &referenceTime,
Date: &Timestamp{referenceTime},
Name: String("name"),
Email: String("email"),
Login: String("login"),
Expand Down
Loading