Is there a way to blacklist a set of file paths efficiently using the lines_of_code API?
I would like to warn about excessive changes of lines of code change on a repo, but excludes changes done for tests, third-party dependency, and more. Does this make sense to others?
Hrm, I think this can only really be done by working against the raw diff and counting hunks, but skipping ones from those folders.
I think you can do this with the diff object that the git plugin has, but it'll need to be exposed, which I think is pretty reasonable (it's expose it in the DSL for JS)
Great, thanks @orta. Will give this a try.
@orta can I expose it?
Yep 馃憤
@orta here PR that will close this.
So how would you go about implementing the exclusion of certain file paths from lines_of_code?
@costincalugaru you could do something like:
ignored_change_files = ["src/test", "src/sharedTest"]
lineChanges = 0
git.diff.stats[:files].each do |file, stats|
if ignored_change_files.any? { |path| file.include?(path) }
print "Ignoring file for Big PR calculation #{file}"
else
lineChanges += stats[:insertions] + stats[:deletions]
end
end
if lineChanges > 1000
warn("Big PR: #{lineChanges} lines changed. Consider splitting this PR")
end
Most helpful comment
@costincalugaru you could do something like: