get filename relative to git repo instead of SimpleCov.root
vaneyckt opened this issue ยท 12 comments
Heyo,
this line only gives back correct info if your rails project is at the root of your github repo.
If the rails project is not at the root, then it might be better to use
`git rev-parse HEAD`.chomp
instead of
SimpleCov.root
Hey, thank you for the suggestion. I'll give it a shot.
PS awesome avatar ๐
haha. Thanks Steve :). I'm worried that my suggestion will only work for git repos though. So perhaps it might be good to have some kind of fallback to the current behaviour if the code is not being run from a git repo? Possible way to check for a git repo.
oh wait, what am I saying git rev-parse HEAD
is the wrong command. Gimme a sec to get my head straight.
`git rev-parse --show-toplevel`.chomp
is the command you want. Apologies. It's been a long day :).
gah
`git rev-parse --show-toplevel`.strip!
that's the one. You need strip!
as OSX machines tend to add a newline char at the end there.
Ok, I see. :) I like the technique here. I'll need to add this same concept to the other uploadering utils too. Thanks!
I just realized I might be able to monkeypatch Simplecov and have the root
method return the root of the git repo. I'll let you know if I can get that working as a work-around. If it does, you could put it in the docs somewhere. The nice thing about that approach would be that you would not need to modify any code.
I feel really dumb about me opening this issue now. In the end I could just solve the problem by monkeypatching the relevant codecov-ruby call. Currently my spec_helper.rb
file looks as follows.
# codecov integration
require "simplecov"
SimpleCov.start
if ENV["JENKINS_URL"] != nil
require "codecov"
class SimpleCov::Formatter::Codecov
def shortened_filename(file)
file.filename.gsub(`git rev-parse --show-toplevel`.strip!, '.').gsub(%r{^\.\/}, '')
end
end
SimpleCov.formatter = SimpleCov::Formatter::Codecov
end
Alternatively, it is possible to change the output of SimpleCov.root
by calling SimpleCov.root(<path to new root>)
, but I cannot recommend this approach as your customers might have other gems installed that rely on SimpleCov.root
.
Honestly this is good stuff! My goal is to make this process so simple that monkey patches are never needed.
I'll review these concepts and improve the process accordingly ๐
thanks Steve. I've said it before, but the CodeCov tools really show a lot of thought having gone into them. I especially liked how this ruby gem even has functionality to deal with scenarios caused by people forgetting to disable WebMock for the codecov endpoint. Those things matter a lot when you're integrating a coverage tool. Keep up the amazing work!
Thanks @vaneyckt :) We are really trying to make this a simple and streamline product! ๐
I think this has been fixed above ^