Skip to content

Commit a0e2f4a

Browse files
committed
includes valid module name in go.mod
1 parent 8e6d3fd commit a0e2f4a

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

bundler/lib/bundler/cli/gem.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class CLI::Gem
1616
"test-unit" => "3.0",
1717
}.freeze
1818

19+
DEFAULT_GITHUB_USERNAME = "[USERNAME]"
20+
1921
attr_reader :options, :gem_name, :thor, :name, :target, :extension
2022

2123
def initialize(options, gem_name, thor)
@@ -72,7 +74,7 @@ def run
7274
exe: options[:exe],
7375
bundler_version: bundler_dependency_version,
7476
git: use_git,
75-
github_username: github_username.empty? ? "[USERNAME]" : github_username,
77+
github_username: github_username.empty? ? DEFAULT_GITHUB_USERNAME : github_username,
7678
required_ruby_version: required_ruby_version,
7779
rust_builder_required_rubygems_version: rust_builder_required_rubygems_version,
7880
minitest_constant_name: minitest_constant_name,
@@ -223,6 +225,7 @@ def run
223225
)
224226

225227
config[:go_version] = go_version
228+
config[:go_module_username] = config[:github_username] == DEFAULT_GITHUB_USERNAME ? "username" : config[:github_username]
226229
end
227230

228231
if target.exist? && !target.directory?

bundler/lib/bundler/templates/newgem/ext/newgem/go.mod.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/<%= config[:github_username] %>/<%= config[:underscored_name] %>
1+
module github.com/<%= config[:go_module_username] %>/<%= config[:underscored_name] %>
22

33
go <%= config[:go_version] %>
44

bundler/spec/commands/newgem_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,6 +1668,10 @@ def create_temporary_dir(dir)
16681668
GO
16691669
end
16701670

1671+
it "includes valid module name in go.mod" do
1672+
expect(bundled_app("#{gem_name}/ext/#{gem_name}/go.mod").read).to include("module github.com/bundleuser/#{gem_name}")
1673+
end
1674+
16711675
context "with --no-ci" do
16721676
let(:flags) { "--ext=go --no-ci" }
16731677

@@ -1737,6 +1741,17 @@ def create_temporary_dir(dir)
17371741
expect(bundled_app("#{gem_name}/ext/#{gem_name}/go.mod").read).to include("go #{go_version}")
17381742
end
17391743
end
1744+
1745+
context "without github.user" do
1746+
before do
1747+
git("config --global --unset github.user")
1748+
bundle ["gem", gem_name, flags].compact.join(" ")
1749+
end
1750+
1751+
it "includes valid module name in go.mod" do
1752+
expect(bundled_app("#{gem_name}/ext/#{gem_name}/go.mod").read).to include("module github.com/username/#{gem_name}")
1753+
end
1754+
end
17401755
end
17411756
end
17421757

0 commit comments

Comments
 (0)