如何在 Gitlab 的 fastapi 预提交钩子中设置条件

how to have condition in the fastapi pre-commit hook in Gitlab

提问人:user2439278 提问时间:10/20/2023 最后编辑:anthony sottileuser2439278 更新时间:10/20/2023 访问量:42

问:

我创建了一个 fastapi 预提交钩子,用于检查 python 代码中的 linting 和格式。 我还添加了一个脚本,该脚本在提交期间递增应用程序版本。即使 linter 失败并阻止提交,版本也会递增。

repos:
  - repo: https://github.com/psf/black
    rev: 23.10.0
    hooks:
      - id: black
        args: ["--check"]
  - repo: local
    hooks:
      - id: flake8
        name: flake8
        entry: flake8
        language: system
        args: ["--output-file=report.xml"]
        files: app
  - repo : local
    hooks:
      - id: pylint
        name: pylint
        entry: ./scripts/pylint_precommit.sh 9.5
        language: script
  - repo : local
    hooks:
      - id: VersionIncrement
        name: VersionIncrement
        entry: ./scripts/version.sh
        language: script      

如何添加条件,仅在 linters,formatters 在 pre-commit 钩子中传递时才增加版本

git gitlab fastapi pre-commit-hook pre-commit.com

评论

1赞 MatsLindh 10/20/2023
你见过 stackoverflow.com/questions/67195842/ 吗?
1赞 anthony sottile 10/20/2023
自动颠簸版本的钩子是一个非常糟糕的主意
0赞 user2439278 10/26/2023
@MatsLindh,IT 工作正常。有没有办法将预提交钩子限制为仅在功能分支上运行?

答: 暂无答案