Rubocop against a string or in-memory blob?

21 views
Skip to first unread message

Walter Lee Davis

unread,
Mar 27, 2015, 1:01:39 PM3/27/15
to phil...@googlegroups.com
I am trying to build a gitlab pre-commit hook that will take a list of changed files and run rubocop against each of them before accepting a push to origin/master.

Rubocop will happily do this sort of thing on the local files, but I believe I only have access to the individual files in a commit as a string or in-memory blob, and I can't see anything in rubocop/commands that would accept either of those.

Any ideas? We want to run this on the Gitlab server, alongside other centralized testers like Jenkins, so we don't have to configure a bunch of individual workstations.

Walter

Charles Treatman

unread,
Mar 30, 2015, 7:03:36 PM3/30/15
to phil...@googlegroups.com
Hi Walter,

In a pre-commit hook, you have access to the files because the hook is running in your local repository, not on the server.  If you're dead set on running rubocop on the server in a pre-receive hook, you could write the files to a temporary directory; you'd have to make sure your hook uses a different temporary directory for each `git push`, and that there's enough disk space on your git server to handle writing out temp files for multiple simultaneous pushes.

That said, I recommend against running rubocop in a pre-receive hook.  You mentioned you're using Jenkins for centralized testing.  Are you using a gitlab hook to run a Jenkins job that verifies each pull request?  If you are, you could modify the Jenkins testing job to run rubocop in addition to running tests.  This has the benefit that individual teams/projects can experiment with different configurations without affecting other teams/projects, which is helpful if you have a lot of legacy code that can't be cleaned up all at once before rubocop is enabled.

Charles
Reply all
Reply to author
Forward
0 new messages