From 1d644d9736e19f39a30859611eaf51c8ca94d97e Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Thu, 5 Feb 2026 20:34:09 +0200 Subject: [PATCH] fix: Address 'modernize.omitzero' issues --- .golangci.yml | 5 +--- github/actions_hosted_runners.go | 2 +- github/activity_notifications.go | 4 ++- github/activity_notifications_test.go | 38 +++++++++++++++++++++++++++ github/repos_contents.go | 2 +- 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index f52016332d2..cd3b497f6ca 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 @@ -146,7 +143,7 @@ linters: - "all" - "-QF1008" # allow embedded field in selector unparam: - check-exported: true + check-exported: true usetesting: context-background: true context-todo: true diff --git a/github/actions_hosted_runners.go b/github/actions_hosted_runners.go index 207b755fc30..e10fb36a368 100644 --- a/github/actions_hosted_runners.go +++ b/github/actions_hosted_runners.go @@ -93,7 +93,7 @@ type HostedRunnerImage struct { // HostedRunnerRequest specifies body parameters to Hosted Runner configuration. type HostedRunnerRequest struct { Name string `json:"name,omitempty"` - Image HostedRunnerImage `json:"image,omitempty"` + Image HostedRunnerImage `json:"image"` RunnerGroupID int64 `json:"runner_group_id,omitempty"` Size string `json:"size,omitempty"` MaximumRunners int64 `json:"maximum_runners,omitempty"` 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.