git-trend 1.2.9 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c515ab8268a8e8e5f67f8a17931e813d5989dabd94f33395583286662bc0b791
4
- data.tar.gz: d6937ec921f004f2d951a9d5da9d410c72982440cb824ad92abe095361c10165
3
+ metadata.gz: e0747b72131e24ecb5c876c337ce33be1941683110562847152189e4ddbb5c72
4
+ data.tar.gz: 47412945f045abb2cd8af2d959ca9cb01547649d7904b5eeec0a3791f5476be6
5
5
  SHA512:
6
- metadata.gz: 6950a80e2186bf6742702f7f00261ef1c643ce893db17f2000def3f647407804b4de6f0ea5cf398027f8aa5e842672e4d1b6c22810cf791bf9ea04ffa15acc0a
7
- data.tar.gz: 719d208ea9cf6e008667007dce28838197d06ff8cdb5360c146195760e2158b4376a77a95ea9dc68cb10e0bec07afb765084e68ee3bfa50b43dd6c5f71664fb8
6
+ metadata.gz: 8a55d7452c04a64ad860e52e19a9673dedd0ef585b9615e1ad2e385100892540cff76209b807ae81087665436379219c351546f9f05115df006e93783050c09a
7
+ data.tar.gz: 041bb27a4b62b0114231b6d0d66cf285ca0dd7b2326d8dee5c3faa31667506960300e7bfb59e05c5e06eb46b81e0c5a14f189ab14a4c3fb466347061a7a9fbe3
@@ -0,0 +1,82 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ jobs:
8
+ ruby27:
9
+ runs-on: ubuntu-latest
10
+ timeout-minutes: 10
11
+
12
+ steps:
13
+ - name: Checkout code
14
+ uses: actions/checkout@v2
15
+
16
+ - name: Setup Ruby
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: '2.7.5'
20
+ bundler-cache: true
21
+
22
+ - name: Show ruby version
23
+ run: ruby -v
24
+
25
+ - name: Run tests
26
+ run: bundle exec rspec
27
+
28
+ - name: Run lint
29
+ run: bundle exec rubocop
30
+
31
+
32
+ ruby31:
33
+ runs-on: ubuntu-latest
34
+ timeout-minutes: 10
35
+
36
+ steps:
37
+ - name: Checkout code
38
+ uses: actions/checkout@v2
39
+
40
+ - name: Setup Ruby
41
+ uses: ruby/setup-ruby@v1
42
+ with:
43
+ ruby-version: '3.1.3'
44
+ bundler-cache: true
45
+
46
+ - name: Show ruby version
47
+ run: ruby -v
48
+
49
+ - name: Run tests
50
+ run: bundle exec rspec
51
+
52
+ - name: Run lint
53
+ run: bundle exec rubocop
54
+
55
+ ruby32:
56
+ runs-on: ubuntu-latest
57
+ timeout-minutes: 10
58
+
59
+ steps:
60
+ - name: Checkout code
61
+ uses: actions/checkout@v2
62
+
63
+ - name: Setup Ruby
64
+ uses: ruby/setup-ruby@v1
65
+ with:
66
+ ruby-version: '3.2.2'
67
+ bundler-cache: true
68
+
69
+ - name: Show ruby version
70
+ run: ruby -v
71
+
72
+ - name: Run tests
73
+ run: bundle exec rspec
74
+
75
+ - name: Run lint
76
+ run: bundle exec rubocop
77
+
78
+ - name: Upload coverage reports to Codecov
79
+ uses: codecov/codecov-action@v3
80
+ with:
81
+ files: ./coverage/.resultset.json
82
+ token: ${{ secrets.CODECOV_TOKEN }}
data/.rubocop.yml CHANGED
@@ -1,5 +1,88 @@
1
- inherit_from:
2
- - https://raw.githubusercontent.com/rails/rails/master/.rubocop.yml
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ require:
4
+ - rubocop-performance
5
+ - rubocop-rake
6
+ - rubocop-rspec
7
+
8
+ AllCops:
9
+ TargetRubyVersion: 2.7
10
+ Exclude:
11
+ - '**/tmp/**/*'
12
+ - '**/vendor/**/*'
13
+ NewCops: enable
14
+
15
+ # ドキュメントの無い public class を許可する
16
+ Style/Documentation:
17
+ Enabled: false
18
+
19
+ # special_inside_parentheses (default) と比べて
20
+ # * 横に長くなりづらい
21
+ # * メソッド名の長さが変わったときに diff が少ない
22
+ Layout/FirstArrayElementIndentation:
23
+ EnforcedStyle: consistent
24
+
25
+ # private/protected は一段深くインデントする
26
+ Layout/IndentationConsistency:
27
+ EnforcedStyle: indented_internal_methods
28
+
29
+ Layout/LineLength:
30
+ Exclude:
31
+ - "spec/**/*.rb"
32
+ Max: 160
33
+
34
+ Metrics/BlockLength:
35
+ Exclude:
36
+ - "Rakefile"
37
+ - "**/*.rake"
38
+ - "spec/**/*.rb"
39
+ - "Gemfile"
40
+ - "*.gemspec"
41
+
42
+ Metrics/MethodLength:
43
+ Max: 20
44
+ Exclude:
45
+ - "spec/**/*.rb"
46
+
47
+ Metrics/ParameterLists:
48
+ Enabled: false
49
+
50
+ Style/BlockComments:
51
+ Enabled: false
52
+
53
+ # namespace 付きのクラスはかなり頻繁に作るので簡単に書きたい。
54
+ Style/ClassAndModuleChildren:
55
+ Enabled: false
3
56
 
4
57
  Style/FrozenStringLiteralComment:
5
58
  Enabled: false
59
+
60
+ # 無指定だと StandardError を rescue するのは常識の範疇なので。
61
+ Style/RescueStandardError:
62
+ EnforcedStyle: implicit
63
+
64
+ # * 式展開したい場合に書き換えるのが面倒
65
+ # * 文章ではダブルクォートよりもシングルクォートの方が頻出する
66
+ # ことから EnforcedStyle: double_quotes 推奨
67
+ Style/StringLiterals:
68
+ EnforcedStyle: double_quotes
69
+
70
+ # 複数行の場合はケツカンマを入れる(Arrayリテラル)
71
+ Style/TrailingCommaInArrayLiteral:
72
+ EnforcedStyleForMultiline: comma
73
+
74
+ # 複数行の場合はケツカンマを入れる(Hashリテラル)
75
+ Style/TrailingCommaInHashLiteral:
76
+ EnforcedStyleForMultiline: comma
77
+
78
+ RSpec/NestedGroups:
79
+ Max: 5
80
+
81
+ RSpec/ContextWording:
82
+ Enabled: false
83
+
84
+ RSpec/ExampleLength:
85
+ Enabled: false
86
+
87
+ RSpec/NamedSubject:
88
+ Enabled: false
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,15 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2023-12-10 21:11:24 UTC using RuboCop version 1.58.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # This cop supports safe autocorrection (--autocorrect).
11
+ # Configuration parameters: EnforcedStyle.
12
+ # SupportedStyles: format, sprintf, percent
13
+ Style/FormatString:
14
+ Exclude:
15
+ - 'lib/git_trend/formatters/text_formatter.rb'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## v1.4.0 (Mon Mar 13 2023)
2
+
3
+ - Drop support of Ruby 2.6 and earlier [41e871e]
4
+
5
+ ## v1.3.0 (Mon Mar 13 2023)
6
+
7
+ - Fix changing HTML structure [8de4920]
8
+
1
9
  ## v1.2.9 (Mon Mar 13 2023)
2
10
 
3
11
  - Upgrade gem [3f79648]
@@ -20,11 +28,11 @@
20
28
 
21
29
  ## v1.2.4 (Mon Mar 2 2020)
22
30
 
23
- - Fix languages without linefeeds [ecc63af]
31
+ - Fix languages without linefeed [ecc63af]
24
32
 
25
33
  ## v1.2.3 (Mon Mar 2 2020)
26
34
 
27
- - Fix wrong interger format of star [dbdc344]
35
+ - Fix wrong integer format of star [dbdc344]
28
36
 
29
37
  ## v1.2.2 (Sun Dec 15 2019)
30
38
 
@@ -40,7 +48,7 @@
40
48
 
41
49
  ## v1.1.9 (Sat Mar 16 2017)
42
50
 
43
- - Fix lagungage result is zero (#24) [9bb8785]
51
+ - Fix language result is zero (#24) [9bb8785]
44
52
 
45
53
  ## v1.1.8 (Sat Jul 22 2017)
46
54
 
@@ -94,7 +102,7 @@
94
102
  - Update gems [29bc2a9]
95
103
 
96
104
  ## v0.2.1 (Sun Dec 6 2015)
97
- - Fix #6 redundancy line feeds when including multibyte characters [61fd81c]
105
+ - Fix #6 redundancy line feeds when including multi-byte characters [61fd81c]
98
106
  - Update gems [ea5a018]
99
107
 
100
108
  ## v0.2.0 (Tue Dec 3 2015)
@@ -121,7 +129,7 @@
121
129
  - Add number option #3 [7cff5b4]
122
130
 
123
131
  ## v0.1.3
124
- - The `descript` option of `list` command was changed into the default. [3602272]
132
+ - The `description` option of `list` command was changed into the default. [3602272]
125
133
 
126
134
  ## v0.1.2
127
135
  - Fix travis ci error #24 [6752e1d]
@@ -152,7 +160,7 @@ Add a magic comment for ruby1.9 #2
152
160
  - Fix lack of addressable gem when installing [54ca275]
153
161
 
154
162
  ## v0.0.4
155
- - Implement descrition option [4587e56]
163
+ - Implement description option [4587e56]
156
164
 
157
165
  ## v0.0.3
158
166
  - Implement since option [04f1978]
data/Gemfile CHANGED
@@ -2,3 +2,14 @@ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in git-trend.gemspec
4
4
  gemspec
5
+
6
+ gem "rake"
7
+ gem "rubocop", require: false
8
+ gem "rubocop-performance", require: false
9
+ gem "rubocop-rake", require: false
10
+ gem "rubocop-rspec", require: false
11
+
12
+ gem "irb", require: false
13
+ gem "rspec", require: false
14
+ gem "simplecov", require: false
15
+ gem "webmock", require: false
data/README.md CHANGED
@@ -1,6 +1,4 @@
1
- [![Build Status](https://travis-ci.com/rochefort/git-trend.svg?branch=master)](https://travis-ci.com/rochefort/git-trend)
2
- [![Coverage Status](https://coveralls.io/repos/github/rochefort/git-trend/badge.svg?branch=master)](https://coveralls.io/github/rochefort/git-trend?branch=master)
3
- [![Code Climate](https://img.shields.io/codeclimate/maintainability/rochefort/git-trend.svg)](https://codeclimate.com/github/rochefort/git-trend/maintainability)
1
+ [![codecov](https://codecov.io/gh/rochefort/git-trend/graph/badge.svg?token=rbh4fONhKx)](https://codecov.io/gh/rochefort/git-trend)
4
2
  [![Gem Version](http://img.shields.io/gem/v/git-trend.svg?style=flat)](http://badge.fury.io/rb/git-trend)
5
3
 
6
4
 
@@ -20,7 +18,7 @@ And this also work as a command line utility.
20
18
 
21
19
  ## Requirements
22
20
 
23
- Ruby versions is 2.4 or later.
21
+ Ruby versions is 2.7 or later.
24
22
 
25
23
  ## Installation
26
24
  Add this line to your application's Gemfile:
data/git-trend.gemspec CHANGED
@@ -1,4 +1,4 @@
1
- lib = File.expand_path("../lib", __FILE__)
1
+ lib = File.expand_path("lib", __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require "git_trend/version"
4
4
 
@@ -17,33 +17,20 @@ Gem::Specification.new do |spec|
17
17
  spec.description = spec.summary
18
18
  spec.homepage = "https://github.com/rochefort/git-trend"
19
19
  spec.license = "MIT"
20
- spec.required_ruby_version = ">= 2.5.0"
20
+ spec.required_ruby_version = ">= 2.7.0"
21
21
 
22
22
  spec.files = `git ls-files -z`.split("\x0")
23
23
  spec.bindir = "exe"
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
26
25
  spec.require_paths = ["lib"]
27
26
 
28
27
  spec.post_install_message = install_message
29
28
 
30
29
  spec.add_dependency "addressable", "~> 2.8"
31
30
  spec.add_dependency "mb_string"
32
- spec.add_dependency "mechanize", ">= 2.8.5", "< 2.9.0"
31
+ spec.add_dependency "mechanize", ">= 2.8.5", "< 2.10.0"
33
32
  spec.add_dependency "thor", ">= 0.20.0", "< 1.3.0"
34
33
  spec.add_dependency "unicode-display_width"
35
34
 
36
- spec.add_development_dependency "bundler"
37
- spec.add_development_dependency "rake", "~> 13.0.0"
38
-
39
- spec.add_development_dependency "rubocop"
40
- spec.add_development_dependency "rubocop-performance"
41
- spec.add_development_dependency "rubocop-rails"
42
-
43
- spec.add_development_dependency "pry-byebug"
44
- spec.add_development_dependency "rspec", "~> 3.12.0"
45
- spec.add_development_dependency "simplecov", "~>0.16.1"
46
- spec.add_development_dependency "webmock", "~> 3.18.1"
47
-
48
- spec.add_development_dependency "coveralls", "~> 0.8.23"
35
+ spec.metadata["rubygems_mfa_required"] = "true"
49
36
  end
data/lib/git-trend.rb CHANGED
@@ -1 +1 @@
1
- require "git_trend"
1
+ require "git_trend" # rubocop:disable Naming/FileName
data/lib/git_trend/cli.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  require "thor"
2
2
 
3
+ # rubocop:disable Metrics/AbcSize
3
4
  module GitTrend
4
5
  class CLI < Thor
5
- map "-v" => :version,
6
- "--version" => :version
6
+ map "-v" => :version, "--version" => :version
7
7
 
8
8
  default_command :list
9
9
  class_option :verbose, type: :boolean
@@ -28,19 +28,20 @@ module GitTrend
28
28
  option :help, aliases: "-h", required: false, type: :boolean
29
29
  def list
30
30
  help(:list) && return if options[:help]
31
+
31
32
  scraper = Scraper.new
32
33
  projects = scraper.get(options[:language], options[:since], options[:number])
33
34
  formatter = Formatter.new(options[:format])
34
35
  formatter.print(projects, enable_description: !!options[:description])
35
36
  rescue => e
36
37
  say "An unexpected #{e.class} has occurred.", :red
37
- say e.message unless e.class.to_s == e.message
38
+ say e.message unless e.instance_of?(e.message) # エラー内容がクラス名の場合は表示しない
38
39
 
39
40
  puts exception.backtrace if options[:verbose]
40
41
  end
41
42
 
42
43
  desc :languages, "Show selectable languages"
43
- option :format, aliases: "-f", required: false, default: "text", desc: "Choose a formatter as text or json. Enable: [t, text, j, json]"
44
+ option :format, aliases: "-f", required: false, default: "text", desc: "Choose a formatter as text or json. Enable: [t, text, j, json]"
44
45
  def languages
45
46
  scraper = Scraper.new
46
47
  languages = scraper.languages
@@ -49,3 +50,4 @@ module GitTrend
49
50
  end
50
51
  end
51
52
  end
53
+ # rubocop:enable Metrics/AbcSize
@@ -13,6 +13,7 @@ module GitTrend
13
13
  end
14
14
 
15
15
  private
16
+
16
17
  def formatter_class(key)
17
18
  case key
18
19
  when "j", "json" then Formatters::JsonFormatter
@@ -2,8 +2,8 @@ require "json"
2
2
 
3
3
  module GitTrend::Formatters
4
4
  class JsonFormatter
5
- def print(projects, options)
6
- puts projects.map { |project| project.to_h }.to_json
5
+ def print(projects, options) # rubocop:disable Lint/UnusedMethodArgument
6
+ puts projects.map(&:to_h).to_json
7
7
  end
8
8
 
9
9
  def print_languages(languages)
@@ -2,8 +2,8 @@ require "mb_string"
2
2
 
3
3
  module GitTrend::Formatters
4
4
  class TextFormatter
5
- HEADER_COLUMNS = %w(no. name lang star description)
6
- DEFAULT_COLUMNS_SIZES = [3, 40, 10, 6, 20]
5
+ HEADER_COLUMNS = %w[no. name lang star description].freeze
6
+ DEFAULT_COLUMNS_SIZES = [3, 40, 10, 6, 20].freeze
7
7
 
8
8
  def print(projects, options)
9
9
  if projects.empty?
@@ -27,6 +27,7 @@ module GitTrend::Formatters
27
27
  end
28
28
 
29
29
  private
30
+
30
31
  def render_zero
31
32
  puts "It looks like we don’t have any trending repositories."
32
33
  puts
@@ -42,7 +43,7 @@ module GitTrend::Formatters
42
43
 
43
44
  def rule_max_description_size
44
45
  terminal_width, _terminal_height = detect_terminal_size
45
- description_width = terminal_width - @columns_sizes[0..-2].inject(&:+) - (@columns_sizes.size - 1)
46
+ description_width = terminal_width - @columns_sizes[0..-2].sum - (@columns_sizes.size - 1)
46
47
  if description_width >= DEFAULT_COLUMNS_SIZES.last
47
48
  @columns_sizes[-1] = description_width
48
49
  else
@@ -71,6 +72,7 @@ module GitTrend::Formatters
71
72
  puts fmt % @columns_sizes.map { |column| "-" * column }
72
73
  end
73
74
 
75
+ # rubocop:disable Metrics/AbcSize
74
76
  def render_body(projects)
75
77
  f = @columns_sizes
76
78
  fmt = "%#{f[0]}s %-#{f[1]}s %-#{f[2]}s %#{f[3]}s"
@@ -87,12 +89,14 @@ module GitTrend::Formatters
87
89
  puts result.rstrip
88
90
  end
89
91
  end
92
+ # rubocop:enable Metrics/AbcSize
90
93
 
91
94
  def render_footer
92
95
  puts
93
96
  end
94
97
 
95
98
  # https://github.com/cldwalker/hirb/blob/master/lib/hirb/util.rb#L61-71
99
+ # rubocop:disable all
96
100
  def detect_terminal_size
97
101
  if (ENV["COLUMNS"] =~ /^\d+$/) && (ENV["LINES"] =~ /^\d+$/)
98
102
  [ENV["COLUMNS"].to_i, ENV["LINES"].to_i]
@@ -104,6 +108,7 @@ module GitTrend::Formatters
104
108
  rescue
105
109
  nil
106
110
  end
111
+ # rubocop:enable all
107
112
 
108
113
  def command_exists?(command)
109
114
  ENV["PATH"].split(File::PATH_SEPARATOR).any? { |d| File.exist? File.join(d, command) }
@@ -3,8 +3,8 @@ require "addressable/uri"
3
3
 
4
4
  module GitTrend
5
5
  class Scraper
6
- BASE_HOST = "https://github.com"
7
- BASE_URL = "#{BASE_HOST}/trending"
6
+ BASE_HOST = "https://github.com".freeze
7
+ BASE_URL = "#{BASE_HOST}/trending".freeze
8
8
 
9
9
  def initialize
10
10
  @agent = Mechanize.new
@@ -28,19 +28,19 @@ module GitTrend
28
28
  end
29
29
 
30
30
  private
31
+
31
32
  def generate_url(language, since)
32
33
  url = BASE_URL.dup
33
34
  url << "/#{language}" if language
34
35
  uri = Addressable::URI.parse(url)
35
36
  since = convert_url_param_since(since)
36
- if since
37
- uri.query_values = { since: since }.delete_if { |_k, v| v.nil? }
38
- end
37
+ uri.query_values = { since: since }.compact if since
39
38
  uri.to_s
40
39
  end
41
40
 
42
41
  def convert_url_param_since(since)
43
42
  return unless since
43
+
44
44
  case since.to_sym
45
45
  when :d, :day, :daily then "daily"
46
46
  when :w, :week, :weekly then "weekly"
@@ -49,11 +49,12 @@ module GitTrend
49
49
  end
50
50
  end
51
51
 
52
+ # rubocop:disable Metrics/AbcSize
52
53
  def generate_project(page)
53
54
  page.search(".Box-row").map do |content|
54
55
  icon_area = content.search(".f6.color-fg-muted.mt-2")
55
56
  Project.new(
56
- name: content.search("h1 a").attr("href").to_s.sub(/\A\//, ""),
57
+ name: content.search("h2 a").attr("href").to_s.delete_prefix("/"),
57
58
  description: content.search(".col-9.color-fg-muted.my-1.pr-4").text.strip,
58
59
  lang: content.search('span[itemprop="programmingLanguage"]').text.strip,
59
60
  all_star_count: comma_to_i(icon_area.search("a:has(svg.octicon-star)").text.strip),
@@ -62,6 +63,7 @@ module GitTrend
62
63
  )
63
64
  end
64
65
  end
66
+ # rubocop:enable Metrics/AbcSize
65
67
 
66
68
  def comma_to_i(obj)
67
69
  obj.to_s.delete(",").to_i
@@ -1,3 +1,3 @@
1
1
  module GitTrend
2
- VERSION = "1.2.9"
2
+ VERSION = "1.4.0".freeze
3
3
  end