Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

bundle inject with source and group options #5456

Merged
merged 8 commits into from
Apr 7, 2017

Conversation

Shekharrajak
Copy link
Contributor

@Shekharrajak Shekharrajak commented Feb 21, 2017

Fixes #5452

Eg

$ bundle inject "bootstrap" ">0" --source=https://rubygems.org --group=development
Fetching gem metadata from https://rubygems.org/............
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Fetching gem metadata from https://rubygems.org/.............
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Added to Gemfile:
  bootstrap (> 0), group => [:development], :source => 'https://rubygems.org'

In GemFile

gem 'bootstrap', '> 0', :group => [:development], :source => 'https://rubygems.org'

Multiple group :

$ dbundle inject "bootstrap" ">0" --source=https://rubygems.org --group=development,production
Fetching gem metadata from https://rubygems.org/............

Added to Gemfile:
gem 'bootstrap', '> 0', :group => [:development, :production], :source => 'https://rubygems.org'

In gemfile

# Added at 2017-03-24 11:40:51 +0530 by shekharrajak:
gem 'bootstrap', '> 0', :group => [:development, :production], :source => 'https://rubygems.org'

@Shekharrajak Shekharrajak force-pushed the 5452_bundle_inject_options branch 3 times, most recently from f58089b to b7689f4 Compare February 21, 2017 07:17
@Shekharrajak Shekharrajak force-pushed the 5452_bundle_inject_options branch from b7689f4 to 67ee37f Compare February 21, 2017 08:31
@@ -31,7 +31,7 @@ def run

if added.any?
Bundler.ui.confirm "Added to Gemfile:"
Bundler.ui.confirm added.map {|g| " #{g}" }.join("\n")
Bundler.ui.confirm added.map {|g| " #{g}, group => #{g.groups.inspect}, :source => '#{g.source}'" }.join("\n")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably use source.dump

Copy link
Contributor Author

@Shekharrajak Shekharrajak Feb 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't understand what this means ? @segiddins, Can you tell me what should be replaced.

Edit : I have edited the line :source => '#{g.source.dump}'" . Thanks for review.

@@ -52,6 +52,29 @@
end
end

context "use source and group options" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please separate the source and group options into separate contexts

gemfile = bundled_app("Gemfile").read
str = "gem 'bootstrap', '> 0', :source => 'https://rubygems.org'"
expect(gemfile).to match(/str/)
end
Copy link
Member

@colby-swandale colby-swandale Feb 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to use include instead if we're not using a regex with match. Example:

expect(gemfile).to include "gem 'bootstrap', '> 0', :source => 'https://rubygems.org'"

Same with the other expectations below as well.

@@ -465,10 +465,14 @@ def platform
end

desc "inject GEM VERSION", "Add the named gem, with version requirements, to the resolved Gemfile"
method_option "source", :type => :string, :banner =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "install gem from the given source" and "Install gem into a bundler group"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for review @colby-swandale . I have edited the PR according to to your comments.

@Shekharrajak Shekharrajak force-pushed the 5452_bundle_inject_options branch from 45345b0 to 15a0208 Compare February 21, 2017 11:40
@Shekharrajak
Copy link
Contributor Author

Shekharrajak commented Feb 22, 2017

I didn't get why I am getting https://travis-ci.org/bundler/bundler/jobs/203772974#L425 error in test, while it is working fine when we run this
$ dbundle inject "bootstrap" ">0" --source=https://rubygems.org --group=development in terminal.

I think this is the main error Could not reach host index.rubygems.org. Check your network connection and try again. But it must go to rubygems.org (not index.rubygems.org)

Edit : This issue is fixed (Now I am using repo source file for the testcase).

@Shekharrajak Shekharrajak force-pushed the 5452_bundle_inject_options branch 2 times, most recently from 7e2aae7 to dd31394 Compare February 22, 2017 07:12
@Shekharrajak Shekharrajak force-pushed the 5452_bundle_inject_options branch from dd31394 to b78a3f0 Compare February 22, 2017 07:14
@Shekharrajak
Copy link
Contributor Author

I have done the required changes and travis build passed as well. Please review it now.

@Shekharrajak
Copy link
Contributor Author

Ping @colby-swandale @segiddins @indirect , please review.

@colby-swandale
Copy link
Member

Please be patient, we will get around to reviewing the PR when we can.

@@ -31,7 +31,7 @@ def run

if added.any?
Bundler.ui.confirm "Added to Gemfile:"
Bundler.ui.confirm added.map {|g| " #{g}" }.join("\n")
Bundler.ui.confirm added.map {|g| " #{g}, group => #{g.groups.inspect}, :source => '#{g.source.dump}'" }.join("\n")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should only include the groups and the source if they're passed in

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for review. I have added new msg in this commit

end

context "with group option" do
it "add gem with group option in gemfile" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also add a test for including multiple groups

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for review I have added the testcase for multiple groups in this commit

@colby-swandale
Copy link
Member

ping @Shekharrajak

@Shekharrajak
Copy link
Contributor Author

Sorry I completely missed the notification. I will edit the PR accordingly soon.

@Shekharrajak
Copy link
Contributor Author

@colby-swandale , @segiddins Please review once when you get time . Thanks!

Copy link
Member

@segiddins segiddins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 other than the one question

it "add gem with multiple group in gemfile" do
bundle "inject 'rack-obama' '>0' --group=development,test"
gemfile = bundled_app("Gemfile").read
str = "gem 'rack-obama', '> 0', :group => [:development, :test]"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be groups instead of group?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @segiddins for review. I have edited the line in this commit 1f466c0

Sorry for the silly mistake.

Copy link
Contributor Author

@Shekharrajak Shekharrajak Mar 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I edited this line : "add gem with multiple group in gemfile" to "add gem with multiple groups in gemfile"

and I think this line : gem 'rack-obama', '> 0', :group => [:development, :test] is correct. I followed this link : http://bundler.io/v1.3/groups.html examples .

it "add gem with multiple groups in gemfile" do
bundle "inject 'rack-obama' '>0' --group=development,test"
gemfile = bundled_app("Gemfile").read
str = "gem 'rack-obama', '> 0', :group => [:development, :test]"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this still reads group, and given it's the key for an array it should be groups

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@segiddins , I saw example here : http://bundler.io/v1.3/groups.html . In gemfile it must be :group => [:development, :test] right ? I haven't see groups in gemfile.

To install all dependencies, except those in specified groups
we do something :

$ bundle install --without test development

will it work when we write groups ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it can be groups as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @segiddins , I have changed it in this commit 1754e50

@Shekharrajak Shekharrajak force-pushed the 5452_bundle_inject_options branch from a4554f1 to 1754e50 Compare April 5, 2017 05:02
if d.groups != Array(:default)
group =
if d.groups.size == 1
", :group => #{d.groups.inspect}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's just one group, we shouldn't need to put it in an array

@segiddins
Copy link
Member

@colby-swandale r?

@colby-swandale
Copy link
Member

@bundlerbot r+

@bundlerbot
Copy link
Collaborator

📌 Commit 1754e50 has been approved by colby-swandale

@bundlerbot
Copy link
Collaborator

⌛ Testing commit 1754e50 with merge 32fb832...

bundlerbot added a commit that referenced this pull request Apr 7, 2017
…y-swandale

`bundle inject` with source and group options

Fixes #5452

Eg

```
$ bundle inject "bootstrap" ">0" --source=https://rubygems.org --group=development
Fetching gem metadata from https://rubygems.org/............
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Fetching gem metadata from https://rubygems.org/.............
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Added to Gemfile:
  bootstrap (> 0), group => [:development], :source => 'https://rubygems.org'
```

In GemFile

```
gem 'bootstrap', '> 0', :group => [:development], :source => 'https://rubygems.org'
```

### Multiple group :

```
$ dbundle inject "bootstrap" ">0" --source=https://rubygems.org --group=development,production
Fetching gem metadata from https://rubygems.org/............

Added to Gemfile:
gem 'bootstrap', '> 0', :group => [:development, :production], :source => 'https://rubygems.org'

```
In gemfile

```
# Added at 2017-03-24 11:40:51 +0530 by shekharrajak:
gem 'bootstrap', '> 0', :group => [:development, :production], :source => 'https://rubygems.org'
```
@bundlerbot
Copy link
Collaborator

☀️ Test successful - status-travis
Approved by: colby-swandale
Pushing 32fb832 to master...

@bundlerbot bundlerbot merged commit 1754e50 into rubygems:master Apr 7, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants