如何使用 Ruby 检测 png、jpg 图像?

How to detect png, jpg images using Ruby?

只是尝试使用 DangerFile 在 github 拉取请求中检测 png 和 jpg 图像。 这是我找到的所有东西

modified_files_has_wrong_pic_formant = git.modified_files.any? { |file| /.*\.(png|jpg)/.match(File.extname(file)) }
added_files_has_wrong_pic_formant = git.added_files.any? { |file| /.*\.(png|jpg)/.match(File.extname(file)) }

它有效吗?或者您能提出更好的解决方案吗?

像这样的东西应该可以工作

failure "Don't commit PNG/JPG" if (git.added_files + git.modified_files).any?(/\.(png|jpg)\z/)

检查 PR 中所有未以 .png.jpg

结尾的文件