captainhookphp / captainhook

CaptainHook is a very flexible git hook manager for software developers that makes sharing git hooks with your team a breeze.
http://captainhook.info
MIT License
992 stars 86 forks source link

[feature] allow hooks to have a label #212

Closed CircleCode closed 1 year ago

CircleCode commented 1 year ago

This label would be used in the output of the hook, transforming

$ git push --force
pre-push: 
 - \CaptainHook\App\Hook\PHP\Action\Linting                          : done
 - vendor/bin/ecs check -n --memory-limit=2048M --no-progress-bar    : done
 - vendor/bin/phpstan analyse -c api/phpstan.neon.dist --no-inter... : done
 - vendor/bin/phpstan analyse --no-interaction --no-progress --me... : failed
Restored changes from /tmp/CaptainHook/patches/1681469658-03c503c2.patch.

into

$ git push --force
pre-push: 
 - Check php files for syntax errors                                 : done
 - Check php files for linting errors                                : done
 - Run phpstan on new stack                                          : done
 - Run phpstan on legacy                                             : failed
Restored changes from /tmp/CaptainHook/patches/1681469658-03c503c2.patch.

If you're ok with it, I have a local version where label could be put in action's options.

However, I did not find a test for this output.

sebastianfeldmann commented 1 year ago

I don't think options is the right place for it. Options are supposed to focus a the action execution. If it is something we will allow for all Actions and is impacting the execution of the Cap'n then I think config is the better suited place to configure something like that.

             {
                "action": "\\CaptainHook\\App\\Hook\\File\\Action\\MaxSize",
                "config": {
                    "label": "My custom description for this action"
                },
                "options": {
                    "maxSize": "1M"
                }
            },

We would need to include it in Config\Action with something like getLabel(): string and implement it in a way that if no label is specified it will return the action

    public function getLabel(): string
    {
        return (string) ($this->settings[Config::SETTING_LABEL] ?? $this->getAction());
    }

Then we can just change the Runner from outputting $config->getAction() to $config->getLabel()

If you want you can provide a pull request for it, but I should be able to do this pretty quickly as well :)

sebastianfeldmann commented 1 year ago

I will start working on it ;)

sebastianfeldmann commented 1 year ago

This works from 5.16.4

{
    "action": "\\CaptainHook\\App\\Hook\\Message\\Action\\Beams",
    "options": {
        "subjectLength": 50,
        "bodyLineLength": 72
    },
    "config": {
        "label": "Verify commit message format"
    }
}