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