chore: enable forcetypeassert linter, fix issues (#38804)

Enable [`forcetypeassert`](https://github.com/gostaticanalysis/forcetypeassert)
linter to prevent unchecked type assertions. ~650 issues fixed, most
fixes were clean, some use `setting.PanicInDevOrTesting`.

The only behaviour changes are where code would previously send a 500 error
or panic, a 4xx error is now emitted.

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
silverwind
2026-08-09 12:25:06 +02:00
committed by GitHub
parent fac8bf2eca
commit 76a81b24f9
248 changed files with 1110 additions and 995 deletions
+17 -24
View File
@@ -36,9 +36,8 @@ func registerUpdateMirrorTask() {
},
PullLimit: 50,
PushLimit: 50,
}, func(ctx context.Context, _ *user_model.User, cfg Config) error {
umtc := cfg.(*UpdateMirrorTaskConfig)
return mirror_service.Update(ctx, umtc.PullLimit, umtc.PushLimit)
}, func(ctx context.Context, _ *user_model.User, cfg *UpdateMirrorTaskConfig) error {
return mirror_service.Update(ctx, cfg.PullLimit, cfg.PushLimit)
})
}
@@ -56,10 +55,9 @@ func registerRepoHealthCheck() {
},
Timeout: time.Duration(setting.Git.Timeout.GC) * time.Second,
Args: []string{},
}, func(ctx context.Context, _ *user_model.User, config Config) error {
rhcConfig := config.(*RepoHealthCheckConfig)
}, func(ctx context.Context, _ *user_model.User, config *RepoHealthCheckConfig) error {
// the git args are set by config, they can be safe to be trusted
return repo_service.GitFsckRepos(ctx, rhcConfig.Timeout, gitcmd.ToTrustedCmdArgs(rhcConfig.Args))
return repo_service.GitFsckRepos(ctx, config.Timeout, gitcmd.ToTrustedCmdArgs(config.Args))
})
}
@@ -68,7 +66,7 @@ func registerCheckRepoStats() {
Enabled: true,
RunAtStart: true,
Schedule: "@midnight",
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
}, func(ctx context.Context, _ *user_model.User, _ *BaseConfig) error {
return repostats.CheckRepoStats(ctx)
})
}
@@ -81,9 +79,8 @@ func registerArchiveCleanup() {
Schedule: "@midnight",
},
OlderThan: 24 * time.Hour,
}, func(ctx context.Context, _ *user_model.User, config Config) error {
acConfig := config.(*OlderThanConfig)
return archiver_service.DeleteOldRepositoryArchives(ctx, acConfig.OlderThan)
}, func(ctx context.Context, _ *user_model.User, config *OlderThanConfig) error {
return archiver_service.DeleteOldRepositoryArchives(ctx, config.OlderThan)
})
}
@@ -95,9 +92,8 @@ func registerSyncExternalUsers() {
Schedule: "@midnight",
},
UpdateExisting: true,
}, func(ctx context.Context, _ *user_model.User, config Config) error {
realConfig := config.(*UpdateExistingConfig)
return auth.SyncExternalUsers(ctx, realConfig.UpdateExisting)
}, func(ctx context.Context, _ *user_model.User, config *UpdateExistingConfig) error {
return auth.SyncExternalUsers(ctx, config.UpdateExisting)
})
}
@@ -109,9 +105,8 @@ func registerDeletedBranchesCleanup() {
Schedule: "@midnight",
},
OlderThan: 24 * time.Hour,
}, func(ctx context.Context, _ *user_model.User, config Config) error {
realConfig := config.(*OlderThanConfig)
git_model.RemoveOldDeletedBranches(ctx, realConfig.OlderThan)
}, func(ctx context.Context, _ *user_model.User, config *OlderThanConfig) error {
git_model.RemoveOldDeletedBranches(ctx, config.OlderThan)
return nil
})
}
@@ -121,7 +116,7 @@ func registerUpdateMigrationPosterID() {
Enabled: true,
RunAtStart: true,
Schedule: "@midnight",
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
}, func(ctx context.Context, _ *user_model.User, _ *BaseConfig) error {
return migrations.UpdateMigrationPosterID(ctx)
})
}
@@ -136,9 +131,8 @@ func registerCleanupHookTaskTable() {
CleanupType: "OlderThan",
OlderThan: 168 * time.Hour,
NumberToKeep: 10,
}, func(ctx context.Context, _ *user_model.User, config Config) error {
realConfig := config.(*CleanupHookTaskConfig)
return webhook.CleanupHookTaskTable(ctx, webhook.ToHookTaskCleanupType(realConfig.CleanupType), realConfig.OlderThan, realConfig.NumberToKeep)
}, func(ctx context.Context, _ *user_model.User, config *CleanupHookTaskConfig) error {
return webhook.CleanupHookTaskTable(ctx, webhook.ToHookTaskCleanupType(config.CleanupType), config.OlderThan, config.NumberToKeep)
})
}
@@ -150,9 +144,8 @@ func registerCleanupPackages() {
Schedule: "@midnight",
},
OlderThan: 24 * time.Hour,
}, func(ctx context.Context, _ *user_model.User, config Config) error {
realConfig := config.(*OlderThanConfig)
return packages_cleanup_service.CleanupTask(ctx, realConfig.OlderThan)
}, func(ctx context.Context, _ *user_model.User, config *OlderThanConfig) error {
return packages_cleanup_service.CleanupTask(ctx, config.OlderThan)
})
}
@@ -161,7 +154,7 @@ func registerSyncRepoLicenses() {
Enabled: false,
RunAtStart: false,
Schedule: "@annually",
}, func(ctx context.Context, _ *user_model.User, config Config) error {
}, func(ctx context.Context, _ *user_model.User, _ *BaseConfig) error {
return repo_service.SyncRepoLicenses(ctx)
})
}