bluebell/hook/hook.go

34 lines
623 B
Go
Raw Normal View History

2025-01-08 22:31:57 +00:00
package hook
import (
"github.com/cyphar/filepath-securejoin"
"os/exec"
"path/filepath"
)
type Hook struct {
hookDir string
sitesDir string
}
func New(hookDir string, sitesDir string) *Hook {
return &Hook{hookDir: hookDir, sitesDir: sitesDir}
}
func (h *Hook) Run(site, branch string) error {
sitePath, err := securejoin.SecureJoin(h.sitesDir, site+"/@"+branch)
if err != nil {
return err
}
scriptPath, err := securejoin.SecureJoin(h.hookDir, site)
if err != nil {
return err
}
cmd := exec.Cmd{
Path: scriptPath,
Args: []string{filepath.Base(scriptPath)},
Dir: sitePath,
}
return cmd.Run()
}