Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync git hooks when config file path changed (#21619) #21625

Merged
merged 1 commit into from
Oct 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion modules/appstate/item_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ package appstate

// RuntimeState contains app state for runtime, and we can save remote version for update checker here in future
type RuntimeState struct {
LastAppPath string `json:"last_app_path"`
LastAppPath string `json:"last_app_path"`
LastCustomConf string `json:"last_custom_conf"`
}

// Name returns the item name
Expand Down
16 changes: 13 additions & 3 deletions routers/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,31 @@ func InitGitServices() {
mustInit(repo_service.Init)
}

func syncAppPathForGit(ctx context.Context) error {
func syncAppConfForGit(ctx context.Context) error {
runtimeState := new(appstate.RuntimeState)
if err := appstate.AppState.Get(runtimeState); err != nil {
return err
}

updated := false
if runtimeState.LastAppPath != setting.AppPath {
log.Info("AppPath changed from '%s' to '%s'", runtimeState.LastAppPath, setting.AppPath)
runtimeState.LastAppPath = setting.AppPath
updated = true
}
if runtimeState.LastCustomConf != setting.CustomConf {
log.Info("CustomConf changed from '%s' to '%s'", runtimeState.LastCustomConf, setting.CustomConf)
runtimeState.LastCustomConf = setting.CustomConf
updated = true
}

if updated {
log.Info("re-sync repository hooks ...")
mustInitCtx(ctx, repo_service.SyncRepositoryHooks)

log.Info("re-write ssh public keys ...")
mustInit(asymkey_model.RewriteAllPublicKeys)

runtimeState.LastAppPath = setting.AppPath
return appstate.AppState.Set(runtimeState)
}
return nil
Expand Down Expand Up @@ -153,7 +163,7 @@ func GlobalInitInstalled(ctx context.Context) {
mustInit(repo_migrations.Init)
eventsource.GetManager().Init()

mustInitCtx(ctx, syncAppPathForGit)
mustInitCtx(ctx, syncAppConfForGit)

mustInit(ssh.Init)

Expand Down