Skip to content

Commit c8fd3f7

Browse files
authored
fix: Address modernize.omitzero issues (#3972)
1 parent 521b62a commit c8fd3f7

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

.golangci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ linters:
9292
ignore-rules:
9393
- analyses # returned by the GitHub API
9494
- cancelled # returned by the GitHub API
95-
modernize:
96-
disable:
97-
- omitzero # TODO: fix
9895
nolintlint:
9996
allow-unused: true
10097
require-specific: true

github/activity_notifications.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ func (s *ActivityService) ListRepositoryNotifications(ctx context.Context, owner
101101
}
102102

103103
type markReadOptions struct {
104-
LastReadAt Timestamp `json:"last_read_at,omitempty"`
104+
LastReadAt Timestamp `json:"last_read_at,omitzero"`
105105
}
106106

107107
// MarkNotificationsRead marks all notifications up to lastRead as read.
108+
// If lastRead is the zero value, all notifications in the repository are marked as read.
108109
//
109110
// GitHub API docs: https://docs.github.com/rest/activity/notifications#mark-notifications-as-read
110111
//
@@ -123,6 +124,7 @@ func (s *ActivityService) MarkNotificationsRead(ctx context.Context, lastRead Ti
123124

124125
// MarkRepositoryNotificationsRead marks all notifications up to lastRead in
125126
// the specified repository as read.
127+
// If lastRead is the zero value, all notifications in the repository are marked as read.
126128
//
127129
// GitHub API docs: https://docs.github.com/rest/activity/notifications#mark-repository-notifications-as-read
128130
//

github/activity_notifications_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,25 @@ func TestActivityService_MarkNotificationsRead(t *testing.T) {
117117
})
118118
}
119119

120+
func TestActivityService_MarkNotificationsRead_EmptyLastReadAt(t *testing.T) {
121+
t.Parallel()
122+
client, mux, _ := setup(t)
123+
124+
mux.HandleFunc("/notifications", func(w http.ResponseWriter, r *http.Request) {
125+
testMethod(t, r, "PUT")
126+
testHeader(t, r, "Content-Type", "application/json")
127+
testBody(t, r, `{}`+"\n")
128+
129+
w.WriteHeader(http.StatusResetContent)
130+
})
131+
132+
ctx := t.Context()
133+
_, err := client.Activity.MarkNotificationsRead(ctx, Timestamp{})
134+
if err != nil {
135+
t.Errorf("Activity.MarkNotificationsRead returned error: %v", err)
136+
}
137+
}
138+
120139
func TestActivityService_MarkRepositoryNotificationsRead(t *testing.T) {
121140
t.Parallel()
122141
client, mux, _ := setup(t)
@@ -146,6 +165,25 @@ func TestActivityService_MarkRepositoryNotificationsRead(t *testing.T) {
146165
})
147166
}
148167

168+
func TestActivityService_MarkRepositoryNotificationsRead_EmptyLastReadAt(t *testing.T) {
169+
t.Parallel()
170+
client, mux, _ := setup(t)
171+
172+
mux.HandleFunc("/repos/o/r/notifications", func(w http.ResponseWriter, r *http.Request) {
173+
testMethod(t, r, "PUT")
174+
testHeader(t, r, "Content-Type", "application/json")
175+
testBody(t, r, `{}`+"\n")
176+
177+
w.WriteHeader(http.StatusResetContent)
178+
})
179+
180+
ctx := t.Context()
181+
_, err := client.Activity.MarkRepositoryNotificationsRead(ctx, "o", "r", Timestamp{})
182+
if err != nil {
183+
t.Errorf("Activity.MarkRepositoryNotificationsRead returned error: %v", err)
184+
}
185+
}
186+
149187
func TestActivityService_GetThread(t *testing.T) {
150188
t.Parallel()
151189
client, mux, _ := setup(t)

github/repos_contents.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type RepositoryContent struct {
4848
// RepositoryContentResponse holds the parsed response from CreateFile, UpdateFile, and DeleteFile.
4949
type RepositoryContentResponse struct {
5050
Content *RepositoryContent `json:"content,omitempty"`
51-
Commit `json:"commit,omitempty"`
51+
Commit `json:"commit"`
5252
}
5353

5454
// RepositoryContentFileOptions specifies optional parameters for CreateFile, UpdateFile, and DeleteFile.

0 commit comments

Comments
 (0)