summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfotanus@gmail.com <Felipe Tanus>2015-05-14 07:00:52 -0300
committerfotanus@gmail.com <Felipe Tanus>2015-05-14 07:00:52 -0300
commit54e416fd45fc47c10c46a20092af51b65e8eda3d (patch)
tree8fae0aed4f563b023d469547446ec6a872242634
parent654e44a1febe1ebc89a43bb986a21f4efa653c6c (diff)
downloadbundler-54e416fd45fc47c10c46a20092af51b65e8eda3d.tar.gz
Distinguish CI command runs
This patch add CI information on the user_agent in order for us to track if a given command was run by a CI, as discussed in #3233.
-rw-r--r--lib/bundler/fetcher.rb17
-rw-r--r--spec/bundler/fetcher_spec.rb16
2 files changed, 33 insertions, 0 deletions
diff --git a/lib/bundler/fetcher.rb b/lib/bundler/fetcher.rb
index 42c6eb6717..936f28331f 100644
--- a/lib/bundler/fetcher.rb
+++ b/lib/bundler/fetcher.rb
@@ -155,6 +155,8 @@ module Bundler
agent << " options/#{Bundler.settings.all.join(",")}"
+ agent << " ci/#{cis.join(",")}" if cis.any?
+
# add a random ID so we can consolidate runs server-side
agent << " " << SecureRandom.hex(8)
@@ -178,6 +180,21 @@ module Bundler
FETCHERS = [Dependency, Index]
+ def cis
+ env_cis = {
+ "TRAVIS" => "travis",
+ "CIRCLECI" => "circle",
+ "SEMAPHORE" => "semaphore",
+ "JENKINS_URL" => "jenkins",
+ "BUILDBOX" => "buildbox",
+ "GO_SERVER_URL" => "go",
+ "SNAP_CI" => "snap",
+ "CI_NAME" => ENV["CI_NAME"],
+ "CI" => "ci"
+ }
+ env_cis.find_all{ |env, ci| ENV[env]}.map{ |env, ci| ci }
+ end
+
def connection
@connection ||= begin
needs_ssl = remote_uri.scheme == "https" ||
diff --git a/spec/bundler/fetcher_spec.rb b/spec/bundler/fetcher_spec.rb
index 0d47bc5e90..543707c6c0 100644
--- a/spec/bundler/fetcher_spec.rb
+++ b/spec/bundler/fetcher_spec.rb
@@ -16,5 +16,21 @@ describe Bundler::Fetcher do
expect(fetcher.user_agent).to match(/ruby\/(\d.)/)
expect(fetcher.user_agent).to match(/options\/foo,bar/)
end
+
+ describe "include CI information" do
+ it "from one CI" do
+ ENV["JENKINS_URL"] = "foo"
+ ci_part = fetcher.user_agent.split(' ').find{|x| x.match(/\Aci\//)}
+ expect(ci_part).to match("jenkins")
+ end
+
+ it "from many CI" do
+ ENV["TRAVIS"] = "foo"
+ ENV["CI_NAME"] = "my_ci"
+ ci_part = fetcher.user_agent.split(' ').find{|x| x.match(/\Aci\//)}
+ expect(ci_part).to match("travis")
+ expect(ci_part).to match("my_ci")
+ end
+ end
end
end