git-trend 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3de2ef516de70662c6b0e2fc26fadb1c474b3b7b
4
- data.tar.gz: 23424ba56d2c4d993448d35174dba801d661140c
3
+ metadata.gz: 99bb0889decc7985ef6ebd3b3fee506d64c5fbaa
4
+ data.tar.gz: 127d52472cff601c90626748d9ff4cb148a053d5
5
5
  SHA512:
6
- metadata.gz: 59767034d3a06bd1a49748a32638db9056b44e31005ee41aaacf50b98f5688a49162e6779850019539f964f594cfd0bbec80963df56889babac94bea72ef92df
7
- data.tar.gz: a04ede690fcfd3610a374f1b882a336c936023b1ace92240b1479192bf71439494c82754c186d3a7a2161d09960a3be13457aee9c65a027948f84c87ce56bd99
6
+ metadata.gz: 396120a4a0cc592a0899edc6295190b09d31d67f67920e09f602de62aa45f210f9f04406e6fd55b9dbdca3c0e368402275cc90863d73bfe959b29f2f406c977b
7
+ data.tar.gz: 339990a96db3c8643d93852cabfd53046cfd16c0abb5380e9d9bde8f8d29baf2e20a825b820692bc632d3c01ef5e5727674086cff91f04cc28f25d87cc6fb92f
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .DS_Store
4
4
  .bundle
5
5
  .config
6
+ .rubocop-*
6
7
  .yardoc
7
8
  Gemfile.lock
8
9
  InstalledFiles
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ inherit_from:
2
+ - https://raw.githubusercontent.com/rails/rails/master/.rubocop.yml
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v1.1.0 (Sat Nov 5 2016)
2
+ - Adapted new github trending [49abccb]
3
+ - Update gems [4051404]
4
+
1
5
  ## v1.0.2 (Fri Apr 1 2016)
2
6
  - Update gems [0d24fae]
3
7
 
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in git-trend.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -27,7 +27,7 @@ Or install it yourself as:
27
27
 
28
28
  $ gem install git-trend
29
29
 
30
- ## Usage Of a gem
30
+ ## Usage of a gem
31
31
 
32
32
  Require it if you haven't:
33
33
 
@@ -76,7 +76,7 @@ GitTrend.get(language: :ruby, since: :weekly)
76
76
 
77
77
  GitTrend.languages
78
78
 
79
- ## Usage Of a command line tool
79
+ ## Usage of a command line tool
80
80
 
81
81
  Use the git-trend as follows:
82
82
 
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'bundler/setup'
4
- require 'git_trend'
3
+ require "bundler/setup"
4
+ require "git_trend"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require 'git_trend'
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require 'irb'
13
+ require "irb"
14
14
  IRB.start
data/exe/git-trend CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
3
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
4
4
 
5
- require 'git_trend'
5
+ require "git_trend"
6
6
 
7
7
  GitTrend::CLI.start
data/git-trend.gemspec CHANGED
@@ -1,12 +1,12 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
2
+ lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'git_trend/version'
4
+ require "git_trend/version"
5
5
 
6
6
  def install_message
7
- s = ''
7
+ s = ""
8
8
  s << "\xf0\x9f\x8d\xba " if or_over_mac_os_lion?
9
- s << 'Thanks for installing!'
9
+ s << "Thanks for installing!"
10
10
  end
11
11
 
12
12
  def or_over_mac_os_lion?
@@ -14,41 +14,41 @@ def or_over_mac_os_lion?
14
14
 
15
15
  macos_full_version = `/usr/bin/sw_vers -productVersion`.chomp
16
16
  macos_version = macos_full_version[/10\.\d+/]
17
- macos_version >= '10.7' # 10.7 is lion
17
+ macos_version >= "10.7" # 10.7 is lion
18
18
  end
19
19
 
20
20
  Gem::Specification.new do |spec|
21
- spec.name = 'git-trend'
21
+ spec.name = "git-trend"
22
22
  spec.version = GitTrend::VERSION
23
- spec.authors = ['rochefort']
24
- spec.email = ['terasawan@gmail.com']
25
- spec.summary = 'CLI-Based tool that show Trending repository on github'
23
+ spec.authors = ["rochefort"]
24
+ spec.email = ["terasawan@gmail.com"]
25
+ spec.summary = "CLI-Based tool that show Trending repository on github"
26
26
  spec.description = spec.summary
27
- spec.homepage = 'https://github.com/rochefort/git-trend'
28
- spec.license = 'MIT'
27
+ spec.homepage = "https://github.com/rochefort/git-trend"
28
+ spec.license = "MIT"
29
29
 
30
30
  spec.files = `git ls-files -z`.split("\x0")
31
- spec.bindir = 'exe'
31
+ spec.bindir = "exe"
32
32
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
33
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
34
- spec.require_paths = ['lib']
34
+ spec.require_paths = ["lib"]
35
35
 
36
36
  spec.post_install_message = install_message
37
37
 
38
- spec.add_dependency 'addressable', '~> 2.4.0'
39
- spec.add_dependency 'mb_string', '~> 0.1.6'
40
- spec.add_dependency 'mechanize', '~> 2.7.4'
41
- spec.add_dependency 'thor', '~> 0.19.1'
42
- spec.add_dependency 'unicode-display_width', '~> 1.0.3'
38
+ spec.add_dependency "addressable", "~> 2.4.0"
39
+ spec.add_dependency "mb_string", "~> 0.1.7"
40
+ spec.add_dependency "mechanize", "~> 2.7.4"
41
+ spec.add_dependency "thor", "~> 0.19.1"
42
+ spec.add_dependency "unicode-display_width", "~> 1.1.1"
43
43
 
44
- spec.add_development_dependency 'bundler', '~> 1.6'
45
- spec.add_development_dependency 'rake', '~> 11.1.2'
44
+ spec.add_development_dependency "bundler", "~> 1.6"
45
+ spec.add_development_dependency "rake", "~> 11.3.0"
46
46
 
47
- spec.add_development_dependency 'rspec', '~> 3.4.0'
48
- spec.add_development_dependency 'simplecov', '~> 0.11.2'
49
- spec.add_development_dependency 'safe_yaml', '~> 1.0.4' # for Ruby2.2.0
50
- spec.add_development_dependency 'webmock', '~> 1.24.2'
47
+ spec.add_development_dependency "rspec", "~> 3.5.0"
48
+ spec.add_development_dependency "simplecov", "~> 0.12.0"
49
+ spec.add_development_dependency "safe_yaml", "~> 1.0.4" # for Ruby2.2.0
50
+ spec.add_development_dependency "webmock", "~> 2.1.0"
51
51
 
52
- spec.add_development_dependency 'coveralls'
53
- spec.add_development_dependency 'codeclimate-test-reporter'
52
+ spec.add_development_dependency "coveralls", "~> 0.8.15"
53
+ spec.add_development_dependency "codeclimate-test-reporter", "~> 1.0.0"
54
54
  end
data/lib/git-trend.rb CHANGED
@@ -1 +1 @@
1
- require 'git_trend'
1
+ require "git_trend"
data/lib/git_trend.rb CHANGED
@@ -1,9 +1,9 @@
1
- require 'mb_string'
1
+ require "mb_string"
2
2
 
3
- require 'git_trend/cli'
4
- require 'git_trend/project'
5
- require 'git_trend/scraper'
6
- require 'git_trend/version'
3
+ require "git_trend/cli"
4
+ require "git_trend/project"
5
+ require "git_trend/scraper"
6
+ require "git_trend/version"
7
7
 
8
8
  module GitTrend
9
9
  class ScrapeException < StandardError; end
data/lib/git_trend/cli.rb CHANGED
@@ -1,28 +1,28 @@
1
- require 'thor'
2
- require 'git_trend/rendering'
1
+ require "thor"
2
+ require "git_trend/rendering"
3
3
 
4
4
  module GitTrend
5
5
  class CLI < Thor
6
6
  include Rendering
7
7
 
8
- map '-v' => :version,
9
- '--version' => :version
8
+ map "-v" => :version,
9
+ "--version" => :version
10
10
 
11
11
  default_command :list
12
12
 
13
- desc :version, 'show version'
13
+ desc :version, "show version"
14
14
  def version
15
15
  say "git-trend version: #{VERSION}", :green
16
16
  end
17
17
 
18
18
  desc :list, "\033[32m(DEFAULT COMMAND)\e[0m List Trending repository on github [-l, -s, -d]"
19
- option :language, aliases: '-l', required: false, desc: 'Specify a language'
20
- option :since, aliases: '-s', required: false, desc: 'Enable: [d, day, daily, w, week, weekly, m, month, monthly]'
21
- option :description, aliases: '-d', required: false, default: true, type: :boolean, desc: "\033[32m(DEFAULT OPTION)\e[0m Dislpay descriptions"
22
- option :number, aliases: '-n', required: false, type: :numeric, desc: 'Number of lines'
23
- option :help, aliases: '-h', required: false, type: :boolean
19
+ option :language, aliases: "-l", required: false, desc: "Specify a language"
20
+ option :since, aliases: "-s", required: false, desc: "Enable: [d, day, daily, w, week, weekly, m, month, monthly]"
21
+ option :description, aliases: "-d", required: false, default: true, type: :boolean, desc: "\033[32m(DEFAULT OPTION)\e[0m Dislpay descriptions"
22
+ option :number, aliases: "-n", required: false, type: :numeric, desc: "Number of lines"
23
+ option :help, aliases: "-h", required: false, type: :boolean
24
24
  def list
25
- help(:list) and return if options[:help]
25
+ help(:list) && return if options[:help]
26
26
  scraper = Scraper.new
27
27
  projects = scraper.get(options[:language], options[:since], options[:number])
28
28
  render(projects, !!options[:description])
@@ -31,7 +31,7 @@ module GitTrend
31
31
  say e.message unless e.class.to_s == e.message
32
32
  end
33
33
 
34
- desc :languages, 'Show selectable languages'
34
+ desc :languages, "Show selectable languages"
35
35
  def languages
36
36
  scraper = Scraper.new
37
37
  languages = scraper.languages
@@ -1,6 +1,14 @@
1
1
  module GitTrend
2
2
  class Project
3
- attr_accessor :name, :lang, :description, :star_count
3
+ attr_accessor :name, :description, :lang, :star_count, :fork_count
4
+
5
+ def initialize(name: "", description: "", lang: "", star_count: 0, fork_count: 0)
6
+ self.name = name
7
+ self.description = description
8
+ self.lang = lang
9
+ self.star_count = star_count
10
+ self.fork_count = fork_count
11
+ end
4
12
 
5
13
  def to_a
6
14
  [@name, @lang, @star_count.to_s]
@@ -25,81 +25,81 @@ module GitTrend
25
25
 
26
26
  private
27
27
 
28
- def rule_columns_sizes(projects)
29
- @columns_sizes = DEFAULT_COLUMNS_SIZES.dup
30
- rule_max_column_size(projects, :name)
31
- rule_max_column_size(projects, :lang)
32
- rule_max_description_size if @enable_description
33
- @columns_sizes.pop unless @enable_description
34
- end
28
+ def rule_columns_sizes(projects)
29
+ @columns_sizes = DEFAULT_COLUMNS_SIZES.dup
30
+ rule_max_column_size(projects, :name)
31
+ rule_max_column_size(projects, :lang)
32
+ rule_max_description_size if @enable_description
33
+ @columns_sizes.pop unless @enable_description
34
+ end
35
35
 
36
- def rule_max_description_size
37
- terminal_width, _terminal_height = detect_terminal_size
38
- description_width = terminal_width - @columns_sizes[0..-2].inject(&:+) - (@columns_sizes.size - 1)
39
- if description_width >= DEFAULT_COLUMNS_SIZES.last
40
- @columns_sizes[-1] = description_width
41
- else
42
- @enable_description = false
36
+ def rule_max_description_size
37
+ terminal_width, _terminal_height = detect_terminal_size
38
+ description_width = terminal_width - @columns_sizes[0..-2].inject(&:+) - (@columns_sizes.size - 1)
39
+ if description_width >= DEFAULT_COLUMNS_SIZES.last
40
+ @columns_sizes[-1] = description_width
41
+ else
42
+ @enable_description = false
43
+ end
43
44
  end
44
- end
45
45
 
46
- def rule_max_column_size(projects, attr)
47
- index = HEADER_COLUMNS.index(attr.to_s)
48
- max_size = max_size_of(projects, attr)
49
- @columns_sizes[index] = max_size if max_size > @columns_sizes[index]
50
- end
46
+ def rule_max_column_size(projects, attr)
47
+ index = HEADER_COLUMNS.index(attr.to_s)
48
+ max_size = max_size_of(projects, attr)
49
+ @columns_sizes[index] = max_size if max_size > @columns_sizes[index]
50
+ end
51
51
 
52
- def max_size_of(projects, attr)
53
- projects.max_by { |project| project.send(attr).size }.send(attr).size
54
- end
52
+ def max_size_of(projects, attr)
53
+ projects.max_by { |project| project.send(attr).size }.send(attr).size
54
+ end
55
55
 
56
- def render_header
57
- header = HEADER_COLUMNS.map(&:capitalize)
58
- header.pop unless @enable_description
59
- f = @columns_sizes
60
- fmt = "%#{f[0]}s %-#{f[1]}s %-#{f[2]}s %#{f[3]}s"
61
- fmt << " %-#{f[4]}s" if @enable_description
56
+ def render_header
57
+ header = HEADER_COLUMNS.map(&:capitalize)
58
+ header.pop unless @enable_description
59
+ f = @columns_sizes
60
+ fmt = "%#{f[0]}s %-#{f[1]}s %-#{f[2]}s %#{f[3]}s"
61
+ fmt << " %-#{f[4]}s" if @enable_description
62
62
 
63
- puts fmt % header
64
- puts fmt % @columns_sizes.map { |column| '-' * column }
65
- end
63
+ puts fmt % header
64
+ puts fmt % @columns_sizes.map { |column| "-" * column }
65
+ end
66
66
 
67
- def render_body(projects)
68
- f = @columns_sizes
69
- fmt = "%#{f[0]}s %-#{f[1]}s %-#{f[2]}s %#{f[3]}s"
70
- description_fmt = ''
71
- projects.each_with_index do |project, i|
72
- data = [i + 1, project.to_a].flatten
73
- if @enable_description
74
- description = project.description.mb_truncate(f.last)
75
- data << description
76
- mb_char_size = description.display_width - description.size
77
- description_fmt = " %-#{f.last - mb_char_size}s"
67
+ def render_body(projects)
68
+ f = @columns_sizes
69
+ fmt = "%#{f[0]}s %-#{f[1]}s %-#{f[2]}s %#{f[3]}s"
70
+ description_fmt = ""
71
+ projects.each_with_index do |project, i|
72
+ data = [i + 1, project.to_a].flatten
73
+ if @enable_description
74
+ description = project.description.mb_truncate(f.last)
75
+ data << description
76
+ mb_char_size = description.display_width - description.size
77
+ description_fmt = " %-#{f.last - mb_char_size}s"
78
+ end
79
+ result = "#{fmt}#{description_fmt}" % data
80
+ puts result
78
81
  end
79
- result = "#{fmt}#{description_fmt}" % data
80
- puts result
81
82
  end
82
- end
83
83
 
84
- def render_footer
85
- puts
86
- end
84
+ def render_footer
85
+ puts
86
+ end
87
87
 
88
- # https://github.com/cldwalker/hirb/blob/master/lib/hirb/util.rb#L61-71
89
- def detect_terminal_size
90
- if (ENV['COLUMNS'] =~ /^\d+$/) && (ENV['LINES'] =~ /^\d+$/)
91
- [ENV['COLUMNS'].to_i, ENV['LINES'].to_i]
92
- elsif (RUBY_PLATFORM =~ /java/ || (!STDIN.tty? && ENV['TERM'])) && command_exists?('tput')
93
- [`tput cols`.to_i, `tput lines`.to_i]
94
- elsif STDIN.tty? && command_exists?('stty')
95
- `stty size`.scan(/\d+/).map(&:to_i).reverse
88
+ # https://github.com/cldwalker/hirb/blob/master/lib/hirb/util.rb#L61-71
89
+ def detect_terminal_size
90
+ if (ENV["COLUMNS"] =~ /^\d+$/) && (ENV["LINES"] =~ /^\d+$/)
91
+ [ENV["COLUMNS"].to_i, ENV["LINES"].to_i]
92
+ elsif (RUBY_PLATFORM =~ /java/ || (!STDIN.tty? && ENV["TERM"])) && command_exists?("tput")
93
+ [`tput cols`.to_i, `tput lines`.to_i]
94
+ elsif STDIN.tty? && command_exists?("stty")
95
+ `stty size`.scan(/\d+/).map(&:to_i).reverse
96
+ end
97
+ rescue
98
+ nil
96
99
  end
97
- rescue
98
- nil
99
- end
100
100
 
101
- def command_exists?(command)
102
- ENV['PATH'].split(File::PATH_SEPARATOR).any? { |d| File.exist? File.join(d, command) }
103
- end
101
+ def command_exists?(command)
102
+ ENV["PATH"].split(File::PATH_SEPARATOR).any? { |d| File.exist? File.join(d, command) }
103
+ end
104
104
  end
105
105
  end
@@ -1,20 +1,20 @@
1
- require 'mechanize'
2
- require 'addressable/uri'
1
+ require "mechanize"
2
+ require "addressable/uri"
3
3
 
4
4
  module GitTrend
5
5
  class Scraper
6
- BASE_HOST = 'https://github.com'
6
+ BASE_HOST = "https://github.com"
7
7
  BASE_URL = "#{BASE_HOST}/trending"
8
8
 
9
9
  def initialize
10
10
  @agent = Mechanize.new
11
11
  @agent.user_agent = "git-trend #{VERSION}"
12
- proxy = URI.parse(ENV['http_proxy']) if ENV['http_proxy']
12
+ proxy = URI.parse(ENV["http_proxy"]) if ENV["http_proxy"]
13
13
  @agent.set_proxy(proxy.host, proxy.port, proxy.user, proxy.password) if proxy
14
14
  end
15
15
 
16
16
  def get(language = nil, since = nil, number = nil)
17
- page = @agent.get(generate_url_for_get(language, since))
17
+ page = @agent.get(generate_url(language, since))
18
18
  projects = generate_project(page)
19
19
  fail ScrapeException if projects.empty?
20
20
  number ? projects[0...number] : projects
@@ -22,61 +22,44 @@ module GitTrend
22
22
 
23
23
  def languages
24
24
  page = @agent.get(BASE_URL)
25
- page.search('.language-filter-list + .select-menu span.select-menu-item-text').inject([]) do |languages, content|
25
+ page.search(".language-filter-list + .select-menu span.select-menu-item-text").inject([]) do |languages, content|
26
26
  languages << content.text if content.text
27
27
  end
28
28
  end
29
29
 
30
30
  private
31
31
 
32
- def generate_url_for_get(language, since)
33
- uri = Addressable::URI.parse(BASE_URL)
34
- since = convert_url_param_since(since)
35
- if language || since
36
- uri.query_values = { l: language, since: since }.delete_if { |_k, v| v.nil? }
37
- end
38
- uri.to_s
39
- end
40
-
41
- def convert_url_param_since(since)
42
- return unless since
43
- case since.to_sym
44
- when :d, :day, :daily then 'daily'
45
- when :w, :week, :weekly then 'weekly'
46
- when :m, :month, :monthly then 'monthly'
47
- else ''
32
+ def generate_url(language, since)
33
+ url = BASE_URL.dup
34
+ url << "/#{language}" if language
35
+ uri = Addressable::URI.parse(url)
36
+ since = convert_url_param_since(since)
37
+ if since
38
+ uri.query_values = { since: since }.delete_if { |_k, v| v.nil? }
39
+ end
40
+ uri.to_s
48
41
  end
49
- end
50
42
 
51
- # Pattern 1: lang + stars
52
- # Ruby 24 stars today • Built by
53
- # Pattern 2: only stars
54
- # 85 stars today • Built by
55
- # Pattern 3: only lang
56
- # ASP Built by
57
- def extract_lang_and_star_from_meta(text)
58
- meta_data = text.split('•').map { |x| x.delete("\n").strip }
59
- meta_data.pop # remove "Build by"
60
- if meta_data.size == 2
61
- [meta_data[0], meta_data[1].delete(',').to_i]
62
- else
63
- if meta_data[0].include?('stars')
64
- ['', meta_data[0].delete(',').to_i]
65
- else
66
- [meta_data[0], 0]
43
+ def convert_url_param_since(since)
44
+ return unless since
45
+ case since.to_sym
46
+ when :d, :day, :daily then "daily"
47
+ when :w, :week, :weekly then "weekly"
48
+ when :m, :month, :monthly then "monthly"
49
+ else ""
67
50
  end
68
51
  end
69
- end
70
52
 
71
- def generate_project(page)
72
- page.search('.repo-list-item').map do |content|
73
- project = Project.new
74
- meta_data = content.search('.repo-list-meta').text
75
- project.lang, project.star_count = extract_lang_and_star_from_meta(meta_data)
76
- project.name = content.search('.repo-list-name a').text.split.join
77
- project.description = content.search('.repo-list-description').text.delete("\n").strip
78
- project
53
+ def generate_project(page)
54
+ content = page.search(".repo-list li").map do |content|
55
+ Project.new(
56
+ name: content.search("h3 a").attr("href").to_s.sub(/\A\//, ""),
57
+ description: content.search(".py-1").text.strip,
58
+ lang: content.search('span[itemprop="programmingLanguage"]').text.strip,
59
+ star_count: content.search('a[aria-label="Stargazers"]').text.strip.to_i,
60
+ fork_count: content.search('a[aria-label="Forks"]').text.strip.to_i,
61
+ )
62
+ end
79
63
  end
80
- end
81
64
  end
82
65
  end