用于检查二进制文件的预接收挂钩
Pre-receive hook to check the binary file
我正在尝试限制在我们的 GitLab 实例中提交的二进制文件(dll、pdf、exe)。如果提交有二进制文件,我的 moto 需要中止提交。我有用于在 Python、
中中止提交的代码
#!/usr/bin/env python3
import os
def scanDir(dirName):
for root, dirs, files in os.walk(dirName):
for fileName in files:
if fileName.split('.')[-1] in ["txt","dll","pdf"]:
return 1
return 0
我在 Gitlab 中的问题在 ruby 中有钩子文件,我的代码在 python 中,所以它在 ruby 代码中不起作用。 (How to load the python file in ruby hook?)
另外我不知道什么是 path 我是否需要让步 def scanDir(dirName):
我已经尽力了,但是我不能在 ruby 因为我是 ruby 的新手。
谁能帮忙添加限制二进制文件的钩子?
GitLab hooks might be in any language.
不清楚为什么不能按原样使用 python 代码。
FWIW,翻译后的代码将是:
def scan_dir(dir_name)
Dir["#{dir_name}/**/*"].any? do |f|
%w|.txt .pdf .dll|.include?(File.extname(f))
end
end
我正在尝试限制在我们的 GitLab 实例中提交的二进制文件(dll、pdf、exe)。如果提交有二进制文件,我的 moto 需要中止提交。我有用于在 Python、
中中止提交的代码#!/usr/bin/env python3
import os
def scanDir(dirName):
for root, dirs, files in os.walk(dirName):
for fileName in files:
if fileName.split('.')[-1] in ["txt","dll","pdf"]:
return 1
return 0
我在 Gitlab 中的问题在 ruby 中有钩子文件,我的代码在 python 中,所以它在 ruby 代码中不起作用。 (How to load the python file in ruby hook?)
另外我不知道什么是 path 我是否需要让步 def scanDir(dirName):
我已经尽力了,但是我不能在 ruby 因为我是 ruby 的新手。
谁能帮忙添加限制二进制文件的钩子?
GitLab hooks might be in any language.
不清楚为什么不能按原样使用 python 代码。
FWIW,翻译后的代码将是:
def scan_dir(dir_name)
Dir["#{dir_name}/**/*"].any? do |f|
%w|.txt .pdf .dll|.include?(File.extname(f))
end
end