如何在自定义预提交挂钩中返回状态“Skipped”?
我有一个自定义的预提交挂钩,如果较早的挂钩失败,我想跳过该挂钩。如果较早的挂钩失败,则会生成名为 pre-commit.log
的日志文件。
.pre-commit-config.yaml
可能如下所示:
repos:
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
log_file: pre-commit.log
- repo: local
hooks:
- id: skript
name: skript
entry: bash skript.sh
language: system
log_file: pre-commit.log
我的 bash skript.sh
如下所示:
if [ -f "pre-commit.log" ]; then
echo "Error in earlier pre-commit! We skip this script."
echo "See 'pre-commit.log' for detailed information."
exit 1
else
echo "All pre-commits successful."
# some other code
fi
现在我检查“pre-commit.log”是否存在,如果存在,我返回exit 1
。因此,该挂钩的输出为 Failed
。但我更喜欢 Skipped
状态,因为没有失败。
我的目标是在控制台或日志文件中看到文本 Skipped
,就像此图中的 jupyter-notebook-cleanup
一样。 如果我写 exit 0
我会得到 Passed
就像 isort
和 black
一样,如果我返回 exit 1
或其他大于 1 的数字,我会得到 Failed
,就像 flake8
一样。
如何获取消息已跳过
?
I have a self defined pre-commit hook which I want to skip if an earlier hook fails. If an earlier hook fails, a logfile named pre-commit.log
is generated.
A .pre-commit-config.yaml
could look like this:
repos:
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
log_file: pre-commit.log
- repo: local
hooks:
- id: skript
name: skript
entry: bash skript.sh
language: system
log_file: pre-commit.log
My bash skript.sh
looks like this:
if [ -f "pre-commit.log" ]; then
echo "Error in earlier pre-commit! We skip this script."
echo "See 'pre-commit.log' for detailed information."
exit 1
else
echo "All pre-commits successful."
# some other code
fi
Right now I check if the "pre-commit.log" exists and if so I return exit 1
. Because of this, the output for this hook is Failed
. But I would prefer the status Skipped
because there was no failure.
My goal is to see in the console or logfile the text Skipped
, like in this image for jupyter-notebook-cleanup
.
If I write exit 0
I get Passed
like for isort
and black
and if I return exit 1
or another number greater 1 I get Failed
like for flake8
.
How can I get the message Skipped
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无法影响文本被
Skipped
Skipped
仅在以下情况下出现:SKIP
中> 环境变量files
/types
/types_or
和pass_filenames
匹配的文件true< /code> (默认)和
always_run
为false
(默认值),您最好的选择是在非失败情况下
exit 0
,这将显示为Passed输出
免责声明中的 :我编写了您正在使用的预提交工具
there is no way to influence that text be
Skipped
Skipped
only appears in the following cases:SKIP
environment variablefiles
/types
/types_or
andpass_filenames
wastrue
(the default) andalways_run
wasfalse
(the default)your best bet is to
exit 0
in the non-failure case, this will appear asPassed
in the outputdisclaimer: I wrote the pre-commit tool you're using