diff --git a/.golangci.yml b/.golangci.yml index d45b62f602b..fbcff90b9c4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -106,6 +106,7 @@ linters-settings: - name: unexported-naming - name: unexported-return - name: unreachable-code + - name: use-any - name: var-declaration - name: var-naming issues: diff --git a/github/actions_secrets.go b/github/actions_secrets.go index cba85c10042..ff09b4ee588 100644 --- a/github/actions_secrets.go +++ b/github/actions_secrets.go @@ -23,8 +23,8 @@ type PublicKey struct { // do not error out when unmarshaling. func (p *PublicKey) UnmarshalJSON(data []byte) error { var pk struct { - KeyID interface{} `json:"key_id"` - Key *string `json:"key"` + KeyID any `json:"key_id"` + Key *string `json:"key"` } if err := json.Unmarshal(data, &pk); err != nil { diff --git a/github/actions_workflows.go b/github/actions_workflows.go index 0214e6abff2..4d9df69eb0d 100644 --- a/github/actions_workflows.go +++ b/github/actions_workflows.go @@ -53,7 +53,7 @@ type CreateWorkflowDispatchEventRequest struct { // Inputs represents input keys and values configured in the workflow file. // The maximum number of properties is 10. // Default: Any default properties configured in the workflow file will be used when `inputs` are omitted. - Inputs map[string]interface{} `json:"inputs,omitempty"` + Inputs map[string]any `json:"inputs,omitempty"` } // ListWorkflows lists all workflows in a repository. diff --git a/github/actions_workflows_test.go b/github/actions_workflows_test.go index baaae7bfb9d..46e904b3747 100644 --- a/github/actions_workflows_test.go +++ b/github/actions_workflows_test.go @@ -237,7 +237,7 @@ func TestActionsService_CreateWorkflowDispatchEventByID(t *testing.T) { event := CreateWorkflowDispatchEventRequest{ Ref: "d4cfb6e7", - Inputs: map[string]interface{}{ + Inputs: map[string]any{ "key": "value", }, } @@ -281,7 +281,7 @@ func TestActionsService_CreateWorkflowDispatchEventByFileName(t *testing.T) { event := CreateWorkflowDispatchEventRequest{ Ref: "d4cfb6e7", - Inputs: map[string]interface{}{ + Inputs: map[string]any{ "key": "value", }, } @@ -618,7 +618,7 @@ func TestCreateWorkflowDispatchEventRequest_Marshal(t *testing.T) { t.Parallel() testJSONMarshal(t, &CreateWorkflowDispatchEventRequest{}, "{}") - inputs := make(map[string]interface{}, 0) + inputs := make(map[string]any, 0) inputs["key"] = "value" u := &CreateWorkflowDispatchEventRequest{ diff --git a/github/activity_events_test.go b/github/activity_events_test.go index cf38b4b6799..3a58588c32c 100644 --- a/github/activity_events_test.go +++ b/github/activity_events_test.go @@ -437,7 +437,7 @@ func TestActivityService_EventParsePayload_typed(t *testing.T) { } // TestEvent_Payload_untyped checks that unrecognized events are parsed to an -// interface{} value (instead of being discarded or throwing an error), for +// any value (instead of being discarded or throwing an error), for // forward compatibility with new event types. func TestActivityService_EventParsePayload_untyped(t *testing.T) { t.Parallel() @@ -447,7 +447,7 @@ func TestActivityService_EventParsePayload_untyped(t *testing.T) { t.Fatalf("Unmarshal Event returned error: %v", err) } - want := map[string]interface{}{"field": "val"} + want := map[string]any{"field": "val"} got, err := event.ParsePayload() if err != nil { t.Fatalf("ParsePayload returned unexpected error: %v", err) diff --git a/github/copilot.go b/github/copilot.go index b9adfcb4eec..bed83536b41 100644 --- a/github/copilot.go +++ b/github/copilot.go @@ -46,14 +46,14 @@ type ListCopilotSeatsResponse struct { // CopilotSeatDetails represents the details of a Copilot for Business seat. type CopilotSeatDetails struct { // Assignee can either be a User, Team, or Organization. - Assignee interface{} `json:"assignee"` - AssigningTeam *Team `json:"assigning_team,omitempty"` - PendingCancellationDate *string `json:"pending_cancellation_date,omitempty"` - LastActivityAt *Timestamp `json:"last_activity_at,omitempty"` - LastActivityEditor *string `json:"last_activity_editor,omitempty"` - CreatedAt *Timestamp `json:"created_at"` - UpdatedAt *Timestamp `json:"updated_at,omitempty"` - PlanType *string `json:"plan_type,omitempty"` + Assignee any `json:"assignee"` + AssigningTeam *Team `json:"assigning_team,omitempty"` + PendingCancellationDate *string `json:"pending_cancellation_date,omitempty"` + LastActivityAt *Timestamp `json:"last_activity_at,omitempty"` + LastActivityEditor *string `json:"last_activity_editor,omitempty"` + CreatedAt *Timestamp `json:"created_at"` + UpdatedAt *Timestamp `json:"updated_at,omitempty"` + PlanType *string `json:"plan_type,omitempty"` } // SeatAssignments represents the number of seats assigned. @@ -203,7 +203,7 @@ func (cp *CopilotSeatDetails) UnmarshalJSON(data []byte) error { cp.PlanType = seatDetail.PlanType switch v := seatDetail.Assignee.(type) { - case map[string]interface{}: + case map[string]any: jsonData, err := json.Marshal(seatDetail.Assignee) if err != nil { return err diff --git a/github/enterprise_audit_log_test.go b/github/enterprise_audit_log_test.go index bc2369090fb..5148e8eabb2 100644 --- a/github/enterprise_audit_log_test.go +++ b/github/enterprise_audit_log_test.go @@ -61,7 +61,7 @@ func TestEnterpriseService_GetAuditLog(t *testing.T) { Actor: Ptr("testactor"), CreatedAt: &Timestamp{timestamp}, Org: Ptr("o"), - AdditionalFields: map[string]interface{}{ + AdditionalFields: map[string]any{ "completed_at": "2021-03-07T00:35:08.000Z", "conclusion": "success", "event": "schedule", diff --git a/github/event.go b/github/event.go index e98606bce5d..446db7fa01e 100644 --- a/github/event.go +++ b/github/event.go @@ -27,7 +27,7 @@ func (e Event) String() string { // ParsePayload parses the event payload. For recognized event types, // a value of the corresponding struct type will be returned. -func (e *Event) ParsePayload() (interface{}, error) { +func (e *Event) ParsePayload() (any, error) { // It would be nice if e.Type were the snake_case name of the event, // but the existing interface uses the struct name instead. payload := EventForType(typeToMessageMapping[e.GetType()]) @@ -44,7 +44,7 @@ func (e *Event) ParsePayload() (interface{}, error) { // // Deprecated: Use ParsePayload instead, which returns an error // rather than panics if JSON unmarshaling raw payload fails. -func (e *Event) Payload() (payload interface{}) { +func (e *Event) Payload() (payload any) { var err error payload, err = e.ParsePayload() if err != nil { diff --git a/github/event_test.go b/github/event_test.go index bc37e12f563..08fc56ad063 100644 --- a/github/event_test.go +++ b/github/event_test.go @@ -49,7 +49,7 @@ func TestEvent_Marshal(t *testing.T) { t.Parallel() testJSONMarshal(t, &Event{}, "{}") - l := make(map[string]interface{}) + l := make(map[string]any) l["key"] = "value" jsonMsg, _ := json.Marshal(&l) diff --git a/github/event_types.go b/github/event_types.go index b5369865608..3aa151e5ca7 100644 --- a/github/event_types.go +++ b/github/event_types.go @@ -1400,44 +1400,44 @@ func (h HeadCommit) String() string { // PushEventRepository represents the repo object in a PushEvent payload. type PushEventRepository struct { - ID *int64 `json:"id,omitempty"` - NodeID *string `json:"node_id,omitempty"` - Name *string `json:"name,omitempty"` - FullName *string `json:"full_name,omitempty"` - Owner *User `json:"owner,omitempty"` - Private *bool `json:"private,omitempty"` - Description *string `json:"description,omitempty"` - Fork *bool `json:"fork,omitempty"` - CreatedAt *Timestamp `json:"created_at,omitempty"` - PushedAt *Timestamp `json:"pushed_at,omitempty"` - UpdatedAt *Timestamp `json:"updated_at,omitempty"` - Homepage *string `json:"homepage,omitempty"` - PullsURL *string `json:"pulls_url,omitempty"` - Size *int `json:"size,omitempty"` - StargazersCount *int `json:"stargazers_count,omitempty"` - WatchersCount *int `json:"watchers_count,omitempty"` - Language *string `json:"language,omitempty"` - HasIssues *bool `json:"has_issues,omitempty"` - HasDownloads *bool `json:"has_downloads,omitempty"` - HasWiki *bool `json:"has_wiki,omitempty"` - HasPages *bool `json:"has_pages,omitempty"` - ForksCount *int `json:"forks_count,omitempty"` - Archived *bool `json:"archived,omitempty"` - Disabled *bool `json:"disabled,omitempty"` - OpenIssuesCount *int `json:"open_issues_count,omitempty"` - DefaultBranch *string `json:"default_branch,omitempty"` - MasterBranch *string `json:"master_branch,omitempty"` - Organization *string `json:"organization,omitempty"` - URL *string `json:"url,omitempty"` - ArchiveURL *string `json:"archive_url,omitempty"` - HTMLURL *string `json:"html_url,omitempty"` - StatusesURL *string `json:"statuses_url,omitempty"` - GitURL *string `json:"git_url,omitempty"` - SSHURL *string `json:"ssh_url,omitempty"` - CloneURL *string `json:"clone_url,omitempty"` - SVNURL *string `json:"svn_url,omitempty"` - Topics []string `json:"topics,omitempty"` - CustomProperties map[string]interface{} `json:"custom_properties,omitempty"` + ID *int64 `json:"id,omitempty"` + NodeID *string `json:"node_id,omitempty"` + Name *string `json:"name,omitempty"` + FullName *string `json:"full_name,omitempty"` + Owner *User `json:"owner,omitempty"` + Private *bool `json:"private,omitempty"` + Description *string `json:"description,omitempty"` + Fork *bool `json:"fork,omitempty"` + CreatedAt *Timestamp `json:"created_at,omitempty"` + PushedAt *Timestamp `json:"pushed_at,omitempty"` + UpdatedAt *Timestamp `json:"updated_at,omitempty"` + Homepage *string `json:"homepage,omitempty"` + PullsURL *string `json:"pulls_url,omitempty"` + Size *int `json:"size,omitempty"` + StargazersCount *int `json:"stargazers_count,omitempty"` + WatchersCount *int `json:"watchers_count,omitempty"` + Language *string `json:"language,omitempty"` + HasIssues *bool `json:"has_issues,omitempty"` + HasDownloads *bool `json:"has_downloads,omitempty"` + HasWiki *bool `json:"has_wiki,omitempty"` + HasPages *bool `json:"has_pages,omitempty"` + ForksCount *int `json:"forks_count,omitempty"` + Archived *bool `json:"archived,omitempty"` + Disabled *bool `json:"disabled,omitempty"` + OpenIssuesCount *int `json:"open_issues_count,omitempty"` + DefaultBranch *string `json:"default_branch,omitempty"` + MasterBranch *string `json:"master_branch,omitempty"` + Organization *string `json:"organization,omitempty"` + URL *string `json:"url,omitempty"` + ArchiveURL *string `json:"archive_url,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` + StatusesURL *string `json:"statuses_url,omitempty"` + GitURL *string `json:"git_url,omitempty"` + SSHURL *string `json:"ssh_url,omitempty"` + CloneURL *string `json:"clone_url,omitempty"` + SVNURL *string `json:"svn_url,omitempty"` + Topics []string `json:"topics,omitempty"` + CustomProperties map[string]any `json:"custom_properties,omitempty"` } // PushEventRepoOwner is a basic representation of user/org in a PushEvent payload. diff --git a/github/event_types_test.go b/github/event_types_test.go index cc2a4e1aad8..ea8909db295 100644 --- a/github/event_types_test.go +++ b/github/event_types_test.go @@ -5644,7 +5644,7 @@ func TestDeploymentEvent_Marshal(t *testing.T) { t.Parallel() testJSONMarshal(t, &DeploymentEvent{}, "{}") - l := make(map[string]interface{}) + l := make(map[string]any) l["key"] = "value" jsonMsg, _ := json.Marshal(&l) @@ -6114,7 +6114,7 @@ func TestDeploymentProtectionRuleEvent_Marshal(t *testing.T) { t.Parallel() testJSONMarshal(t, &DeploymentProtectionRuleEvent{}, "{}") - l := make(map[string]interface{}) + l := make(map[string]any) l["key"] = "value" jsonMsg, _ := json.Marshal(&l) @@ -7099,7 +7099,7 @@ func TestDeploymentStatusEvent_Marshal(t *testing.T) { t.Parallel() testJSONMarshal(t, &DeploymentStatusEvent{}, "{}") - l := make(map[string]interface{}) + l := make(map[string]any) l["key"] = "value" jsonMsg, _ := json.Marshal(&l) @@ -8399,7 +8399,7 @@ func TestPingEvent_Marshal(t *testing.T) { t.Parallel() testJSONMarshal(t, &PingEvent{}, "{}") - l := make(map[string]interface{}) + l := make(map[string]any) l["key"] = "value" hookConfig := new(HookConfig) @@ -8773,7 +8773,7 @@ func TestRepositoryDispatchEvent_Marshal(t *testing.T) { t.Parallel() testJSONMarshal(t, &RepositoryDispatchEvent{}, "{}") - l := make(map[string]interface{}) + l := make(map[string]any) l["key"] = "value" jsonMsg, _ := json.Marshal(&l) @@ -11978,7 +11978,7 @@ func TestWorkflowDispatchEvent_Marshal(t *testing.T) { t.Parallel() testJSONMarshal(t, &WorkflowDispatchEvent{}, "{}") - i := make(map[string]interface{}) + i := make(map[string]any) i["key"] = "value" jsonMsg, _ := json.Marshal(i) @@ -13343,7 +13343,7 @@ func TestMetaEvent_Marshal(t *testing.T) { t.Parallel() testJSONMarshal(t, &MetaEvent{}, "{}") - v := make(map[string]interface{}) + v := make(map[string]any) v["a"] = "b" hookConfig := &HookConfig{ ContentType: Ptr("json"), diff --git a/github/gen-accessors.go b/github/gen-accessors.go index 66450fb7ae9..896734b4c51 100644 --- a/github/gen-accessors.go +++ b/github/gen-accessors.go @@ -59,7 +59,7 @@ var ( } ) -func logf(fmt string, args ...interface{}) { +func logf(fmt string, args ...any) { if *verbose { log.Printf(fmt, args...) } diff --git a/github/gen-stringify-test.go b/github/gen-stringify-test.go index 6c887a0ca2c..6b09e80c3f5 100644 --- a/github/gen-stringify-test.go +++ b/github/gen-stringify-test.go @@ -72,6 +72,8 @@ var ( return `[""]` case "[]Scope{ScopeNone}": return `["(no scope)"]` + case "[]any{nil}": + return "[]" } log.Fatalf("Unhandled zero value: %q", v) return "" @@ -311,6 +313,8 @@ func (t *templateData) addIdentSlice(x *ast.Ident, receiverType, fieldName strin zeroValue = "[]bool{false}" case "Scope": zeroValue = "[]Scope{ScopeNone}" + case "any": + zeroValue = "[]any{nil}" // case "Timestamp": // zeroValue = "&Timestamp{}" default: @@ -377,7 +381,7 @@ func newStructField(receiverType, fieldName, fieldType, zeroValue string, namedS } } -func logf(fmt string, args ...interface{}) { +func logf(fmt string, args ...any) { if *verbose { log.Printf(fmt, args...) } diff --git a/github/git_trees.go b/github/git_trees.go index b8eed58e136..4396dd0160b 100644 --- a/github/git_trees.go +++ b/github/git_trees.go @@ -118,8 +118,8 @@ func (s *GitService) GetTree(ctx context.Context, owner string, repo string, sha // createTree represents the body of a CreateTree request. type createTree struct { - BaseTree string `json:"base_tree,omitempty"` - Entries []interface{} `json:"tree"` + BaseTree string `json:"base_tree,omitempty"` + Entries []any `json:"tree"` } // CreateTree creates a new tree in a repository. If both a tree and a nested @@ -132,7 +132,7 @@ type createTree struct { func (s *GitService) CreateTree(ctx context.Context, owner string, repo string, baseTree string, entries []*TreeEntry) (*Tree, *Response, error) { u := fmt.Sprintf("repos/%v/%v/git/trees", owner, repo) - newEntries := make([]interface{}, 0, len(entries)) + newEntries := make([]any, 0, len(entries)) for _, entry := range entries { if entry.Content == nil && entry.SHA == nil { newEntries = append(newEntries, treeEntryWithFileDelete{ diff --git a/github/git_trees_test.go b/github/git_trees_test.go index 0c264470ce2..5d12f3068f6 100644 --- a/github/git_trees_test.go +++ b/github/git_trees_test.go @@ -441,7 +441,7 @@ func TestCreateTree_Marshal(t *testing.T) { u := &createTree{ BaseTree: "bt", - Entries: []interface{}{"e"}, + Entries: []any{"e"}, } want := `{ diff --git a/github/github-accessors.go b/github/github-accessors.go index 307d6e339d3..3193aa9943f 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -1110,6 +1110,14 @@ func (a *AuditEntry) GetActorLocation() *ActorLocation { return a.ActorLocation } +// GetAdditionalFields returns the AdditionalFields map if it's non-nil, an empty map otherwise. +func (a *AuditEntry) GetAdditionalFields() map[string]any { + if a == nil || a.AdditionalFields == nil { + return map[string]any{} + } + return a.AdditionalFields +} + // GetBusiness returns the Business field if it's non-nil, zero value otherwise. func (a *AuditEntry) GetBusiness() string { if a == nil || a.Business == nil { @@ -1134,6 +1142,14 @@ func (a *AuditEntry) GetCreatedAt() Timestamp { return *a.CreatedAt } +// GetData returns the Data map if it's non-nil, an empty map otherwise. +func (a *AuditEntry) GetData() map[string]any { + if a == nil || a.Data == nil { + return map[string]any{} + } + return a.Data +} + // GetDocumentID returns the DocumentID field if it's non-nil, zero value otherwise. func (a *AuditEntry) GetDocumentID() string { if a == nil || a.DocumentID == nil { @@ -6038,6 +6054,14 @@ func (c *CreateUserRequest) GetSuspended() bool { return *c.Suspended } +// GetInputs returns the Inputs map if it's non-nil, an empty map otherwise. +func (c *CreateWorkflowDispatchEventRequest) GetInputs() map[string]any { + if c == nil || c.Inputs == nil { + return map[string]any{} + } + return c.Inputs +} + // GetCreated returns the Created field if it's non-nil, zero value otherwise. func (c *CreationInfo) GetCreated() Timestamp { if c == nil || c.Created == nil { @@ -9942,6 +9966,14 @@ func (h *Hook) GetID() int64 { return *h.ID } +// GetLastResponse returns the LastResponse map if it's non-nil, an empty map otherwise. +func (h *Hook) GetLastResponse() map[string]any { + if h == nil || h.LastResponse == nil { + return map[string]any{} + } + return h.LastResponse +} + // GetName returns the Name field if it's non-nil, zero value otherwise. func (h *Hook) GetName() string { if h == nil || h.Name == nil { @@ -20342,6 +20374,14 @@ func (p *PushEventRepository) GetCreatedAt() Timestamp { return *p.CreatedAt } +// GetCustomProperties returns the CustomProperties map if it's non-nil, an empty map otherwise. +func (p *PushEventRepository) GetCustomProperties() map[string]any { + if p == nil || p.CustomProperties == nil { + return map[string]any{} + } + return p.CustomProperties +} + // GetDefaultBranch returns the DefaultBranch field if it's non-nil, zero value otherwise. func (p *PushEventRepository) GetDefaultBranch() string { if p == nil || p.DefaultBranch == nil { @@ -21486,6 +21526,14 @@ func (r *Repository) GetCreatedAt() Timestamp { return *r.CreatedAt } +// GetCustomProperties returns the CustomProperties map if it's non-nil, an empty map otherwise. +func (r *Repository) GetCustomProperties() map[string]any { + if r == nil || r.CustomProperties == nil { + return map[string]any{} + } + return r.CustomProperties +} + // GetDefaultBranch returns the DefaultBranch field if it's non-nil, zero value otherwise. func (r *Repository) GetDefaultBranch() string { if r == nil || r.DefaultBranch == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index f2a51a6028c..1bb42959961 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -1441,6 +1441,17 @@ func TestAuditEntry_GetActorLocation(tt *testing.T) { a.GetActorLocation() } +func TestAuditEntry_GetAdditionalFields(tt *testing.T) { + tt.Parallel() + zeroValue := map[string]any{} + a := &AuditEntry{AdditionalFields: zeroValue} + a.GetAdditionalFields() + a = &AuditEntry{} + a.GetAdditionalFields() + a = nil + a.GetAdditionalFields() +} + func TestAuditEntry_GetBusiness(tt *testing.T) { tt.Parallel() var zeroValue string @@ -1474,6 +1485,17 @@ func TestAuditEntry_GetCreatedAt(tt *testing.T) { a.GetCreatedAt() } +func TestAuditEntry_GetData(tt *testing.T) { + tt.Parallel() + zeroValue := map[string]any{} + a := &AuditEntry{Data: zeroValue} + a.GetData() + a = &AuditEntry{} + a.GetData() + a = nil + a.GetData() +} + func TestAuditEntry_GetDocumentID(tt *testing.T) { tt.Parallel() var zeroValue string @@ -7872,6 +7894,17 @@ func TestCreateUserRequest_GetSuspended(tt *testing.T) { c.GetSuspended() } +func TestCreateWorkflowDispatchEventRequest_GetInputs(tt *testing.T) { + tt.Parallel() + zeroValue := map[string]any{} + c := &CreateWorkflowDispatchEventRequest{Inputs: zeroValue} + c.GetInputs() + c = &CreateWorkflowDispatchEventRequest{} + c.GetInputs() + c = nil + c.GetInputs() +} + func TestCreationInfo_GetCreated(tt *testing.T) { tt.Parallel() var zeroValue Timestamp @@ -12859,6 +12892,17 @@ func TestHook_GetID(tt *testing.T) { h.GetID() } +func TestHook_GetLastResponse(tt *testing.T) { + tt.Parallel() + zeroValue := map[string]any{} + h := &Hook{LastResponse: zeroValue} + h.GetLastResponse() + h = &Hook{} + h.GetLastResponse() + h = nil + h.GetLastResponse() +} + func TestHook_GetName(tt *testing.T) { tt.Parallel() var zeroValue string @@ -26211,6 +26255,17 @@ func TestPushEventRepository_GetCreatedAt(tt *testing.T) { p.GetCreatedAt() } +func TestPushEventRepository_GetCustomProperties(tt *testing.T) { + tt.Parallel() + zeroValue := map[string]any{} + p := &PushEventRepository{CustomProperties: zeroValue} + p.GetCustomProperties() + p = &PushEventRepository{} + p.GetCustomProperties() + p = nil + p.GetCustomProperties() +} + func TestPushEventRepository_GetDefaultBranch(tt *testing.T) { tt.Parallel() var zeroValue string @@ -27700,6 +27755,17 @@ func TestRepository_GetCreatedAt(tt *testing.T) { r.GetCreatedAt() } +func TestRepository_GetCustomProperties(tt *testing.T) { + tt.Parallel() + zeroValue := map[string]any{} + r := &Repository{CustomProperties: zeroValue} + r.GetCustomProperties() + r = &Repository{} + r.GetCustomProperties() + r = nil + r.GetCustomProperties() +} + func TestRepository_GetDefaultBranch(tt *testing.T) { tt.Parallel() var zeroValue string diff --git a/github/github-stringify_test.go b/github/github-stringify_test.go index 0100a4c202f..4563959967e 100644 --- a/github/github-stringify_test.go +++ b/github/github-stringify_test.go @@ -1238,6 +1238,8 @@ func TestPackageNPMMetadata_String(t *testing.T) { NodeVersion: Ptr(""), NPMVersion: Ptr(""), HasShrinkwrap: Ptr(false), + Maintainers: []any{nil}, + Contributors: []any{nil}, Keywords: []string{""}, Files: []string{""}, OS: []string{""}, @@ -1249,7 +1251,7 @@ func TestPackageNPMMetadata_String(t *testing.T) { PublishedViaActions: Ptr(false), DeletedByID: Ptr(int64(0)), } - want := `github.PackageNPMMetadata{Name:"", Version:"", NPMUser:"", Description:"", GitHead:"", Homepage:"", License:"", Main:"", ID:"", NodeVersion:"", NPMVersion:"", HasShrinkwrap:false, Keywords:[""], Files:[""], OS:[""], CPU:[""], Readme:"", InstallationCommand:"", ReleaseID:0, CommitOID:"", PublishedViaActions:false, DeletedByID:0}` + want := `github.PackageNPMMetadata{Name:"", Version:"", NPMUser:"", Description:"", GitHead:"", Homepage:"", License:"", Main:"", ID:"", NodeVersion:"", NPMVersion:"", HasShrinkwrap:false, Maintainers:[], Contributors:[], Keywords:[""], Files:[""], OS:[""], CPU:[""], Readme:"", InstallationCommand:"", ReleaseID:0, CommitOID:"", PublishedViaActions:false, DeletedByID:0}` if got := v.String(); got != want { t.Errorf("PackageNPMMetadata.String = %v, want %v", got, want) } @@ -1325,6 +1327,7 @@ func TestPackageVersion_String(t *testing.T) { Draft: Ptr(false), Prerelease: Ptr(false), ContainerMetadata: &PackageEventContainerMetadata{}, + DockerMetadata: []any{nil}, NPMMetadata: &PackageNPMMetadata{}, PackageURL: Ptr(""), Author: &User{}, @@ -1332,7 +1335,7 @@ func TestPackageVersion_String(t *testing.T) { InstallationCommand: Ptr(""), DeletedAt: &Timestamp{}, } - want := `github.PackageVersion{ID:0, Name:"", URL:"", PackageHTMLURL:"", License:"", Description:"", CreatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, UpdatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Version:"", Summary:"", BodyHTML:"", Release:github.PackageRelease{}, Manifest:"", HTMLURL:"", TagName:"", TargetCommitish:"", TargetOID:"", Draft:false, Prerelease:false, ContainerMetadata:github.PackageEventContainerMetadata{}, NPMMetadata:github.PackageNPMMetadata{}, PackageURL:"", Author:github.User{}, SourceURL:"", InstallationCommand:"", DeletedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}}` + want := `github.PackageVersion{ID:0, Name:"", URL:"", PackageHTMLURL:"", License:"", Description:"", CreatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, UpdatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Version:"", Summary:"", BodyHTML:"", Release:github.PackageRelease{}, Manifest:"", HTMLURL:"", TagName:"", TargetCommitish:"", TargetOID:"", Draft:false, Prerelease:false, ContainerMetadata:github.PackageEventContainerMetadata{}, DockerMetadata:[], NPMMetadata:github.PackageNPMMetadata{}, PackageURL:"", Author:github.User{}, SourceURL:"", InstallationCommand:"", DeletedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}}` if got := v.String(); got != want { t.Errorf("PackageVersion.String = %v, want %v", got, want) } diff --git a/github/github.go b/github/github.go index c366820383d..513f9fe4bcd 100644 --- a/github/github.go +++ b/github/github.go @@ -303,7 +303,7 @@ type RawOptions struct { // addOptions adds the parameters in opts as URL query parameters to s. opts // must be a struct whose fields may contain "url" tags. -func addOptions(s string, opts interface{}) (string, error) { +func addOptions(s string, opts any) (string, error) { v := reflect.ValueOf(opts) if v.Kind() == reflect.Ptr && v.IsNil() { return s, nil @@ -526,7 +526,7 @@ func WithVersion(version string) RequestOption { // Relative URLs should always be specified without a preceding slash. If // specified, the value pointed to by body is JSON encoded and included as the // request body. -func (c *Client) NewRequest(method, urlStr string, body interface{}, opts ...RequestOption) (*http.Request, error) { +func (c *Client) NewRequest(method, urlStr string, body any, opts ...RequestOption) (*http.Request, error) { if !strings.HasSuffix(c.BaseURL.Path, "/") { return nil, fmt.Errorf("baseURL must have a trailing slash, but %q does not", c.BaseURL) } @@ -1023,7 +1023,7 @@ func (c *Client) bareDoUntilFound(ctx context.Context, req *http.Request, maxRed // // The provided ctx must be non-nil, if it is nil an error is returned. If it // is canceled or times out, ctx.Err() will be returned. -func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error) { +func (c *Client) Do(ctx context.Context, req *http.Request, v any) (*Response, error) { resp, err := c.BareDo(ctx, req) if err != nil { return resp, err diff --git a/github/github_test.go b/github/github_test.go index 6069b3ebf4a..08a6eaaf6fc 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -162,7 +162,7 @@ func testBody(t *testing.T, r *http.Request, want string) { // Test whether the marshaling of v produces JSON that corresponds // to the want string. -func testJSONMarshal(t *testing.T, v interface{}, want string) { +func testJSONMarshal(t *testing.T, v any, want string) { t.Helper() // Unmarshal the wanted JSON, to verify its correctness, and marshal it back // to sort the keys. @@ -188,7 +188,7 @@ func testJSONMarshal(t *testing.T, v interface{}, want string) { // Test whether the v fields have the url tag and the parsing of v // produces query parameters that corresponds to the want string. -func testAddURLOptions(t *testing.T, url string, v interface{}, want string) { +func testAddURLOptions(t *testing.T, url string, v any, want string) { t.Helper() vt := reflect.Indirect(reflect.ValueOf(v)).Type() @@ -291,7 +291,7 @@ func testErrorResponseForStatusCode(t *testing.T, code int) { } } -func assertNoDiff(t *testing.T, want, got interface{}) { +func assertNoDiff(t *testing.T, want, got any) { t.Helper() if diff := cmp.Diff(want, got); diff != "" { t.Errorf("diff mismatch (-want +got):\n%v", diff) @@ -567,7 +567,7 @@ func TestNewRequest_invalidJSON(t *testing.T) { c := NewClient(nil) type T struct { - A map[interface{}]interface{} + A map[any]any } _, err := c.NewRequest("GET", ".", &T{}) @@ -1140,7 +1140,7 @@ func TestDo_preservesResponseInHTTPError(t *testing.T) { req, _ := client.NewRequest("GET", ".", nil) var resp *Response - var data interface{} + var data any resp, err := client.Do(context.Background(), req, &data) if err == nil { diff --git a/github/messages.go b/github/messages.go index 2b5cce7504a..95cb94b0eb5 100644 --- a/github/messages.go +++ b/github/messages.go @@ -45,7 +45,7 @@ const ( var ( // eventTypeMapping maps webhooks types to their corresponding go-github struct types. - eventTypeMapping = map[string]interface{}{ + eventTypeMapping = map[string]any{ "branch_protection_configuration": &BranchProtectionConfigurationEvent{}, "branch_protection_rule": &BranchProtectionRuleEvent{}, "check_run": &CheckRunEvent{}, @@ -318,7 +318,7 @@ func DeliveryID(r *http.Request) string { // ... // } // } -func ParseWebHook(messageType string, payload []byte) (interface{}, error) { +func ParseWebHook(messageType string, payload []byte) (any, error) { eventType, ok := messageToTypeName[messageType] if !ok { return nil, fmt.Errorf("unknown X-Github-Event in message: %v", messageType) @@ -344,7 +344,7 @@ func MessageTypes() []string { // EventForType returns an empty struct matching the specified GitHub event type. // If messageType does not match any known event types, it returns nil. -func EventForType(messageType string) interface{} { +func EventForType(messageType string) any { prototype := eventTypeMapping[messageType] if prototype == nil { return nil diff --git a/github/messages_test.go b/github/messages_test.go index a2b9feac92b..3c8cedfeab8 100644 --- a/github/messages_test.go +++ b/github/messages_test.go @@ -260,7 +260,7 @@ func TestValidatePayload_ValidContentTypeParams(t *testing.T) { func TestParseWebHook(t *testing.T) { t.Parallel() tests := []struct { - payload interface{} + payload any messageType string }{ { diff --git a/github/orgs_audit_log.go b/github/orgs_audit_log.go index 025c5d02327..409faebbca2 100644 --- a/github/orgs_audit_log.go +++ b/github/orgs_audit_log.go @@ -50,10 +50,10 @@ type AuditEntry struct { UserID *int64 `json:"user_id,omitempty"` // Some events types have a data field that contains additional information about the event. - Data map[string]interface{} `json:"data,omitempty"` + Data map[string]any `json:"data,omitempty"` // All fields that are not explicitly defined in the struct are captured here. - AdditionalFields map[string]interface{} `json:"-"` + AdditionalFields map[string]any `json:"-"` } func (a *AuditEntry) UnmarshalJSON(data []byte) error { @@ -67,7 +67,7 @@ func (a *AuditEntry) UnmarshalJSON(data []byte) error { if err != nil { return err } - definedFields := map[string]interface{}{} + definedFields := map[string]any{} if err := json.Unmarshal(rawDefinedFields, &definedFields); err != nil { return err } @@ -99,7 +99,7 @@ func (a *AuditEntry) MarshalJSON() ([]byte, error) { if len(a.AdditionalFields) == 0 { return defBytes, err } - resMap := map[string]interface{}{} + resMap := map[string]any{} if err := json.Unmarshal(defBytes, &resMap); err != nil { return nil, err } diff --git a/github/orgs_audit_log_test.go b/github/orgs_audit_log_test.go index f4b617c587b..376956c4a39 100644 --- a/github/orgs_audit_log_test.go +++ b/github/orgs_audit_log_test.go @@ -108,7 +108,7 @@ func TestOrganizationService_GetAuditLog(t *testing.T) { OrgID: Ptr(int64(1)), TokenID: Ptr(int64(1)), TokenScopes: Ptr("gist,repo:read"), - AdditionalFields: map[string]interface{}{ + AdditionalFields: map[string]any{ "actor_ip": "10.0.0.1", "active": true, "cancelled_at": "2021-03-07T00:35:08.000Z", @@ -121,13 +121,13 @@ func TestOrganizationService_GetAuditLog(t *testing.T) { "name": "Code scanning - action", "oauth_application_id": float64(1), "old_permission": "read", - "overridden_codes": []interface{}{"review_policy_not_satisfied"}, + "overridden_codes": []any{"review_policy_not_satisfied"}, "permission": "admin", "programmatic_access_type": "GitHub App server-to-server token", "pull_request_id": float64(1), "pull_request_title": "a pr title", "pull_request_url": "https://github.com/testorg/testrepo/pull/1", - "reasons": []interface{}{map[string]interface{}{ + "reasons": []any{map[string]any{ "code": "a code", "message": "a message", }}, @@ -140,8 +140,8 @@ func TestOrganizationService_GetAuditLog(t *testing.T) { "user_agent": "a user agent", "workflow_id": float64(123456), "workflow_run_id": float64(628312345), - "events": []interface{}{"code_scanning_alert"}, - "config": map[string]interface{}{ + "events": []any{"code_scanning_alert"}, + "config": map[string]any{ "content_type": "json", "insecure_ssl": "0", "url": "https://example.com/deadbeef-new-hook", @@ -241,11 +241,11 @@ func TestAuditEntry_Marshal(t *testing.T) { TokenID: Ptr(int64(1)), TokenScopes: Ptr("ts"), User: Ptr("u"), - Data: map[string]interface{}{ + Data: map[string]any{ "old_name": "on", "old_login": "ol", }, - AdditionalFields: map[string]interface{}{ + AdditionalFields: map[string]any{ "active": false, "active_was": false, "actor_ip": "aip", @@ -253,10 +253,10 @@ func TestAuditEntry_Marshal(t *testing.T) { "cancelled_at": "2021-03-07T00:35:08.000Z", "completed_at": "2021-03-07T00:35:08.000Z", "conclusion": "c", - "config": map[string]interface{}{ + "config": map[string]any{ "url": "s", }, - "config_was": map[string]interface{}{ + "config_was": map[string]any{ "url": "s", }, "content_type": "ct", @@ -264,8 +264,8 @@ func TestAuditEntry_Marshal(t *testing.T) { "emoji": "e", "environment_name": "en", "event": "e", - "events": []interface{}{"s"}, - "events_were": []interface{}{"s"}, + "events": []any{"s"}, + "events_were": []any{"s"}, "explanation": "e", "fingerprint": "f", "head_branch": "hb", @@ -286,8 +286,8 @@ func TestAuditEntry_Marshal(t *testing.T) { "pull_request_title": "prt", "pull_request_url": "pru", "read_only": "ro", - "reasons": []interface{}{ - map[string]interface{}{ + "reasons": []any{ + map[string]any{ "code": "c", "message": "m", }, @@ -300,9 +300,9 @@ func TestAuditEntry_Marshal(t *testing.T) { "runner_group_id": 1, "runner_group_name": "rgn", "runner_id": 1, - "runner_labels": []interface{}{"s"}, + "runner_labels": []any{"s"}, "runner_name": "rn", - "secrets_passed": []interface{}{"s"}, + "secrets_passed": []any{"s"}, "source_version": "sv", "started_at": "2006-01-02T15:04:05Z", "target_login": "tl", diff --git a/github/orgs_properties.go b/github/orgs_properties.go index f59d9f467ed..09abdffbfcb 100644 --- a/github/orgs_properties.go +++ b/github/orgs_properties.go @@ -44,8 +44,8 @@ type RepoCustomPropertyValue struct { // CustomPropertyValue represents a custom property value. type CustomPropertyValue struct { - PropertyName string `json:"property_name"` - Value interface{} `json:"value"` + PropertyName string `json:"property_name"` + Value any `json:"value"` } // UnmarshalJSON implements the json.Unmarshaler interface. @@ -66,7 +66,7 @@ func (cpv *CustomPropertyValue) UnmarshalJSON(data []byte) error { cpv.Value = nil case string: cpv.Value = v - case []interface{}: + case []any: strSlice := make([]string, len(v)) for i, item := range v { str, ok := item.(string) diff --git a/github/packages.go b/github/packages.go index 1eed77e804d..cc04a044d7d 100644 --- a/github/packages.go +++ b/github/packages.go @@ -63,7 +63,7 @@ type PackageVersion struct { Draft *bool `json:"draft,omitempty"` Prerelease *bool `json:"prerelease,omitempty"` ContainerMetadata *PackageEventContainerMetadata `json:"container_metadata,omitempty"` - DockerMetadata []interface{} `json:"docker_metadata,omitempty"` + DockerMetadata []any `json:"docker_metadata,omitempty"` NPMMetadata *PackageNPMMetadata `json:"npm_metadata,omitempty"` NugetMetadata []*PackageNugetMetadata `json:"nuget_metadata,omitempty"` RubyMetadata map[string]any `json:"ruby_metadata,omitempty"` @@ -296,8 +296,8 @@ type PackageNPMMetadata struct { NodeVersion *string `json:"node_version,omitempty"` NPMVersion *string `json:"npm_version,omitempty"` HasShrinkwrap *bool `json:"has_shrinkwrap,omitempty"` - Maintainers []interface{} `json:"maintainers,omitempty"` - Contributors []interface{} `json:"contributors,omitempty"` + Maintainers []any `json:"maintainers,omitempty"` + Contributors []any `json:"contributors,omitempty"` Engines map[string]string `json:"engines,omitempty"` Keywords []string `json:"keywords,omitempty"` Files []string `json:"files,omitempty"` diff --git a/github/packages_test.go b/github/packages_test.go index 9d2dcf10850..fa72bfcceea 100644 --- a/github/packages_test.go +++ b/github/packages_test.go @@ -243,7 +243,7 @@ func TestPackageVersion_Marshal(t *testing.T) { ContainerMetadata: &PackageEventContainerMetadata{ Labels: map[string]any{"l1": true, "l2": "a"}, }, - DockerMetadata: []interface{}{"a", "b"}, + DockerMetadata: []any{"a", "b"}, NPMMetadata: Ptr(PackageNPMMetadata{ Name: Ptr("n"), }), @@ -1208,15 +1208,15 @@ func TestPackageNPMMetadata_Marshal(t *testing.T) { Repository: map[string]string{"k1": "v1"}, Engines: map[string]string{"k1": "v1"}, Directories: map[string]string{"k1": "v1"}, - Scripts: map[string]interface{}{"k1": 1}, - Bin: map[string]interface{}{"k1": true}, - Man: map[string]interface{}{"k1": "v1"}, + Scripts: map[string]any{"k1": 1}, + Bin: map[string]any{"k1": true}, + Man: map[string]any{"k1": "v1"}, Keywords: []string{"kw1", "kw2"}, Files: []string{"f1", "f2"}, OS: []string{"os1", "os2"}, CPU: []string{"cpu1", "cpu2"}, - Maintainers: []interface{}{"m1", "m2"}, - Contributors: []interface{}{"c1", "c2"}, + Maintainers: []any{"m1", "m2"}, + Contributors: []any{"c1", "c2"}, }, want: `{ "name": "n", diff --git a/github/repos.go b/github/repos.go index c4ef5d59877..71483534363 100644 --- a/github/repos.go +++ b/github/repos.go @@ -27,59 +27,59 @@ type RepositoriesService service // Repository represents a GitHub repository. type Repository struct { - ID *int64 `json:"id,omitempty"` - NodeID *string `json:"node_id,omitempty"` - Owner *User `json:"owner,omitempty"` - Name *string `json:"name,omitempty"` - FullName *string `json:"full_name,omitempty"` - Description *string `json:"description,omitempty"` - Homepage *string `json:"homepage,omitempty"` - CodeOfConduct *CodeOfConduct `json:"code_of_conduct,omitempty"` - DefaultBranch *string `json:"default_branch,omitempty"` - MasterBranch *string `json:"master_branch,omitempty"` - CreatedAt *Timestamp `json:"created_at,omitempty"` - PushedAt *Timestamp `json:"pushed_at,omitempty"` - UpdatedAt *Timestamp `json:"updated_at,omitempty"` - HTMLURL *string `json:"html_url,omitempty"` - CloneURL *string `json:"clone_url,omitempty"` - GitURL *string `json:"git_url,omitempty"` - MirrorURL *string `json:"mirror_url,omitempty"` - SSHURL *string `json:"ssh_url,omitempty"` - SVNURL *string `json:"svn_url,omitempty"` - Language *string `json:"language,omitempty"` - Fork *bool `json:"fork,omitempty"` - ForksCount *int `json:"forks_count,omitempty"` - NetworkCount *int `json:"network_count,omitempty"` - OpenIssuesCount *int `json:"open_issues_count,omitempty"` - OpenIssues *int `json:"open_issues,omitempty"` // Deprecated: Replaced by OpenIssuesCount. For backward compatibility OpenIssues is still populated. - StargazersCount *int `json:"stargazers_count,omitempty"` - SubscribersCount *int `json:"subscribers_count,omitempty"` - WatchersCount *int `json:"watchers_count,omitempty"` // Deprecated: Replaced by StargazersCount. For backward compatibility WatchersCount is still populated. - Watchers *int `json:"watchers,omitempty"` // Deprecated: Replaced by StargazersCount. For backward compatibility Watchers is still populated. - Size *int `json:"size,omitempty"` - AutoInit *bool `json:"auto_init,omitempty"` - Parent *Repository `json:"parent,omitempty"` - Source *Repository `json:"source,omitempty"` - TemplateRepository *Repository `json:"template_repository,omitempty"` - Organization *Organization `json:"organization,omitempty"` - Permissions map[string]bool `json:"permissions,omitempty"` - AllowRebaseMerge *bool `json:"allow_rebase_merge,omitempty"` - AllowUpdateBranch *bool `json:"allow_update_branch,omitempty"` - AllowSquashMerge *bool `json:"allow_squash_merge,omitempty"` - AllowMergeCommit *bool `json:"allow_merge_commit,omitempty"` - AllowAutoMerge *bool `json:"allow_auto_merge,omitempty"` - AllowForking *bool `json:"allow_forking,omitempty"` - WebCommitSignoffRequired *bool `json:"web_commit_signoff_required,omitempty"` - DeleteBranchOnMerge *bool `json:"delete_branch_on_merge,omitempty"` - UseSquashPRTitleAsDefault *bool `json:"use_squash_pr_title_as_default,omitempty"` - SquashMergeCommitTitle *string `json:"squash_merge_commit_title,omitempty"` // Can be one of: "PR_TITLE", "COMMIT_OR_PR_TITLE" - SquashMergeCommitMessage *string `json:"squash_merge_commit_message,omitempty"` // Can be one of: "PR_BODY", "COMMIT_MESSAGES", "BLANK" - MergeCommitTitle *string `json:"merge_commit_title,omitempty"` // Can be one of: "PR_TITLE", "MERGE_MESSAGE" - MergeCommitMessage *string `json:"merge_commit_message,omitempty"` // Can be one of: "PR_BODY", "PR_TITLE", "BLANK" - Topics []string `json:"topics,omitempty"` - CustomProperties map[string]interface{} `json:"custom_properties,omitempty"` - Archived *bool `json:"archived,omitempty"` - Disabled *bool `json:"disabled,omitempty"` + ID *int64 `json:"id,omitempty"` + NodeID *string `json:"node_id,omitempty"` + Owner *User `json:"owner,omitempty"` + Name *string `json:"name,omitempty"` + FullName *string `json:"full_name,omitempty"` + Description *string `json:"description,omitempty"` + Homepage *string `json:"homepage,omitempty"` + CodeOfConduct *CodeOfConduct `json:"code_of_conduct,omitempty"` + DefaultBranch *string `json:"default_branch,omitempty"` + MasterBranch *string `json:"master_branch,omitempty"` + CreatedAt *Timestamp `json:"created_at,omitempty"` + PushedAt *Timestamp `json:"pushed_at,omitempty"` + UpdatedAt *Timestamp `json:"updated_at,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` + CloneURL *string `json:"clone_url,omitempty"` + GitURL *string `json:"git_url,omitempty"` + MirrorURL *string `json:"mirror_url,omitempty"` + SSHURL *string `json:"ssh_url,omitempty"` + SVNURL *string `json:"svn_url,omitempty"` + Language *string `json:"language,omitempty"` + Fork *bool `json:"fork,omitempty"` + ForksCount *int `json:"forks_count,omitempty"` + NetworkCount *int `json:"network_count,omitempty"` + OpenIssuesCount *int `json:"open_issues_count,omitempty"` + OpenIssues *int `json:"open_issues,omitempty"` // Deprecated: Replaced by OpenIssuesCount. For backward compatibility OpenIssues is still populated. + StargazersCount *int `json:"stargazers_count,omitempty"` + SubscribersCount *int `json:"subscribers_count,omitempty"` + WatchersCount *int `json:"watchers_count,omitempty"` // Deprecated: Replaced by StargazersCount. For backward compatibility WatchersCount is still populated. + Watchers *int `json:"watchers,omitempty"` // Deprecated: Replaced by StargazersCount. For backward compatibility Watchers is still populated. + Size *int `json:"size,omitempty"` + AutoInit *bool `json:"auto_init,omitempty"` + Parent *Repository `json:"parent,omitempty"` + Source *Repository `json:"source,omitempty"` + TemplateRepository *Repository `json:"template_repository,omitempty"` + Organization *Organization `json:"organization,omitempty"` + Permissions map[string]bool `json:"permissions,omitempty"` + AllowRebaseMerge *bool `json:"allow_rebase_merge,omitempty"` + AllowUpdateBranch *bool `json:"allow_update_branch,omitempty"` + AllowSquashMerge *bool `json:"allow_squash_merge,omitempty"` + AllowMergeCommit *bool `json:"allow_merge_commit,omitempty"` + AllowAutoMerge *bool `json:"allow_auto_merge,omitempty"` + AllowForking *bool `json:"allow_forking,omitempty"` + WebCommitSignoffRequired *bool `json:"web_commit_signoff_required,omitempty"` + DeleteBranchOnMerge *bool `json:"delete_branch_on_merge,omitempty"` + UseSquashPRTitleAsDefault *bool `json:"use_squash_pr_title_as_default,omitempty"` + SquashMergeCommitTitle *string `json:"squash_merge_commit_title,omitempty"` // Can be one of: "PR_TITLE", "COMMIT_OR_PR_TITLE" + SquashMergeCommitMessage *string `json:"squash_merge_commit_message,omitempty"` // Can be one of: "PR_BODY", "COMMIT_MESSAGES", "BLANK" + MergeCommitTitle *string `json:"merge_commit_title,omitempty"` // Can be one of: "PR_TITLE", "MERGE_MESSAGE" + MergeCommitMessage *string `json:"merge_commit_message,omitempty"` // Can be one of: "PR_BODY", "PR_TITLE", "BLANK" + Topics []string `json:"topics,omitempty"` + CustomProperties map[string]any `json:"custom_properties,omitempty"` + Archived *bool `json:"archived,omitempty"` + Disabled *bool `json:"disabled,omitempty"` // Only provided when using RepositoriesService.Get while in preview License *License `json:"license,omitempty"` diff --git a/github/repos_deployments.go b/github/repos_deployments.go index 6277ac2151a..ded36a95b40 100644 --- a/github/repos_deployments.go +++ b/github/repos_deployments.go @@ -32,15 +32,15 @@ type Deployment struct { // DeploymentRequest represents a deployment request. type DeploymentRequest struct { - Ref *string `json:"ref,omitempty"` - Task *string `json:"task,omitempty"` - AutoMerge *bool `json:"auto_merge,omitempty"` - RequiredContexts *[]string `json:"required_contexts,omitempty"` - Payload interface{} `json:"payload,omitempty"` - Environment *string `json:"environment,omitempty"` - Description *string `json:"description,omitempty"` - TransientEnvironment *bool `json:"transient_environment,omitempty"` - ProductionEnvironment *bool `json:"production_environment,omitempty"` + Ref *string `json:"ref,omitempty"` + Task *string `json:"task,omitempty"` + AutoMerge *bool `json:"auto_merge,omitempty"` + RequiredContexts *[]string `json:"required_contexts,omitempty"` + Payload any `json:"payload,omitempty"` + Environment *string `json:"environment,omitempty"` + Description *string `json:"description,omitempty"` + TransientEnvironment *bool `json:"transient_environment,omitempty"` + ProductionEnvironment *bool `json:"production_environment,omitempty"` } // DeploymentsListOptions specifies the optional parameters to the diff --git a/github/repos_environments.go b/github/repos_environments.go index d3e34fa8f80..eab51a11b1d 100644 --- a/github/repos_environments.go +++ b/github/repos_environments.go @@ -62,8 +62,8 @@ type ProtectionRule struct { // RequiredReviewer represents a required reviewer. type RequiredReviewer struct { - Type *string `json:"type,omitempty"` - Reviewer interface{} `json:"reviewer,omitempty"` + Type *string `json:"type,omitempty"` + Reviewer any `json:"reviewer,omitempty"` } // EnvironmentListOptions specifies the optional parameters to the diff --git a/github/repos_hooks.go b/github/repos_hooks.go index d221db21b6b..67b80b857f1 100644 --- a/github/repos_hooks.go +++ b/github/repos_hooks.go @@ -39,15 +39,15 @@ type WebHookAuthor = CommitAuthor // Hook represents a GitHub (web and service) hook for a repository. type Hook struct { - CreatedAt *Timestamp `json:"created_at,omitempty"` - UpdatedAt *Timestamp `json:"updated_at,omitempty"` - URL *string `json:"url,omitempty"` - ID *int64 `json:"id,omitempty"` - Type *string `json:"type,omitempty"` - Name *string `json:"name,omitempty"` - TestURL *string `json:"test_url,omitempty"` - PingURL *string `json:"ping_url,omitempty"` - LastResponse map[string]interface{} `json:"last_response,omitempty"` + CreatedAt *Timestamp `json:"created_at,omitempty"` + UpdatedAt *Timestamp `json:"updated_at,omitempty"` + URL *string `json:"url,omitempty"` + ID *int64 `json:"id,omitempty"` + Type *string `json:"type,omitempty"` + Name *string `json:"name,omitempty"` + TestURL *string `json:"test_url,omitempty"` + PingURL *string `json:"ping_url,omitempty"` + LastResponse map[string]any `json:"last_response,omitempty"` // Only the following fields are used when creating a hook. // Config is required. diff --git a/github/repos_hooks_deliveries.go b/github/repos_hooks_deliveries.go index bcd4b336e53..526d82c6f7c 100644 --- a/github/repos_hooks_deliveries.go +++ b/github/repos_hooks_deliveries.go @@ -152,7 +152,7 @@ func (s *RepositoriesService) RedeliverHookDelivery(ctx context.Context, owner, // ParseRequestPayload parses the request payload. For recognized event types, // a value of the corresponding struct type will be returned. -func (d *HookDelivery) ParseRequestPayload() (interface{}, error) { +func (d *HookDelivery) ParseRequestPayload() (any, error) { eType, ok := messageToTypeName[d.GetEvent()] if !ok { return nil, fmt.Errorf("unsupported event type %q", d.GetEvent()) diff --git a/github/repos_hooks_deliveries_test.go b/github/repos_hooks_deliveries_test.go index 91ff3ad7113..b3f8d7d570a 100644 --- a/github/repos_hooks_deliveries_test.go +++ b/github/repos_hooks_deliveries_test.go @@ -142,7 +142,7 @@ func TestRepositoriesService_RedeliverHookDelivery(t *testing.T) { }) } -var hookDeliveryPayloadTypeToStruct = map[string]interface{}{ +var hookDeliveryPayloadTypeToStruct = map[string]any{ "check_run": &CheckRunEvent{}, "check_suite": &CheckSuiteEvent{}, "code_scanning_alert": &CodeScanningAlertEvent{}, diff --git a/github/repos_hooks_test.go b/github/repos_hooks_test.go index 17b13daadd4..059d5371034 100644 --- a/github/repos_hooks_test.go +++ b/github/repos_hooks_test.go @@ -536,7 +536,7 @@ func TestBranchHook_Marshal(t *testing.T) { Name: Ptr("name"), TestURL: Ptr("testurl"), PingURL: Ptr("pingurl"), - LastResponse: map[string]interface{}{ + LastResponse: map[string]any{ "item": "item", }, Config: &HookConfig{ContentType: Ptr("json")}, diff --git a/github/repos_test.go b/github/repos_test.go index 716abaf9aac..a62711a1454 100644 --- a/github/repos_test.go +++ b/github/repos_test.go @@ -4167,7 +4167,7 @@ func TestRepositoriesService_Dispatch(t *testing.T) { ctx := context.Background() - testCases := []interface{}{ + testCases := []any{ nil, struct { Foo string @@ -4536,12 +4536,12 @@ func TestRepository_UnmarshalJSON(t *testing.T) { }, "Partial project": { data: []byte(`{"id":10270722,"name":"go-github","private":false,"owner":{"login":"google"},"created_at":"2013-05-24T16:42:58Z","license":{},"topics":["github"],"permissions":{"pull":true},"custom_properties":{},"organization":{"login":"google"}}`), - wantRepository: Repository{ID: Ptr(int64(10270722)), Name: Ptr("go-github"), Private: Ptr(false), Owner: &User{Login: Ptr("google")}, CreatedAt: &Timestamp{time.Date(2013, 5, 24, 16, 42, 58, 0, time.UTC)}, License: &License{}, Topics: []string{"github"}, Permissions: map[string]bool{"pull": true}, CustomProperties: map[string]interface{}{}, Organization: &Organization{Login: Ptr("google")}}, + wantRepository: Repository{ID: Ptr(int64(10270722)), Name: Ptr("go-github"), Private: Ptr(false), Owner: &User{Login: Ptr("google")}, CreatedAt: &Timestamp{time.Date(2013, 5, 24, 16, 42, 58, 0, time.UTC)}, License: &License{}, Topics: []string{"github"}, Permissions: map[string]bool{"pull": true}, CustomProperties: map[string]any{}, Organization: &Organization{Login: Ptr("google")}}, wantErr: false, }, "With custom properties": { data: []byte(`{"custom_properties":{"boolean":"false","text":"a","single-select":"a","multi-select":["a","b","c"]}}`), - wantRepository: Repository{CustomProperties: map[string]interface{}{"boolean": "false", "text": "a", "single-select": "a", "multi-select": []interface{}{"a", "b", "c"}}}, + wantRepository: Repository{CustomProperties: map[string]any{"boolean": "false", "text": "a", "single-select": "a", "multi-select": []any{"a", "b", "c"}}}, wantErr: false, }, } diff --git a/github/search.go b/github/search.go index 54bc6d5e1f4..8cdb634225d 100644 --- a/github/search.go +++ b/github/search.go @@ -300,7 +300,7 @@ func (s *SearchService) Labels(ctx context.Context, repoID int64, query string, // // If searchParameters.Query includes multiple condition, it MUST NOT include "+" as condition separator. // For example, querying with "language:c++" and "leveldb", then searchParameters.Query should be "language:c++ leveldb" but not "language:c+++leveldb". -func (s *SearchService) search(ctx context.Context, searchType string, parameters *searchParameters, opts *SearchOptions, result interface{}) (*Response, error) { +func (s *SearchService) search(ctx context.Context, searchType string, parameters *searchParameters, opts *SearchOptions, result any) (*Response, error) { params, err := qs.Values(opts) if err != nil { return nil, err diff --git a/github/strings.go b/github/strings.go index f5e61aa3265..46fd55ad142 100644 --- a/github/strings.go +++ b/github/strings.go @@ -16,7 +16,7 @@ var timestampType = reflect.TypeOf(Timestamp{}) // Stringify attempts to create a reasonable string representation of types in // the GitHub library. It does things like resolve pointers to their values // and omits struct fields with nil values. -func Stringify(message interface{}) string { +func Stringify(message any) string { var buf bytes.Buffer v := reflect.ValueOf(message) stringifyValue(&buf, v) diff --git a/github/strings_test.go b/github/strings_test.go index 98906b4d41d..0e6203c096c 100644 --- a/github/strings_test.go +++ b/github/strings_test.go @@ -16,7 +16,7 @@ func TestStringify(t *testing.T) { var nilPointer *string var tests = []struct { - in interface{} + in any out string }{ // basic types @@ -89,7 +89,7 @@ func TestStringify(t *testing.T) { func TestString(t *testing.T) { t.Parallel() var tests = []struct { - in interface{} + in any out string }{ {CodeResult{Name: Ptr("n")}, `github.CodeResult{Name:"n"}`}, diff --git a/scrape/scrape.go b/scrape/scrape.go index dc7aa88fad4..9f218b7f172 100644 --- a/scrape/scrape.go +++ b/scrape/scrape.go @@ -92,7 +92,7 @@ func (c *Client) LoadCookies(v []byte) error { // get fetches a urlStr (a GitHub URL relative to the client's baseURL), and // returns the parsed response document. -func (c *Client) get(urlStr string, a ...interface{}) (*goquery.Document, error) { +func (c *Client) get(urlStr string, a ...any) (*goquery.Document, error) { u, err := c.baseURL.Parse(fmt.Sprintf(urlStr, a...)) if err != nil { return nil, fmt.Errorf("error parsing URL: %q: %v", urlStr, err) diff --git a/test/fields/fields.go b/test/fields/fields.go index f35abb6de1b..1f48edfe514 100644 --- a/test/fields/fields.go +++ b/test/fields/fields.go @@ -47,7 +47,7 @@ func main() { for _, tt := range []struct { url string - typ interface{} + typ any }{ {"users/octocat", &github.User{}}, {"user", &github.User{}}, @@ -66,7 +66,7 @@ func main() { // testType fetches the JSON resource at urlStr and compares its keys to the // struct fields of typ. -func testType(urlStr string, typ interface{}) error { +func testType(urlStr string, typ any) error { slice := reflect.Indirect(reflect.ValueOf(typ)).Kind() == reflect.Slice req, err := client.NewRequest("GET", urlStr, nil) @@ -82,9 +82,9 @@ func testType(urlStr string, typ interface{}) error { } // unmarshal directly to a map - var m1 map[string]interface{} + var m1 map[string]any if slice { - var s []map[string]interface{} + var s []map[string]any err = json.Unmarshal(*raw, &s) if err != nil { return err @@ -118,7 +118,7 @@ func testType(urlStr string, typ interface{}) error { } } - var m2 map[string]interface{} + var m2 map[string]any err = json.Unmarshal(byt, &m2) if err != nil { return err diff --git a/tools/metadata/main_test.go b/tools/metadata/main_test.go index f0cdff43843..2fab7948a85 100644 --- a/tools/metadata/main_test.go +++ b/tools/metadata/main_test.go @@ -69,7 +69,7 @@ GET /undocumented/{undocumented_id} //nolint:tparallel,paralleltest // cannot use t.Parallel() when helper calls t.Setenv func TestUpdateOpenAPI(t *testing.T) { - testServer := newTestServer(t, "main", map[string]interface{}{ + testServer := newTestServer(t, "main", map[string]any{ "api.github.com/api.github.com.json": openapi3.T{ Paths: openapi3.NewPaths( openapi3.WithPath("/a/{a_id}", &openapi3.PathItem{ @@ -332,9 +332,9 @@ func runTest(t *testing.T, srcDir string, args ...string) testRun { return res } -func newTestServer(t *testing.T, ref string, files map[string]interface{}) *httptest.Server { +func newTestServer(t *testing.T, ref string, files map[string]any) *httptest.Server { t.Helper() - jsonHandler := func(wantQuery url.Values, val interface{}) http.HandlerFunc { + jsonHandler := func(wantQuery url.Values, val any) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { gotQuery := r.URL.Query() queryDiff := cmp.Diff(wantQuery, gotQuery) diff --git a/tools/sliceofpointers/sliceofpointers.go b/tools/sliceofpointers/sliceofpointers.go index d6a59b38f28..75639b68b0b 100644 --- a/tools/sliceofpointers/sliceofpointers.go +++ b/tools/sliceofpointers/sliceofpointers.go @@ -42,7 +42,7 @@ func (f *SliceOfPointersPlugin) GetLoadMode() string { return register.LoadModeSyntax } -func run(pass *analysis.Pass) (interface{}, error) { +func run(pass *analysis.Pass) (any, error) { for _, file := range pass.Files { ast.Inspect(file, func(n ast.Node) bool { if n == nil {