ruby-changes:70081
From: Jean <ko1@a...>
Date: Mon, 6 Dec 2021 20:27:41 +0900 (JST)
Subject: [ruby-changes:70081] 715a51a0d6 (master): [rubygems/rubygems] FeatuRe: accept pull request URLs as github source
https://git.ruby-lang.org/ruby.git/commit/?id=715a51a0d6 From 715a51a0d6963f9d727191d4e1ad0690fd28c4dd Mon Sep 17 00:00:00 2001 From: Jean Boussier <jean.boussier@g...> Date: Thu, 2 Dec 2021 12:59:45 +0100 Subject: [rubygems/rubygems] Feature: accept pull request URLs as github source Very often github source is used to temporarily use a modified gem while a PR upstream is being reviewed. So for instance https://github.com/ruby/bigdecimal/pull/211 will look like: ```ruby gem "bigdecimal", github: "casperisfine/bigdecimal", branch: "git-gem" # https://github.com/ruby/bigdecimal/pull/200 ``` It's annoying because you have to fiddle with the branch name, which is copied as `casperisfine:git-gem`, etc etc. If I could simply use the PR URL like this: ``` gem "bigdecimal", github: "https://github.com/ruby/bigdecimal/pull/211" ``` It would make a very common task for me so much simpler. https://github.com/rubygems/rubygems/commit/517c527751 --- lib/bundler/dsl.rb | 21 ++++++++++++++++++--- lib/bundler/man/bundle-add.1 | 2 +- lib/bundler/man/bundle-binstubs.1 | 2 +- lib/bundler/man/bundle-cache.1 | 2 +- lib/bundler/man/bundle-check.1 | 2 +- lib/bundler/man/bundle-clean.1 | 2 +- lib/bundler/man/bundle-config.1 | 2 +- lib/bundler/man/bundle-doctor.1 | 2 +- lib/bundler/man/bundle-exec.1 | 2 +- lib/bundler/man/bundle-gem.1 | 2 +- lib/bundler/man/bundle-info.1 | 2 +- lib/bundler/man/bundle-init.1 | 2 +- lib/bundler/man/bundle-inject.1 | 2 +- lib/bundler/man/bundle-install.1 | 2 +- lib/bundler/man/bundle-list.1 | 2 +- lib/bundler/man/bundle-lock.1 | 2 +- lib/bundler/man/bundle-open.1 | 2 +- lib/bundler/man/bundle-outdated.1 | 2 +- lib/bundler/man/bundle-platform.1 | 2 +- lib/bundler/man/bundle-pristine.1 | 2 +- lib/bundler/man/bundle-remove.1 | 2 +- lib/bundler/man/bundle-show.1 | 2 +- lib/bundler/man/bundle-update.1 | 2 +- lib/bundler/man/bundle-viz.1 | 2 +- lib/bundler/man/bundle.1 | 2 +- lib/bundler/man/gemfile.5 | 28 +++++++++++++++++++++++++++- lib/bundler/man/gemfile.5.ronn | 8 ++++++++ spec/bundler/bundler/dsl_spec.rb | 39 +++++++++++++++++++++++++++++++++++++++ 28 files changed, 116 insertions(+), 28 deletions(-) diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index ed7b3e2d6b7..1108fc3b781 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -18,6 +18,8 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/dsl.rb#L18 VALID_KEYS = %w[group groups git path glob name branch ref tag require submodules platform platforms type source install_if gemfile].freeze + GITHUB_PULL_REQUEST_URL = %r{\Ahttps://github\.com/([A-Za-z0-9_\-\.]+/[A-Za-z0-9_\-\.]+)/pull/(\d+)\z}.freeze + attr_reader :gemspecs attr_accessor :dependencies @@ -278,8 +280,17 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/dsl.rb#L280 warn_deprecated_git_source(:github, <<-'RUBY'.strip, 'Change any "reponame" :github sources to "username/reponame".') "https://github.com/#{repo_name}.git" RUBY - repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") - "https://github.com/#{repo_name}.git" + if repo_name =~ GITHUB_PULL_REQUEST_URL + { + "git" => "https://github.com/#{$1}.git", + "branch" => "refs/pull/#{$2}/head", + "ref" => nil, + "tag" => nil, + } + else + repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") + "https://github.com/#{repo_name}.git" + end end git_source(:gist) do |repo_name| @@ -365,7 +376,11 @@ repo_name ||= user_name https://github.com/ruby/ruby/blob/trunk/lib/bundler/dsl.rb#L376 git_name = (git_names & opts.keys).last if @git_sources[git_name] - opts["git"] = @git_sources[git_name].call(opts[git_name]) + git_opts = @git_sources[git_name].call(opts[git_name]) + git_opts = { "git" => git_opts } if git_opts.is_a?(String) + opts.merge!(git_opts) do |key, _gemfile_value, _git_source_value| + raise GemfileError, %(The :#{key} option can't be used with `#{git_name}: #{opts[git_name].inspect}`) + end end %w[git path].each do |type| diff --git a/lib/bundler/man/bundle-add.1 b/lib/bundler/man/bundle-add.1 index 1d1e32e2e50..a94467e25f3 100644 --- a/lib/bundler/man/bundle-add.1 +++ b/lib/bundler/man/bundle-add.1 @@ -1,7 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/bundler/man/bundle-add.1#L1 .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-ADD" "1" "November 2021" "" "" +.TH "BUNDLE\-ADD" "1" "December 2021" "" "" . .SH "NAME" \fBbundle\-add\fR \- Add gem to the Gemfile and run bundle install diff --git a/lib/bundler/man/bundle-binstubs.1 b/lib/bundler/man/bundle-binstubs.1 index 1447c034482..6d1b1d4247d 100644 --- a/lib/bundler/man/bundle-binstubs.1 +++ b/lib/bundler/man/bundle-binstubs.1 @@ -1,7 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/bundler/man/bundle-binstubs.1#L1 .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-BINSTUBS" "1" "November 2021" "" "" +.TH "BUNDLE\-BINSTUBS" "1" "December 2021" "" "" . .SH "NAME" \fBbundle\-binstubs\fR \- Install the binstubs of the listed gems diff --git a/lib/bundler/man/bundle-cache.1 b/lib/bundler/man/bundle-cache.1 index b774bfd39bd..acbdae0df2f 100644 --- a/lib/bundler/man/bundle-cache.1 +++ b/lib/bundler/man/bundle-cache.1 @@ -1,7 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/bundler/man/bundle-cache.1#L1 .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-CACHE" "1" "November 2021" "" "" +.TH "BUNDLE\-CACHE" "1" "December 2021" "" "" . .SH "NAME" \fBbundle\-cache\fR \- Package your needed \fB\.gem\fR files into your application diff --git a/lib/bundler/man/bundle-check.1 b/lib/bundler/man/bundle-check.1 index 1d490ca2ba4..e555c9b3996 100644 --- a/lib/bundler/man/bundle-check.1 +++ b/lib/bundler/man/bundle-check.1 @@ -1,7 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/bundler/man/bundle-check.1#L1 .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-CHECK" "1" "November 2021" "" "" +.TH "BUNDLE\-CHECK" "1" "December 2021" "" "" . .SH "NAME" \fBbundle\-check\fR \- Verifies if dependencies are satisfied by installed gems diff --git a/lib/bundler/man/bundle-clean.1 b/lib/bundler/man/bundle-clean.1 index db13ad2bf53..d4032475240 100644 --- a/lib/bundler/man/bundle-clean.1 +++ b/lib/bundler/man/bundle-clean.1 @@ -1,7 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/bundler/man/bundle-clean.1#L1 .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-CLEAN" "1" "November 2021" "" "" +.TH "BUNDLE\-CLEAN" "1" "December 2021" "" "" . .SH "NAME" \fBbundle\-clean\fR \- Cleans up unused gems in your bundler directory diff --git a/lib/bundler/man/bundle-config.1 b/lib/bundler/man/bundle-config.1 index 94f7b98d9ad..5c07e227fdd 100644 --- a/lib/bundler/man/bundle-config.1 +++ b/lib/bundler/man/bundle-config.1 @@ -1,7 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/bundler/man/bundle-config.1#L1 .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-CONFIG" "1" "November 2021" "" "" +.TH "BUNDLE\-CONFIG" "1" "December 2021" "" "" . .SH "NAME" \fBbundle\-config\fR \- Set bundler configuration options diff --git a/lib/bundler/man/bundle-doctor.1 b/lib/bundler/man/bundle-doctor.1 index 64ae8d1164f..87a7fe5f2f6 100644 --- a/lib/bundler/man/bundle-doctor.1 +++ b/lib/bundler/man/bundle-doctor.1 @@ -1,7 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/bundler/man/bundle-doctor.1#L1 .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-DOCTOR" "1" "November 2021" "" "" +.TH "BUNDLE\-DOCTOR" "1" "December 2021" "" "" . .SH "NAME" \fBbundle\-doctor\fR \- Checks the bundle for common problems diff --git a/lib/bundler/man/bundle-exec.1 b/lib/bundler/man/bundle-exec.1 index 61b9833c357..69adfa7c92c 100644 --- a/lib/bundler/man/bundle-exec.1 +++ b/lib/bundler/man/bundle-exec.1 @@ -1,7 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/bundler/man/bundle-exec.1#L1 .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-EXEC" "1" "November 2021" "" "" +.TH "BUNDLE\-EXEC" "1" "December 2021" "" "" . .SH "NAME" \fBbundle\-exec\fR \- Execute a command in the context of the bundle diff --git a/lib/bundler/man/bundle-gem.1 b/lib/bundler/man/bundle-gem.1 index 42875fc1893..fae5c34e7e9 100644 --- a/lib/bundler/man/bundle-gem.1 +++ b/lib/bundler/man/bundle-gem.1 @@ -1,7 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/bundler/man/bundle-gem.1#L1 .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-GEM" "1" "November 2021" "" "" +.TH "BUNDLE\-GEM" "1" "December 2021" "" "" . .SH "NAME" \fBbundle\-gem\fR \- Generate a project skeleton for creating a rubygem diff --git a/lib/bundler/man/bundle-info.1 b/lib/bundler/man/bundle-info.1 index 0804534c3ec..9e1400ec56c 100644 --- a/lib/bundler/man/bundle-info.1 +++ b/lib/bundler/man/bundle-info.1 @@ -1,7 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/bundler/man/bundle-info.1#L1 .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-INFO" "1" "November 2021" "" "" +.TH "BUNDLE\-INFO" "1" "December 2021" "" "" . .SH "NAME" \fBbundle\-info\fR \- Show information for the given gem in your bundle diff --git a/lib/bundler/man/bundle-init.1 b/lib/bundler/man/bundle-init.1 index 3171452cffd..612d16031c6 100644 --- a/lib/bundler/man/bundle-init.1 +++ b/lib/bundler/man/bundle-init.1 @@ -1,7 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/bundler/man/b (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/