mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-08 22:13:26 +09:00
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:
@@ -28,9 +28,8 @@ func registerDeleteInactiveUsers() {
|
||||
Schedule: "@annually",
|
||||
},
|
||||
OlderThan: time.Minute * time.Duration(setting.Service.ActiveCodeLives),
|
||||
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
||||
olderThanConfig := config.(*OlderThanConfig)
|
||||
return user_service.DeleteInactiveUsers(ctx, olderThanConfig.OlderThan)
|
||||
}, func(ctx context.Context, _ *user_model.User, config *OlderThanConfig) error {
|
||||
return user_service.DeleteInactiveUsers(ctx, config.OlderThan)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -39,7 +38,7 @@ func registerDeleteRepositoryArchives() {
|
||||
Enabled: false,
|
||||
RunAtStart: false,
|
||||
Schedule: "@annually",
|
||||
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
||||
}, func(ctx context.Context, _ *user_model.User, _ *BaseConfig) error {
|
||||
return archiver_service.DeleteRepositoryArchives(ctx)
|
||||
})
|
||||
}
|
||||
@@ -58,10 +57,9 @@ func registerGarbageCollectRepositories() {
|
||||
},
|
||||
Timeout: time.Duration(setting.Git.Timeout.GC) * time.Second,
|
||||
Args: setting.Git.GCArgs,
|
||||
}, 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.GitGcRepos(ctx, rhcConfig.Timeout, gitcmd.ToTrustedCmdArgs(rhcConfig.Args))
|
||||
return repo_service.GitGcRepos(ctx, config.Timeout, gitcmd.ToTrustedCmdArgs(config.Args))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -70,7 +68,7 @@ func registerRewriteAllPublicKeys() {
|
||||
Enabled: false,
|
||||
RunAtStart: false,
|
||||
Schedule: "@every 72h",
|
||||
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
||||
}, func(ctx context.Context, _ *user_model.User, _ *BaseConfig) error {
|
||||
return asymkey_service.RewriteAllPublicKeys(ctx)
|
||||
})
|
||||
}
|
||||
@@ -80,7 +78,7 @@ func registerRewriteAllPrincipalKeys() {
|
||||
Enabled: false,
|
||||
RunAtStart: false,
|
||||
Schedule: "@every 72h",
|
||||
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
||||
}, func(ctx context.Context, _ *user_model.User, _ *BaseConfig) error {
|
||||
return asymkey_service.RewriteAllPrincipalKeys(ctx)
|
||||
})
|
||||
}
|
||||
@@ -90,7 +88,7 @@ func registerRepositoryUpdateHook() {
|
||||
Enabled: false,
|
||||
RunAtStart: false,
|
||||
Schedule: "@every 72h",
|
||||
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
||||
}, func(ctx context.Context, _ *user_model.User, _ *BaseConfig) error {
|
||||
return repo_service.SyncRepositoryHooks(ctx)
|
||||
})
|
||||
}
|
||||
@@ -100,7 +98,7 @@ func registerReinitMissingRepositories() {
|
||||
Enabled: false,
|
||||
RunAtStart: false,
|
||||
Schedule: "@every 72h",
|
||||
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
||||
}, func(ctx context.Context, _ *user_model.User, _ *BaseConfig) error {
|
||||
return repo_service.ReinitMissingRepositories(ctx)
|
||||
})
|
||||
}
|
||||
@@ -110,7 +108,7 @@ func registerDeleteMissingRepositories() {
|
||||
Enabled: false,
|
||||
RunAtStart: false,
|
||||
Schedule: "@every 72h",
|
||||
}, func(ctx context.Context, user *user_model.User, _ Config) error {
|
||||
}, func(ctx context.Context, user *user_model.User, _ *BaseConfig) error {
|
||||
return repo_service.DeleteMissingRepositories(ctx, user)
|
||||
})
|
||||
}
|
||||
@@ -120,7 +118,7 @@ func registerRemoveRandomAvatars() {
|
||||
Enabled: false,
|
||||
RunAtStart: false,
|
||||
Schedule: "@every 72h",
|
||||
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
||||
}, func(ctx context.Context, _ *user_model.User, _ *BaseConfig) error {
|
||||
return repo_service.RemoveRandomAvatars(ctx)
|
||||
})
|
||||
}
|
||||
@@ -133,9 +131,8 @@ func registerDeleteOldActions() {
|
||||
Schedule: "@every 168h",
|
||||
},
|
||||
OlderThan: 365 * 24 * time.Hour,
|
||||
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
||||
olderThanConfig := config.(*OlderThanConfig)
|
||||
return activities_model.DeleteOldActions(ctx, olderThanConfig.OlderThan)
|
||||
}, func(ctx context.Context, _ *user_model.User, config *OlderThanConfig) error {
|
||||
return activities_model.DeleteOldActions(ctx, config.OlderThan)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -151,9 +148,8 @@ func registerUpdateGiteaChecker() {
|
||||
Schedule: "@every 168h",
|
||||
},
|
||||
HTTPEndpoint: "https://dl.gitea.com/gitea/version.json",
|
||||
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
||||
updateCheckerConfig := config.(*UpdateCheckerConfig)
|
||||
return updatechecker.GiteaUpdateChecker(updateCheckerConfig.HTTPEndpoint)
|
||||
}, func(ctx context.Context, _ *user_model.User, config *UpdateCheckerConfig) error {
|
||||
return updatechecker.GiteaUpdateChecker(config.HTTPEndpoint)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -165,9 +161,8 @@ func registerDeleteOldSystemNotices() {
|
||||
Schedule: "@every 168h",
|
||||
},
|
||||
OlderThan: 365 * 24 * time.Hour,
|
||||
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
||||
olderThanConfig := config.(*OlderThanConfig)
|
||||
return system.DeleteOldSystemNotices(ctx, olderThanConfig.OlderThan)
|
||||
}, func(ctx context.Context, _ *user_model.User, config *OlderThanConfig) error {
|
||||
return system.DeleteOldSystemNotices(ctx, config.OlderThan)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -204,12 +199,11 @@ func registerGCLFS() {
|
||||
LastUpdatedMoreThanAgo: 24 * time.Hour * 3,
|
||||
NumberToCheckPerRepo: 100,
|
||||
ProportionToCheckPerRepo: 0.6,
|
||||
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
||||
gcLFSConfig := config.(*GCLFSConfig)
|
||||
}, func(ctx context.Context, _ *user_model.User, config *GCLFSConfig) error {
|
||||
return repo_service.GarbageCollectLFSMetaObjects(ctx, repo_service.GarbageCollectLFSMetaObjectsOptions{
|
||||
AutoFix: true,
|
||||
OlderThan: time.Now().Add(-gcLFSConfig.OlderThan),
|
||||
UpdatedLessRecentlyThan: time.Now().Add(-gcLFSConfig.LastUpdatedMoreThanAgo),
|
||||
OlderThan: time.Now().Add(-config.OlderThan),
|
||||
UpdatedLessRecentlyThan: time.Now().Add(-config.LastUpdatedMoreThanAgo),
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -219,7 +213,7 @@ func registerRebuildIssueIndexer() {
|
||||
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 issue_indexer.PopulateIssueIndexer(ctx)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user