Merge pull request #7580 from tharun208/brew-cask-analytics
Added analytics for cask info
This commit is contained in:
commit
1ebb1c2885
@ -46,6 +46,7 @@ module Cask
|
||||
|
||||
def self.info(cask)
|
||||
puts get_info(cask)
|
||||
::Utils::Analytics.cask_output(cask)
|
||||
end
|
||||
|
||||
def self.title_info(cask)
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
require_relative "shared_examples/requires_cask_token"
|
||||
require_relative "shared_examples/invalid_option"
|
||||
require "utils"
|
||||
|
||||
describe Cask::Cmd::Info, :cask do
|
||||
it_behaves_like "a command that requires a Cask token"
|
||||
@ -139,7 +140,16 @@ describe Cask::Cmd::Info, :cask do
|
||||
EOS
|
||||
end
|
||||
|
||||
it "can run be run with a url twice", :needs_network do
|
||||
it "can run be run with a url twice and returns analytics", :needs_network do
|
||||
analytics = {
|
||||
"analytics" => {
|
||||
"install" => {
|
||||
"30d" => { "docker" => 1000 }, "90d" => { "docker" => 2000 }, "365d" => { "docker" => 3000 }
|
||||
},
|
||||
},
|
||||
}
|
||||
expect(Utils::Analytics).to receive(:formulae_brew_sh_json).twice.with("cask/docker.json")
|
||||
.and_return(analytics)
|
||||
expect {
|
||||
described_class.run("https://raw.githubusercontent.com/Homebrew/homebrew-cask" \
|
||||
"/d0b2c58652ae5eff20a7a4ac93292a08b250912b/Casks/docker.rb")
|
||||
@ -155,6 +165,8 @@ describe Cask::Cmd::Info, :cask do
|
||||
Docker CE
|
||||
==> Artifacts
|
||||
Docker.app (App)
|
||||
==> Analytics
|
||||
install: 1,000 (30 days), 2,000 (90 days), 3,000 (365 days)
|
||||
==> Downloading https://raw.githubusercontent.com/Homebrew/homebrew-cask/d0b2c58652ae5eff20a7a4ac93292a08b250912b/Casks/docker.rb.
|
||||
docker: 2.0.0.2-ce-mac81,30215 (auto_updates)
|
||||
https://www.docker.com/community-edition
|
||||
@ -164,6 +176,8 @@ describe Cask::Cmd::Info, :cask do
|
||||
Docker CE
|
||||
==> Artifacts
|
||||
Docker.app (App)
|
||||
==> Analytics
|
||||
install: 1,000 (30 days), 2,000 (90 days), 3,000 (365 days)
|
||||
EOS
|
||||
end
|
||||
end
|
||||
|
||||
@ -119,7 +119,7 @@ module Utils
|
||||
def output(filter: nil)
|
||||
days = Homebrew.args.days || "30"
|
||||
category = Homebrew.args.category || "install"
|
||||
json = formulae_api_json("analytics/#{category}/#{days}d.json")
|
||||
json = formulae_brew_sh_json("analytics/#{category}/#{days}d.json")
|
||||
return if json.blank? || json["items"].blank?
|
||||
|
||||
os_version = category == "os-version"
|
||||
@ -147,10 +147,7 @@ module Utils
|
||||
table_output(category, days, results, os_version: os_version, cask_install: cask_install)
|
||||
end
|
||||
|
||||
def formula_output(f)
|
||||
json = formulae_api_json("#{formula_path}/#{f}.json")
|
||||
return if json.blank? || json["analytics"].blank?
|
||||
|
||||
def get_analytics(json)
|
||||
full_analytics = Homebrew.args.analytics? || Homebrew.args.verbose?
|
||||
|
||||
ohai "Analytics"
|
||||
@ -179,6 +176,20 @@ module Utils
|
||||
end
|
||||
end
|
||||
|
||||
def formula_output(f)
|
||||
json = formulae_brew_sh_json("#{formula_path}/#{f}.json")
|
||||
return if json.blank? || json["analytics"].blank?
|
||||
|
||||
get_analytics(json)
|
||||
end
|
||||
|
||||
def cask_output(cask)
|
||||
json = formulae_brew_sh_json("#{cask_path}/#{cask}.json")
|
||||
return if json.blank? || json["analytics"].blank?
|
||||
|
||||
get_analytics(json)
|
||||
end
|
||||
|
||||
def custom_prefix_label
|
||||
"custom-prefix"
|
||||
end
|
||||
@ -307,7 +318,7 @@ module Utils
|
||||
end
|
||||
end
|
||||
|
||||
def formulae_api_json(endpoint)
|
||||
def formulae_brew_sh_json(endpoint)
|
||||
return if Homebrew::EnvConfig.no_analytics? || Homebrew::EnvConfig.no_github_api?
|
||||
|
||||
output, = curl_output("--max-time", "5",
|
||||
@ -336,6 +347,10 @@ module Utils
|
||||
"analytics"
|
||||
end
|
||||
alias generic_analytics_path analytics_path
|
||||
|
||||
def cask_path
|
||||
"cask"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user