mirror of
https://github.com/1f349/site-hosting.git
synced 2025-01-21 06:36:33 +00:00
34 lines
623 B
Go
34 lines
623 B
Go
|
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()
|
||
|
}
|