spryker/git-hook

Spryker Git钩子

dev-master 2024-09-19 15:41 UTC

This package is auto-updated.

Last update: 2024-09-19 15:41:39 UTC


README

CI Minimum PHP Version PHPStan License

GitHook for Spryker。此工具将为您的本地钩子目录添加Git钩子。

目前,我们只有一个名为pre-commit的钩子。每次提交时都会执行应用的命令。

安装

composer require --dev spryker/git-hook

设置

将Composer脚本添加到您的composer.json文件中

对于核心

    "scripts": {
        "post-install-cmd": [
        "GitHook\\Composer\\Scripts\\HookInstaller::installSprykerHooks",
        "GitHook\\Composer\\Scripts\\HookInstaller::installEcoHooks"
    ],
    "post-update-cmd": [
        "GitHook\\Composer\\Scripts\\HookInstaller::installSprykerHooks",
        "GitHook\\Composer\\Scripts\\HookInstaller::installEcoHooks"
    ]

对于项目

  "scripts": {
    "post-install-cmd": [
      "GitHook\\Composer\\Scripts\\HookInstaller::installProjectHooks"
    ],
    "post-update-cmd": [
      "GitHook\\Composer\\Scripts\\HookInstaller::installProjectHooks"
    ]
  }

这会将git钩子复制到您的.git/hooks/目录。

配置

在项目的根目录放置一个.githook文件。在此文件内您可以配置命令。

您也可以通过创建一个.githook_local文件并忽略它来使用您的私有配置,在项目的.gitignore文件中忽略它。

启用命令

要启用命令,您需要指定它们。一个示例配置可能如下所示

preCommitFileCommands:
    - GitHook\Command\FileCommand\PreCommit\ArchitectureCheckCommand
    - GitHook\Command\FileCommand\PreCommit\CodeStyleCheckCommand
    - GitHook\Command\FileCommand\PreCommit\CodeStyleFixCommand
    - GitHook\Command\FileCommand\PreCommit\PhpMdCheckCommand
    - GitHook\Command\FileCommand\PreCommit\PhpStanCheckCommand

preCommitRepositoryCommands:
    - GitHook\Command\RepositoryCommand\PreCommit\ValidateBranchNameCommand
    - GitHook\Command\RepositoryCommand\PreCommit\GitAddCommand

src/GitHook/Command/FileCommand/src/GitHook/Command/RepositoryCommand/中查看可用的完整命令列表。

注意:GitHook\Command\RepositoryCommand\PreCommit\GitAddCommand将在其他命令更改文件(例如CodeStyleFixCommand)时自动将所有新文件添加到提交中,因此仅在您确实需要时使用它!

PhpStanCheckCommand配置

config:
    phpstan:
        level: 8
        config: .phpstan.neon

命令

我们有两种不同类型的命令。FileCommands将为给定提交的每个文件执行。RepositoryCommands将在整个仓库上执行。