Skip to content

Commit

Permalink
Added git:hook task
Browse files Browse the repository at this point in the history
  • Loading branch information
vorban committed Jul 9, 2021
1 parent 6802ee6 commit 88c685f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions domain/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func DefaultTaskNames() []TaskID {
"composer",
"gulp",
"db:update",
"git:hook",
}
}

Expand Down
41 changes: 40 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"io/ioutil"
"os"
"regexp"
"sort"
Expand Down Expand Up @@ -194,7 +195,14 @@ func main() {
}

/*
* 5. The end
* 5. Plug Git precommit Hook
*/

fmt.Printf("%s %s\n", color.MagentaString("Executing:"), "git:plug-hook")
cmd = domain.NewCommand([]string{"pliz", "git:plug-hook"})
cmd.Execute()
/*
* 6. The end
*/

fmt.Printf("\n\n%s You may now run '%s' to launch your project\n", color.GreenString("✓"), color.MagentaString("pliz start"))
Expand Down Expand Up @@ -320,6 +328,37 @@ func main() {
}
})

app.Command("git:plug-hook", "Register hooks in the Git repository", func(cmd *cli.Cmd) {
cmd.Action = func() {
fmt.Printf("%s %s\n", color.MagentaString("Executing:"), "git:hook")
code :=
`#!/bin/sh
# don't validate if phpcs is not found
PHPCS="$(command -v phpcs)"
if [ -z "$PHPCS" ]; then
echo "phpcs unavailable; skipping PHP Standards validation..."
exit
fi
# get all modified and staged PHP files (.blade included)
# and run phpcs over them
FILES="$(git diff --name-only --staged | grep .php | tr "\n" " ")"
if [ ! -z "$FILES" ]; then
OUTPUT=$(phpcs --report=summary $FILES)
if [ ! -z "$OUTPUT" ]; then
echo "$OUTPUT"
exit 1
fi
fi
exit 0`
err := ioutil.WriteFile(".git/hooks/pre-commit", []byte(code), 0755)
if err != nil {
fmt.Printf("Unable to write file: %v", err)
}
}
})

app.Run(os.Args)
}

Expand Down
2 changes: 2 additions & 0 deletions tasks/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ func CreateTaskWithName(name domain.TaskID, config domain.Config) (domain.Task,
return GulpTask(config.Containers.Builder), nil
case "db:update":
return DbUpdateTask(config.Containers.App), nil
case "git:plug-hook":
return GitPlugHookTask(), nil
}

return domain.Task{}, fmt.Errorf("Unable to find the task '%s'\n", name)
Expand Down
12 changes: 12 additions & 0 deletions tasks/git-hook.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package tasks

import "webup/pliz/domain"

// Create a task for running 'gulp'
func GitPlugHookTask() domain.Task {
task := domain.Task{Name: "git:plug-hook", Description: "Run 'pliz git:plug-hook'"}

task.CommandArgs = []string{"pliz", "git:plug-hook"}

return task
}

0 comments on commit 88c685f

Please sign in to comment.