diff --git a/.golangci.yml b/.golangci.yml index 80bd856ccfb..12d08ec69f1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -92,9 +92,6 @@ linters: ignore-rules: - analyses # returned by the GitHub API - cancelled # returned by the GitHub API - modernize: - disable: - - omitzero # TODO: fix nolintlint: allow-unused: true require-specific: true diff --git a/github/activity_notifications.go b/github/activity_notifications.go index e712323ed43..feb38ea3391 100644 --- a/github/activity_notifications.go +++ b/github/activity_notifications.go @@ -101,10 +101,11 @@ func (s *ActivityService) ListRepositoryNotifications(ctx context.Context, owner } type markReadOptions struct { - LastReadAt Timestamp `json:"last_read_at,omitempty"` + LastReadAt Timestamp `json:"last_read_at,omitzero"` } // MarkNotificationsRead marks all notifications up to lastRead as read. +// If lastRead is the zero value, all notifications in the repository are marked as read. // // GitHub API docs: https://docs.github.com/rest/activity/notifications#mark-notifications-as-read // @@ -123,6 +124,7 @@ func (s *ActivityService) MarkNotificationsRead(ctx context.Context, lastRead Ti // MarkRepositoryNotificationsRead marks all notifications up to lastRead in // the specified repository as read. +// If lastRead is the zero value, all notifications in the repository are marked as read. // // GitHub API docs: https://docs.github.com/rest/activity/notifications#mark-repository-notifications-as-read // diff --git a/github/activity_notifications_test.go b/github/activity_notifications_test.go index 7744f1e6a3d..b0d25645ab2 100644 --- a/github/activity_notifications_test.go +++ b/github/activity_notifications_test.go @@ -117,6 +117,25 @@ func TestActivityService_MarkNotificationsRead(t *testing.T) { }) } +func TestActivityService_MarkNotificationsRead_EmptyLastReadAt(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/notifications", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PUT") + testHeader(t, r, "Content-Type", "application/json") + testBody(t, r, `{}`+"\n") + + w.WriteHeader(http.StatusResetContent) + }) + + ctx := t.Context() + _, err := client.Activity.MarkNotificationsRead(ctx, Timestamp{}) + if err != nil { + t.Errorf("Activity.MarkNotificationsRead returned error: %v", err) + } +} + func TestActivityService_MarkRepositoryNotificationsRead(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -146,6 +165,25 @@ func TestActivityService_MarkRepositoryNotificationsRead(t *testing.T) { }) } +func TestActivityService_MarkRepositoryNotificationsRead_EmptyLastReadAt(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/repos/o/r/notifications", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PUT") + testHeader(t, r, "Content-Type", "application/json") + testBody(t, r, `{}`+"\n") + + w.WriteHeader(http.StatusResetContent) + }) + + ctx := t.Context() + _, err := client.Activity.MarkRepositoryNotificationsRead(ctx, "o", "r", Timestamp{}) + if err != nil { + t.Errorf("Activity.MarkRepositoryNotificationsRead returned error: %v", err) + } +} + func TestActivityService_GetThread(t *testing.T) { t.Parallel() client, mux, _ := setup(t) diff --git a/github/repos_contents.go b/github/repos_contents.go index 6090c8b9f92..73321e260d9 100644 --- a/github/repos_contents.go +++ b/github/repos_contents.go @@ -48,7 +48,7 @@ type RepositoryContent struct { // RepositoryContentResponse holds the parsed response from CreateFile, UpdateFile, and DeleteFile. type RepositoryContentResponse struct { Content *RepositoryContent `json:"content,omitempty"` - Commit `json:"commit,omitempty"` + Commit `json:"commit"` } // RepositoryContentFileOptions specifies optional parameters for CreateFile, UpdateFile, and DeleteFile.