executeSingle executes hooks at a specific time
(ctx devspacecontext.Context, extraEnv map[string]string, event string)
| 100 | |
| 101 | // executeSingle executes hooks at a specific time |
| 102 | func executeSingle(ctx devspacecontext.Context, extraEnv map[string]string, event string) error { |
| 103 | config := ctx.Config() |
| 104 | if config == nil { |
| 105 | return nil |
| 106 | } |
| 107 | |
| 108 | c := config.Config() |
| 109 | if len(c.Hooks) > 0 { |
| 110 | hooksToExecute := []*latest.HookConfig{} |
| 111 | |
| 112 | // Gather all hooks we should execute |
| 113 | for _, hook := range c.Hooks { |
| 114 | for _, e := range hook.Events { |
| 115 | if e == event { |
| 116 | hooksToExecute = append(hooksToExecute, hook) |
| 117 | break |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | // Execute hooks |
| 123 | for _, hookConfig := range hooksToExecute { |
| 124 | if hookConfig.Disabled || !command.ShouldExecuteOnOS(hookConfig.OperatingSystem) { |
| 125 | continue |
| 126 | } |
| 127 | |
| 128 | err := runHook(ctx, hookConfig, extraEnv, event) |
| 129 | if err != nil { |
| 130 | return err |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | return nil |
| 136 | } |
| 137 | |
| 138 | func runHook(ctx devspacecontext.Context, hookConfig *latest.HookConfig, extraEnv map[string]string, event string) error { |
| 139 | // Determine output writer |
no test coverage detected