Skip to content

Commit

Permalink
chore: output enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexox committed Sep 14, 2023
1 parent 58e8769 commit bec6468
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 33 deletions.
28 changes: 14 additions & 14 deletions internal/config/available_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,35 @@ const GhostHookName = "prepare-commit-msg"

// AvailableHooks - list of hooks taken from https://git-scm.com/docs/githooks.
var AvailableHooks = [...]string{
"pre-applypatch",
"applypatch-msg",
"post-applypatch",
"pre-commit",
"pre-push",
"commit-msg",
"applypatch-msg",
"fsmonitor-watchman",
"p4-changelist",
"p4-post-changelist",
"p4-pre-submit",
"p4-prepare-changelist",
"pre-commit",
"post-applypatch",
"post-checkout",
"post-commit",
"pre-receive",
"proc-receive",
"post-receive",
"post-index-change",
"post-merge",
"pre-rebase",
"rebase",
"update",
"post-update",
"post-receive",
"post-rewrite",
"post-checkout",
"post-index-change",
"post-update",
"pre-applypatch",
"pre-auto-gc",
"pre-merge-commit",
"pre-push",
"pre-rebase",
"pre-receive",
"prepare-commit-msg",
"proc-receive",
"push-to-checkout",
"rebase",
"reference-transaction",
"sendemail-validate",
"update",
}

func HookUsesStagedFiles(hook string) bool {
Expand Down
14 changes: 12 additions & 2 deletions internal/lefthook/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,14 @@ func (l *Lefthook) createHooksIfNeeded(cfg *config.Config, force bool) error {
return nil
}

log.Info(log.Cyan("SYNCING"))
log.Infof(log.Cyan("sync hooks"))

var success bool
defer func() {
if !success {
log.Info(log.Cyan(": ❌"))
}
}()

checksum, err := l.configChecksum()
if err != nil {
Expand Down Expand Up @@ -148,8 +155,11 @@ func (l *Lefthook) createHooksIfNeeded(cfg *config.Config, force bool) error {
return err
}

success = true
if len(hookNames) > 0 {
log.Info(log.Cyan("SERVED HOOKS:"), log.Bold(strings.Join(hookNames, ", ")))
log.Info(log.Cyan(": ✔️"), log.Gray("("+strings.Join(hookNames, ", ")+")"))
} else {
log.Info(log.Cyan(": ✔️ "))
}

return nil
Expand Down
27 changes: 18 additions & 9 deletions internal/lefthook/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ func (l *Lefthook) Run(hookName string, args RunArgs, gitArgs []string) error {
}

if !logSettings.SkipMeta() {
log.Info(log.Cyan("Lefthook v" + version.Version(false)))
log.Info(
log.Cyan("lefthook"),
log.Gray(fmt.Sprintf("v%s,", version.Version(false))),
log.Gray("hook:"),
log.Bold(hookName),
)
}

// This line controls updating the git hook if config has changed
Expand All @@ -91,10 +96,6 @@ Run 'lefthook install' manually.`,
)
}

if !logSettings.SkipMeta() {
log.Info(log.Cyan("RUNNING HOOK:"), log.Bold(hookName))
}

// Find the hook
hook, ok := cfg.Hooks[hookName]
if !ok {
Expand Down Expand Up @@ -173,14 +174,22 @@ func printSummary(
) {
if len(results) == 0 {
if !logSettings.SkipEmptySummary() {
log.Info(log.Cyan("\nSUMMARY: (SKIP EMPTY)"))
log.Info(
fmt.Sprintf(
"%s %s %s",
log.Cyan("summary:"),
log.Gray("(skip)"),
log.Yellow("empty"),
),
)
}
return
}

log.Info(log.Cyan(
fmt.Sprintf("\nSUMMARY: (done in %.2f seconds)", duration.Seconds()),
))
log.Info(
log.Cyan("\nsummary:"),
log.Gray(fmt.Sprintf("(done in %.2f seconds)", duration.Seconds())),
)

if !logSettings.SkipSuccess() {
for _, result := range results {
Expand Down
13 changes: 5 additions & 8 deletions internal/lefthook/run/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,9 @@ func (r *Runner) logSkip(name, reason string) {
}

log.Info(
fmt.Sprintf(
"%s: %s %s",
log.Bold(name),
log.Gray("(skip)"),
log.Yellow(reason),
),
log.Cyan(fmt.Sprintf("\n %s", log.Bold(name))),
log.Gray("(skip)"),
log.Yellow(reason),
)
}

Expand All @@ -489,9 +486,9 @@ func (r *Runner) logExecute(name string, err error, out io.Reader) {
case r.SkipSettings.SkipExecutionInfo():
execLog = ""
case err != nil:
execLog = fmt.Sprint(log.Red("\n EXECUTE > "), log.Bold(name))
execLog = log.Red(fmt.Sprintf("\n %s > ", name))
default:
execLog = fmt.Sprint(log.Cyan("\n EXECUTE > "), log.Bold(name))
execLog = log.Cyan(fmt.Sprintf("\n %s > ", name))
}

if execLog != "" {
Expand Down

0 comments on commit bec6468

Please sign in to comment.