unwrappr icon indicating copy to clipboard operation
unwrappr copied to clipboard

Cannot annotate pull request without Gemfile

Open orien opened this issue 6 years ago • 2 comments

Unwrappr has difficulty annotating pull requests when executed from a directory without a Gemfile:

$ gem install unwrappr
Successfully installed unwrappr-0.3.2
1 gem installed

$ unwrappr annotate-pull-request --repo orien/my-ruby-project --pr 30
Traceback (most recent call last):
	24: from /usr/local/opt/rbenv/versions/2.5.3/bin/unwrappr:23:in `<main>'
	23: from /usr/local/opt/rbenv/versions/2.5.3/bin/unwrappr:23:in `load'
	22: from /usr/local/Cellar/rbenv/1.1.1/versions/2.5.3/lib/ruby/gems/2.5.0/gems/unwrappr-0.3.2/exe/unwrappr:11:in `<top (required)>'
	21: from /usr/local/Cellar/rbenv/1.1.1/versions/2.5.3/lib/ruby/gems/2.5.0/gems/clamp-1.3.0/lib/clamp/command.rb:140:in `run'
	20: from /usr/local/Cellar/rbenv/1.1.1/versions/2.5.3/lib/ruby/gems/2.5.0/gems/clamp-1.3.0/lib/clamp/command.rb:66:in `run'
	19: from /usr/local/Cellar/rbenv/1.1.1/versions/2.5.3/lib/ruby/gems/2.5.0/gems/clamp-1.3.0/lib/clamp/subcommand/execution.rb:18:in `execute'
	18: from /usr/local/Cellar/rbenv/1.1.1/versions/2.5.3/lib/ruby/gems/2.5.0/gems/clamp-1.3.0/lib/clamp/command.rb:66:in `run'
	17: from /usr/local/Cellar/rbenv/1.1.1/versions/2.5.3/lib/ruby/gems/2.5.0/gems/unwrappr-0.3.2/lib/unwrappr/cli.rb:35:in `execute'
	16: from /usr/local/Cellar/rbenv/1.1.1/versions/2.5.3/lib/ruby/gems/2.5.0/gems/unwrappr-0.3.2/lib/unwrappr/lock_file_annotator.rb:39:in `annotate_github_pull_request'
	15: from /usr/local/Cellar/rbenv/1.1.1/versions/2.5.3/lib/ruby/gems/2.5.0/gems/unwrappr-0.3.2/lib/unwrappr/lock_file_annotator.rb:56:in `annotate'
	14: from /usr/local/Cellar/rbenv/1.1.1/versions/2.5.3/lib/ruby/gems/2.5.0/gems/unwrappr-0.3.2/lib/unwrappr/github/pr_source.rb:19:in `each_file'
	13: from /usr/local/Cellar/rbenv/1.1.1/versions/2.5.3/lib/ruby/gems/2.5.0/gems/unwrappr-0.3.2/lib/unwrappr/github/pr_source.rb:19:in `each'
	12: from /usr/local/Cellar/rbenv/1.1.1/versions/2.5.3/lib/ruby/gems/2.5.0/gems/unwrappr-0.3.2/lib/unwrappr/github/pr_source.rb:20:in `block in each_file'
	11: from /usr/local/Cellar/rbenv/1.1.1/versions/2.5.3/lib/ruby/gems/2.5.0/gems/unwrappr-0.3.2/lib/unwrappr/lock_file_annotator.rb:57:in `block in annotate'
	10: from /usr/local/Cellar/rbenv/1.1.1/versions/2.5.3/lib/ruby/gems/2.5.0/gems/unwrappr-0.3.2/lib/unwrappr/lock_file_diff.rb:18:in `each_gem_change'
	 9: from /usr/local/Cellar/rbenv/1.1.1/versions/2.5.3/lib/ruby/gems/2.5.0/gems/unwrappr-0.3.2/lib/unwrappr/lock_file_diff.rb:33:in `version_changes'
	 8: from /usr/local/Cellar/rbenv/1.1.1/versions/2.5.3/lib/ruby/gems/2.5.0/gems/unwrappr-0.3.2/lib/unwrappr/lock_file_comparator.rb:10:in `perform'
	 7: from /usr/local/Cellar/rbenv/1.1.1/versions/2.5.3/lib/ruby/gems/2.5.0/gems/unwrappr-0.3.2/lib/unwrappr/lock_file_comparator.rb:10:in `new'
	 6: from /usr/local/Cellar/rbenv/1.1.1/versions/2.5.3/lib/ruby/gems/2.5.0/gems/bundler-1.17.1/lib/bundler/lockfile_parser.rb:68:in `initialize'
	 5: from /usr/local/Cellar/rbenv/1.1.1/versions/2.5.3/lib/ruby/gems/2.5.0/gems/bundler-1.17.1/lib/bundler/lockfile_parser.rb:68:in `new'
	 4: from /usr/local/Cellar/rbenv/1.1.1/versions/2.5.3/lib/ruby/gems/2.5.0/gems/bundler-1.17.1/lib/bundler/source/rubygems.rb:24:in `initialize'
	 3: from /usr/local/Cellar/rbenv/1.1.1/versions/2.5.3/lib/ruby/gems/2.5.0/gems/bundler-1.17.1/lib/bundler/source/rubygems.rb:462:in `cache_path'
	 2: from /usr/local/Cellar/rbenv/1.1.1/versions/2.5.3/lib/ruby/gems/2.5.0/gems/bundler-1.17.1/lib/bundler.rb:251:in `app_cache'
	 1: from /usr/local/Cellar/rbenv/1.1.1/versions/2.5.3/lib/ruby/gems/2.5.0/gems/bundler-1.17.1/lib/bundler.rb:233:in `root'
/usr/local/Cellar/rbenv/1.1.1/versions/2.5.3/lib/ruby/gems/2.5.0/gems/bundler-1.17.1/lib/bundler.rb:237:in `rescue in root': Could not locate Gemfile or .bundle/ directory (Bundler::GemfileNotFound)

$ echo $?
1

If I change to a directory containing a Gemfile (any Gemfile will do, even one unrelated to the PR being annotated):

$ cd ~/src/another-ruby-project

$unwrappr annotate-pull-request --repo orien/my-ruby-project --pr 30

$ echo $?
0

orien avatar Nov 14 '18 00:11 orien

Well, that's frustrating!

It seems that when we create, a Bundler::LockfileParser, it creates a Source::Rubygems object, which in turn expects to find its root using either the Gemfile or .bundle.

I ran unwrappr annotate-pull-request -r org/repo -p 1 from $TEMP to reproduce this bug and then created a ${TEMP}/.bundle directory and re-ran successfully, the new directory remained empty after unwrappr had done its thing.

johnsyweb avatar Nov 14 '18 10:11 johnsyweb

Interestingly, setting a BUNDLE_GEMFILE environment variable bypasses the problem:

$ BUNDLE_GEMFILE=egg unwrappr annotate-pull-request --repo org/repo --pr 30

$ echo $?
0

It seems the SharedHelper.root method won't raise an exception if this is environment variable is set.

orien avatar Nov 14 '18 12:11 orien