mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
[rubygems/rubygems] Update gemspec based on provided github username when exists
* Conditionally set changelog_url if gh username passed
and enabled
* conditionally set homepage, source code uri, homepage uri when gh
username passed in
* update documentation to say username will also be used for gemspec file
1c1ada593b
This commit is contained in:
parent
3feba181ed
commit
4ed2757543
5 changed files with 77 additions and 14 deletions
|
@ -47,13 +47,16 @@ module Bundler
|
|||
git_author_name = use_git ? `git config user.name`.chomp : ""
|
||||
git_username = use_git ? `git config github.user`.chomp : ""
|
||||
git_user_email = use_git ? `git config user.email`.chomp : ""
|
||||
github_username = github_username(git_username)
|
||||
|
||||
github_username = if options[:github_username].nil?
|
||||
git_username
|
||||
elsif options[:github_username] == false
|
||||
""
|
||||
if github_username.empty?
|
||||
homepage_uri = "TODO: Put your gem's website or public repo URL here."
|
||||
source_code_uri = "TODO: Put your gem's public repo URL here."
|
||||
changelog_uri = "TODO: Put your gem's CHANGELOG.md URL here."
|
||||
else
|
||||
options[:github_username]
|
||||
homepage_uri = "https://github.com/#{github_username}/#{name}"
|
||||
source_code_uri = "https://github.com/#{github_username}/#{name}"
|
||||
changelog_uri = "https://github.com/#{github_username}/#{name}/blob/main/CHANGELOG.md"
|
||||
end
|
||||
|
||||
config = {
|
||||
|
@ -76,6 +79,9 @@ module Bundler
|
|||
rust_builder_required_rubygems_version: rust_builder_required_rubygems_version,
|
||||
minitest_constant_name: minitest_constant_name,
|
||||
ignore_paths: %w[bin/],
|
||||
homepage_uri: homepage_uri,
|
||||
source_code_uri: source_code_uri,
|
||||
changelog_uri: changelog_uri,
|
||||
}
|
||||
ensure_safe_gem_name(name, constant_array)
|
||||
|
||||
|
@ -479,5 +485,15 @@ module Bundler
|
|||
def standard_version
|
||||
"1.3"
|
||||
end
|
||||
|
||||
def github_username(git_username)
|
||||
if options[:github_username].nil?
|
||||
git_username
|
||||
elsif options[:github_username] == false
|
||||
""
|
||||
else
|
||||
options[:github_username]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -108,7 +108,7 @@ Ignore the current machine's platform and install only \fBruby\fR platform gems\
|
|||
Disallow any automatic changes to \fBGemfile\.lock\fR\. Bundler commands will be blocked unless the lockfile can be installed exactly as written\. Usually this will happen when changing the \fBGemfile\fR manually and forgetting to update the lockfile through \fBbundle lock\fR or \fBbundle install\fR\.
|
||||
.TP
|
||||
\fBgem\.github_username\fR (\fBBUNDLE_GEM__GITHUB_USERNAME\fR)
|
||||
Sets a GitHub username or organization to be used in \fBREADME\fR file when you create a new gem via \fBbundle gem\fR command\. It can be overridden by passing an explicit \fB\-\-github\-username\fR flag to \fBbundle gem\fR\.
|
||||
Sets a GitHub username or organization to be used in the \fBREADME\fR and \fB\.gemspec\fR files when you create a new gem via \fBbundle gem\fR command\. It can be overridden by passing an explicit \fB\-\-github\-username\fR flag to \fBbundle gem\fR\.
|
||||
.TP
|
||||
\fBgem\.push_key\fR (\fBBUNDLE_GEM__PUSH_KEY\fR)
|
||||
Sets the \fB\-\-key\fR parameter for \fBgem push\fR when using the \fBrake release\fR command with a private gemstash server\.
|
||||
|
|
|
@ -131,8 +131,8 @@ learn more about their operation in [bundle install(1)](bundle-install.1.html).
|
|||
Usually this will happen when changing the `Gemfile` manually and forgetting
|
||||
to update the lockfile through `bundle lock` or `bundle install`.
|
||||
* `gem.github_username` (`BUNDLE_GEM__GITHUB_USERNAME`):
|
||||
Sets a GitHub username or organization to be used in `README` file when you
|
||||
create a new gem via `bundle gem` command. It can be overridden by passing an
|
||||
Sets a GitHub username or organization to be used in the `README` and `.gemspec` files
|
||||
when you create a new gem via `bundle gem` command. It can be overridden by passing an
|
||||
explicit `--github-username` flag to `bundle gem`.
|
||||
* `gem.push_key` (`BUNDLE_GEM__PUSH_KEY`):
|
||||
Sets the `--key` parameter for `gem push` when using the `rake release`
|
||||
|
|
|
@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|||
|
||||
spec.summary = "TODO: Write a short summary, because RubyGems requires one."
|
||||
spec.description = "TODO: Write a longer description or delete this line."
|
||||
spec.homepage = "TODO: Put your gem's website or public repo URL here."
|
||||
spec.homepage = "<%= config[:homepage_uri] %>"
|
||||
<%- if config[:mit] -%>
|
||||
spec.license = "MIT"
|
||||
<%- end -%>
|
||||
|
@ -20,10 +20,11 @@ Gem::Specification.new do |spec|
|
|||
<%- end -%>
|
||||
|
||||
spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
||||
|
||||
spec.metadata["homepage_uri"] = spec.homepage
|
||||
spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
||||
spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
||||
spec.metadata["source_code_uri"] = "<%= config[:source_code_uri] %>"
|
||||
<%- if config[:changelog] -%>
|
||||
spec.metadata["changelog_uri"] = "<%= config[:changelog_uri] %>"
|
||||
<%- end -%>
|
||||
|
||||
# Specify which files should be added to the gem when it is released.
|
||||
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
||||
|
|
|
@ -1645,7 +1645,7 @@ RSpec.describe "bundle gem" do
|
|||
end
|
||||
end
|
||||
|
||||
context "without git config set" do
|
||||
context "without git config github.user set" do
|
||||
before do
|
||||
git("config --global --unset github.user")
|
||||
end
|
||||
|
@ -1664,9 +1664,32 @@ RSpec.describe "bundle gem" do
|
|||
end
|
||||
it_behaves_like "--github-username option", "gh_user"
|
||||
end
|
||||
|
||||
context "when changelog is enabled" do
|
||||
it "sets gemspec changelog_uri, homepage, homepage_uri, source_code_uri to TODOs" do
|
||||
bundle "gem #{gem_name} --changelog"
|
||||
|
||||
expect(generated_gemspec.metadata["changelog_uri"]).
|
||||
to eq("TODO: Put your gem's CHANGELOG.md URL here.")
|
||||
expect(generated_gemspec.homepage).to eq("TODO: Put your gem's website or public repo URL here.")
|
||||
expect(generated_gemspec.metadata["homepage_uri"]).to eq("TODO: Put your gem's website or public repo URL here.")
|
||||
expect(generated_gemspec.metadata["source_code_uri"]).to eq("TODO: Put your gem's public repo URL here.")
|
||||
end
|
||||
end
|
||||
|
||||
context "when changelog is not enabled" do
|
||||
it "sets gemspec homepage, homepage_uri, source_code_uri to TODOs and changelog_uri to nil" do
|
||||
bundle "gem #{gem_name}"
|
||||
|
||||
expect(generated_gemspec.metadata["changelog_uri"]).to be_nil
|
||||
expect(generated_gemspec.homepage).to eq("TODO: Put your gem's website or public repo URL here.")
|
||||
expect(generated_gemspec.metadata["homepage_uri"]).to eq("TODO: Put your gem's website or public repo URL here.")
|
||||
expect(generated_gemspec.metadata["source_code_uri"]).to eq("TODO: Put your gem's public repo URL here.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with git config set" do
|
||||
context "with git config github.user set" do
|
||||
context "with github-username option in bundle config settings set to some value" do
|
||||
before do
|
||||
global_config "BUNDLE_GEM__GITHUB_USERNAME" => "different_username"
|
||||
|
@ -1682,6 +1705,29 @@ RSpec.describe "bundle gem" do
|
|||
end
|
||||
it_behaves_like "--github-username option", "gh_user"
|
||||
end
|
||||
|
||||
context "when changelog is enabled" do
|
||||
it "sets gemspec changelog_uri, homepage, homepage_uri, source_code_uri based on git username" do
|
||||
bundle "gem #{gem_name} --changelog"
|
||||
|
||||
expect(generated_gemspec.metadata["changelog_uri"]).
|
||||
to eq("https://github.com/bundleuser/#{gem_name}/blob/main/CHANGELOG.md")
|
||||
expect(generated_gemspec.homepage).to eq("https://github.com/bundleuser/#{gem_name}")
|
||||
expect(generated_gemspec.metadata["homepage_uri"]).to eq("https://github.com/bundleuser/#{gem_name}")
|
||||
expect(generated_gemspec.metadata["source_code_uri"]).to eq("https://github.com/bundleuser/#{gem_name}")
|
||||
end
|
||||
end
|
||||
|
||||
context "when changelog is not enabled" do
|
||||
it "sets gemspec source_code_uri, homepage, homepage_uri but not changelog_uri" do
|
||||
bundle "gem #{gem_name}"
|
||||
|
||||
expect(generated_gemspec.metadata["changelog_uri"]).to be_nil
|
||||
expect(generated_gemspec.homepage).to eq("https://github.com/bundleuser/#{gem_name}")
|
||||
expect(generated_gemspec.metadata["homepage_uri"]).to eq("https://github.com/bundleuser/#{gem_name}")
|
||||
expect(generated_gemspec.metadata["source_code_uri"]).to eq("https://github.com/bundleuser/#{gem_name}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "standard gem naming" do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue