mirror of
https://github.com/go-gitea/gitea.git
synced 2026-03-28 04:32:42 +01:00
This is a step towards potentially splitting command groups into their own folders to clean up `cmd/` as one folder for all cli commands. Returning fresh command instances will also aid in adding tests as you don't need to concern yourself with the whole command tree being one mutable variable. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
45 lines
1015 B
Go
45 lines
1015 B
Go
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"context"
|
|
|
|
"code.gitea.io/gitea/modules/graceful"
|
|
asymkey_service "code.gitea.io/gitea/services/asymkey"
|
|
repo_service "code.gitea.io/gitea/services/repository"
|
|
|
|
"github.com/urfave/cli/v3"
|
|
)
|
|
|
|
func newRegenerateHooksCommand() *cli.Command {
|
|
return &cli.Command{
|
|
Name: "hooks",
|
|
Usage: "Regenerate git-hooks",
|
|
Action: runRegenerateHooks,
|
|
}
|
|
}
|
|
|
|
func newRegenerateKeysCommand() *cli.Command {
|
|
return &cli.Command{
|
|
Name: "keys",
|
|
Usage: "Regenerate authorized_keys file",
|
|
Action: runRegenerateKeys,
|
|
}
|
|
}
|
|
|
|
func runRegenerateHooks(ctx context.Context, _ *cli.Command) error {
|
|
if err := initDB(ctx); err != nil {
|
|
return err
|
|
}
|
|
return repo_service.SyncRepositoryHooks(graceful.GetManager().ShutdownContext())
|
|
}
|
|
|
|
func runRegenerateKeys(ctx context.Context, _ *cli.Command) error {
|
|
if err := initDB(ctx); err != nil {
|
|
return err
|
|
}
|
|
return asymkey_service.RewriteAllPublicKeys(ctx)
|
|
}
|