Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3390 from gjtorikian/go-fund-me
Add `bundle fund` command (cherry picked from commit ce27b98)
- Loading branch information
1 parent
89efb05
commit 6756d3c
Showing
13 changed files
with
282 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
module Bundler | ||
class CLI::Fund | ||
attr_reader :options | ||
|
||
def initialize(options) | ||
@options = options | ||
end | ||
|
||
def run | ||
Bundler.definition.validate_runtime! | ||
|
||
groups = Array(options[:group]).map(&:to_sym) | ||
|
||
deps = if groups.any? | ||
Bundler.definition.dependencies_for(groups) | ||
else | ||
Bundler.definition.current_dependencies | ||
end | ||
|
||
fund_info = deps.each_with_object([]) do |dep, arr| | ||
spec = Bundler.definition.specs[dep.name].first | ||
if spec.metadata.key?("funding_uri") | ||
arr << "* #{spec.name} (#{spec.version})\n Funding: #{spec.metadata["funding_uri"]}" | ||
end | ||
end | ||
|
||
if fund_info.empty? | ||
Bundler.ui.info "None of the installed gems you directly depend on are looking for funding." | ||
else | ||
Bundler.ui.info fund_info.join("\n") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe "bundle fund" do | ||
it "prints fund information for all gems in the bundle" do | ||
install_gemfile <<-G | ||
source "#{file_uri_for(gem_repo1)}" | ||
gem 'has_metadata' | ||
gem 'has_funding' | ||
gem 'rack-obama' | ||
G | ||
|
||
bundle "fund" | ||
|
||
expect(out).to include("* has_metadata (1.0)\n Funding: https://example.com/has_metadata/funding") | ||
expect(out).to include("* has_funding (1.2.3)\n Funding: https://example.com/has_funding/funding") | ||
expect(out).to_not include("rack-obama") | ||
end | ||
|
||
it "does not consider fund information for gem dependencies" do | ||
install_gemfile <<-G | ||
source "#{file_uri_for(gem_repo1)}" | ||
gem 'gem_with_dependent_funding' | ||
G | ||
|
||
bundle "fund" | ||
|
||
expect(out).to_not include("* has_funding (1.2.3)\n Funding: https://example.com/has_funding/funding") | ||
expect(out).to_not include("gem_with_dependent_funding") | ||
end | ||
|
||
it "prints message if none of the gems have fund information" do | ||
install_gemfile <<-G | ||
source "#{file_uri_for(gem_repo1)}" | ||
gem 'rack-obama' | ||
G | ||
|
||
bundle "fund" | ||
|
||
expect(out).to include("None of the installed gems you directly depend on are looking for funding.") | ||
end | ||
|
||
describe "with --group option" do | ||
it "prints fund message for only specified group gems" do | ||
install_gemfile <<-G | ||
source "#{file_uri_for(gem_repo1)}" | ||
gem 'has_metadata', :group => :development | ||
gem 'has_funding' | ||
G | ||
|
||
bundle "fund --group development" | ||
expect(out).to include("* has_metadata (1.0)\n Funding: https://example.com/has_metadata/funding") | ||
expect(out).to_not include("* has_funding (1.2.3)\n Funding: https://example.com/has_funding/funding") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe "bundle install" do | ||
context "with gem sources" do | ||
context "when gems include a fund URI" do | ||
it "displays the plural fund message after installing" do | ||
install_gemfile <<-G | ||
source "#{file_uri_for(gem_repo1)}" | ||
gem 'has_metadata' | ||
gem 'has_funding' | ||
gem 'rack-obama' | ||
G | ||
|
||
expect(out).to include("2 installed gems you directly depend on are looking for funding.") | ||
end | ||
|
||
it "displays the singular fund message after installing" do | ||
install_gemfile <<-G | ||
source "#{file_uri_for(gem_repo1)}" | ||
gem 'has_funding' | ||
gem 'rack-obama' | ||
G | ||
|
||
expect(out).to include("1 installed gem you directly depend on is looking for funding.") | ||
end | ||
end | ||
|
||
context "when gems do not include fund messages" do | ||
it "does not display any fund messages" do | ||
install_gemfile <<-G | ||
source "#{file_uri_for(gem_repo1)}" | ||
gem "activesupport" | ||
G | ||
|
||
expect(out).not_to include("gem you depend on") | ||
end | ||
end | ||
|
||
context "when a dependency includes a fund message" do | ||
it "does not display the fund message" do | ||
install_gemfile <<-G | ||
source "#{file_uri_for(gem_repo1)}" | ||
gem 'gem_with_dependent_funding' | ||
G | ||
|
||
expect(out).not_to include("gem you depend on") | ||
end | ||
end | ||
end | ||
|
||
context "with git sources" do | ||
context "when gems include fund URI" do | ||
it "displays the fund message after installing" do | ||
build_git "also_has_funding" do |s| | ||
s.metadata = { | ||
"funding_uri" => "https://example.com/also_has_funding/funding", | ||
} | ||
end | ||
install_gemfile <<-G | ||
source "#{file_uri_for(gem_repo1)}" | ||
gem 'also_has_funding', :git => '#{lib_path("also_has_funding-1.0")}' | ||
G | ||
|
||
expect(out).to include("1 installed gem you directly depend on is looking for funding.") | ||
end | ||
|
||
it "displays the fund message if repo is updated" do | ||
build_git "also_has_funding" do |s| | ||
s.metadata = { | ||
"funding_uri" => "https://example.com/also_has_funding/funding", | ||
} | ||
end | ||
install_gemfile <<-G | ||
source "#{file_uri_for(gem_repo1)}" | ||
gem 'also_has_funding', :git => '#{lib_path("also_has_funding-1.0")}' | ||
G | ||
|
||
build_git "also_has_funding", "1.1" do |s| | ||
s.metadata = { | ||
"funding_uri" => "https://example.com/also_has_funding/funding", | ||
} | ||
end | ||
install_gemfile <<-G | ||
source "#{file_uri_for(gem_repo1)}" | ||
gem 'also_has_funding', :git => '#{lib_path("also_has_funding-1.1")}' | ||
G | ||
|
||
expect(out).to include("1 installed gem you directly depend on is looking for funding.") | ||
end | ||
|
||
it "displays the fund message if repo is not updated" do | ||
build_git "also_has_funding" do |s| | ||
s.metadata = { | ||
"funding_uri" => "https://example.com/also_has_funding/funding", | ||
} | ||
end | ||
gemfile <<-G | ||
source "#{file_uri_for(gem_repo1)}" | ||
gem 'also_has_funding', :git => '#{lib_path("also_has_funding-1.0")}' | ||
G | ||
|
||
bundle :install | ||
expect(out).to include("1 installed gem you directly depend on is looking for funding.") | ||
|
||
bundle :install | ||
expect(out).to include("1 installed gem you directly depend on is looking for funding.") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe "bundle update" do | ||
before do | ||
gemfile <<-G | ||
source "#{file_uri_for(gem_repo1)}" | ||
gem 'has_metadata' | ||
gem 'has_funding', '< 2.0' | ||
G | ||
|
||
bundle :install | ||
end | ||
|
||
context "when listed gems are updated" do | ||
before do | ||
gemfile <<-G | ||
source "#{file_uri_for(gem_repo1)}" | ||
gem 'has_metadata' | ||
gem 'has_funding' | ||
G | ||
|
||
bundle :update, :all => true | ||
end | ||
|
||
it "displays fund message" do | ||
expect(out).to include("2 installed gems you directly depend on are looking for funding.") | ||
end | ||
end | ||
end |