git-trend 1.3.0 → 1.4.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
  SHA256:
3
- metadata.gz: 323d3cdcc6a5b98203e5ece49d36d138889ec29c1ec19468e838bb3434fd2c88
4
- data.tar.gz: b3baf1505331b32e0ce86cf088687b9655f0757ed85d339bb35814b2ee84a06e
3
+ metadata.gz: e0747b72131e24ecb5c876c337ce33be1941683110562847152189e4ddbb5c72
4
+ data.tar.gz: 47412945f045abb2cd8af2d959ca9cb01547649d7904b5eeec0a3791f5476be6
5
5
  SHA512:
6
- metadata.gz: e5c0976042644c9dfd4586be12d139657c2cb2fb7732f1fef028b357d4f4e7b11f78892e3e400fd7476224e00abf8806f9087d1cda244c7f6dbbff7713aebc53
7
- data.tar.gz: 2a0f4c8bdbff6e03a83e43233825f98c67ff0156f2185d2b6e4fbe4776b64b54c5dcc1a169f4c1f868b31a61cb9522b899b967bd3d3f11a753682c6e864ca356
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,7 @@
1
+ ## v1.4.0 (Mon Mar 13 2023)
2
+
3
+ - Drop support of Ruby 2.6 and earlier [41e871e]
4
+
1
5
  ## v1.3.0 (Mon Mar 13 2023)
2
6
 
3
7
  - Fix changing HTML structure [8de4920]
@@ -24,11 +28,11 @@
24
28
 
25
29
  ## v1.2.4 (Mon Mar 2 2020)
26
30
 
27
- - Fix languages without linefeeds [ecc63af]
31
+ - Fix languages without linefeed [ecc63af]
28
32
 
29
33
  ## v1.2.3 (Mon Mar 2 2020)
30
34
 
31
- - Fix wrong interger format of star [dbdc344]
35
+ - Fix wrong integer format of star [dbdc344]
32
36
 
33
37
  ## v1.2.2 (Sun Dec 15 2019)
34
38
 
@@ -44,7 +48,7 @@
44
48
 
45
49
  ## v1.1.9 (Sat Mar 16 2017)
46
50
 
47
- - Fix lagungage result is zero (#24) [9bb8785]
51
+ - Fix language result is zero (#24) [9bb8785]
48
52
 
49
53
  ## v1.1.8 (Sat Jul 22 2017)
50
54
 
@@ -98,7 +102,7 @@
98
102
  - Update gems [29bc2a9]
99
103
 
100
104
  ## v0.2.1 (Sun Dec 6 2015)
101
- - Fix #6 redundancy line feeds when including multibyte characters [61fd81c]
105
+ - Fix #6 redundancy line feeds when including multi-byte characters [61fd81c]
102
106
  - Update gems [ea5a018]
103
107
 
104
108
  ## v0.2.0 (Tue Dec 3 2015)
@@ -125,7 +129,7 @@
125
129
  - Add number option #3 [7cff5b4]
126
130
 
127
131
  ## v0.1.3
128
- - 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]
129
133
 
130
134
  ## v0.1.2
131
135
  - Fix travis ci error #24 [6752e1d]
@@ -156,7 +160,7 @@ Add a magic comment for ruby1.9 #2
156
160
  - Fix lack of addressable gem when installing [54ca275]
157
161
 
158
162
  ## v0.0.4
159
- - Implement descrition option [4587e56]
163
+ - Implement description option [4587e56]
160
164
 
161
165
  ## v0.0.3
162
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("h2 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.3.0"
2
+ VERSION = "1.4.0".freeze
3
3
  end
@@ -1,6 +1,6 @@
1
- # rubocop:disable Style/TrailingWhitespace
2
- include GitTrend
3
1
  RSpec.describe GitTrend::CLI do
2
+ include GitTrend
3
+
4
4
  shared_examples "since daily ranking" do |since|
5
5
  it "display daily ranking" do
6
6
  expect { cli.invoke(:list, [], since: since, description: false) }.to output(dummy_result_without_description).to_stdout
@@ -25,23 +25,27 @@ RSpec.describe GitTrend::CLI do
25
25
  describe "with -n option" do
26
26
  context "with 3" do
27
27
  before { stub_request_get("trending") }
28
+
28
29
  let(:number) { 3 }
30
+
29
31
  it "display top 3 daily ranking" do
30
- res = <<-'EOS'.unindent
32
+ res = <<-OUTPUT.unindent
31
33
  |No. Name Lang Star
32
34
  |--- ---------------------------------------- ---------------- ------
33
35
  | 1 linexjlin/GPTs 445
34
36
  | 2 ml-explore/mlx-examples Python 161
35
37
  | 3 PRIS-CV/DemoFusion Jupyter Notebook 169
36
38
 
37
- EOS
39
+ OUTPUT
38
40
  expect { cli.invoke(:list, [], number: number, description: false) }.to output(res).to_stdout
39
41
  end
40
42
  end
41
43
 
42
44
  context "with over 25" do
43
45
  before { stub_request_get("trending") }
46
+
44
47
  let(:number) { 26 }
48
+
45
49
  it "display daily ranking" do
46
50
  expect { cli.invoke(:list, [], number: number, description: false) }.to output(dummy_result_without_description).to_stdout
47
51
  end
@@ -51,10 +55,11 @@ RSpec.describe GitTrend::CLI do
51
55
  describe "with -l option" do
52
56
  context "with ruby" do
53
57
  before { stub_request_get("trending/#{language}") }
58
+
54
59
  let(:language) { "ruby" }
55
60
 
56
61
  it "display daily ranking by language" do
57
- res = <<-'EOS'.unindent
62
+ res = <<-OUTPUT.unindent
58
63
  |No. Name Lang Star
59
64
  |--- ---------------------------------------- ---------- ------
60
65
  | 1 greatghoul/remote-working Ruby 34
@@ -83,20 +88,21 @@ RSpec.describe GitTrend::CLI do
83
88
  | 24 chef/chef Ruby 0
84
89
  | 25 instructure/canvas-lms Ruby 0
85
90
 
86
- EOS
91
+ OUTPUT
87
92
  expect { cli.invoke(:list, [], language: language, description: false) }.to output(res).to_stdout
88
93
  end
89
94
  end
90
95
 
91
96
  context "with alloy : when trending is nothing" do
92
97
  before { stub_request_get("trending/#{language}") }
98
+
93
99
  let(:language) { "alloy" }
94
100
 
95
101
  it "display the 0cases message" do
96
- res = <<-'EOS'.unindent
102
+ res = <<-OUTPUT.unindent
97
103
  |It looks like we don’t have any trending repositories.
98
104
 
99
- EOS
105
+ OUTPUT
100
106
  expect { cli.invoke(:list, [], language: language, description: false) }.to output(res).to_stdout
101
107
  end
102
108
  end
@@ -105,11 +111,13 @@ RSpec.describe GitTrend::CLI do
105
111
  describe "with -s option" do
106
112
  context "with no option" do
107
113
  before { stub_request_get("trending?since=") }
114
+
108
115
  include_examples "since daily ranking", ""
109
116
  end
110
117
 
111
118
  describe "since daily" do
112
119
  before { stub_request_get("trending?since=daily") }
120
+
113
121
  context "with d" do
114
122
  include_examples "since daily ranking", "d"
115
123
  end
@@ -125,6 +133,7 @@ RSpec.describe GitTrend::CLI do
125
133
 
126
134
  describe "since weekly" do
127
135
  before { stub_request_get("trending?since=weekly") }
136
+
128
137
  context "with w" do
129
138
  include_examples "since weekly ranking", "w"
130
139
  end
@@ -140,6 +149,7 @@ RSpec.describe GitTrend::CLI do
140
149
 
141
150
  describe "since monthly" do
142
151
  before { stub_request_get("trending?since=monthly") }
152
+
143
153
  context "with m" do
144
154
  include_examples "since monthly ranking", "m"
145
155
  end
@@ -193,11 +203,12 @@ RSpec.describe GitTrend::CLI do
193
203
  describe "with -l and -s option" do
194
204
  context "with ruby and weekly" do
195
205
  before { stub_request_get("trending/#{language}?since=#{since}") }
206
+
196
207
  let(:language) { "ruby" }
197
208
  let(:since) { "weekly" }
198
209
 
199
210
  it "display weekly ranking by language" do
200
- res = <<-'EOS'.unindent
211
+ res = <<-OUTPUT.unindent
201
212
  |No. Name Lang Star
202
213
  |--- ---------------------------------------- ---------- ------
203
214
  | 1 mastodon/mastodon Ruby 115
@@ -226,7 +237,7 @@ RSpec.describe GitTrend::CLI do
226
237
  | 24 rubocop/rubocop Ruby 10
227
238
  | 25 paper-trail-gem/paper_trail Ruby 3
228
239
 
229
- EOS
240
+ OUTPUT
230
241
  expect { cli.invoke(:list, [], language: language, since: since, description: false) }.to output(res).to_stdout
231
242
  end
232
243
  end
@@ -235,16 +246,18 @@ RSpec.describe GitTrend::CLI do
235
246
 
236
247
  describe "#languages" do
237
248
  before { stub_request_get("trending") }
249
+
238
250
  let(:cli) { CLI.new }
239
251
 
240
252
  context "with no option" do
241
253
  it "display languages" do
242
- expect { cli.languages }.to output(match("C++").and match("HTML").and match("Ruby")).to_stdout
254
+ expect { cli.languages }.to output(include("C++", "HTML", "Ruby")).to_stdout
243
255
  end
244
256
  end
245
257
  end
246
258
 
247
259
  private
260
+
248
261
  def stub_request_get(stub_url_path, stub_file_name = nil)
249
262
  url = Scraper::BASE_HOST.dup
250
263
  url << "/#{stub_url_path}" if stub_url_path
@@ -254,11 +267,12 @@ RSpec.describe GitTrend::CLI do
254
267
  .to_return(
255
268
  status: 200,
256
269
  headers: { content_type: "text/html" },
257
- body: load_http_stub(stub_file))
270
+ body: load_http_stub(stub_file)
271
+ )
258
272
  end
259
273
 
260
274
  def dummy_result_without_description
261
- <<-'EOS'.unindent
275
+ <<-OUTPUT.unindent
262
276
  |No. Name Lang Star
263
277
  |--- ------------------------------------------ ---------------- ------
264
278
  | 1 linexjlin/GPTs 445
@@ -287,11 +301,11 @@ RSpec.describe GitTrend::CLI do
287
301
  | 24 ytdl-org/youtube-dl Python 24
288
302
  | 25 dunglas/frankenphp Go 53
289
303
 
290
- EOS
304
+ OUTPUT
291
305
  end
292
306
 
293
307
  def dummy_result_no_options
294
- <<-'EOS'.unindent
308
+ <<-OUTPUT.unindent
295
309
  |No. Name Lang Star Description
296
310
  |--- ------------------------------------------ ---------------- ------ ---------------------------------------------------------------------
297
311
  | 1 linexjlin/GPTs 445 leaked prompts of GPTs
@@ -320,11 +334,11 @@ RSpec.describe GitTrend::CLI do
320
334
  | 24 ytdl-org/youtube-dl Python 24 Command-line program to download videos from YouTube.com and other...
321
335
  | 25 dunglas/frankenphp Go 53 The modern PHP app server
322
336
 
323
- EOS
337
+ OUTPUT
324
338
  end
325
339
 
326
340
  def dummy_weekly_result
327
- <<-'EOS'.unindent
341
+ <<-OUTPUT.unindent
328
342
  |No. Name Lang Star
329
343
  |--- ------------------------------------------ ---------------- ------
330
344
  | 1 LC044/WeChatMsg Python 10719
@@ -353,11 +367,11 @@ RSpec.describe GitTrend::CLI do
353
367
  | 24 coolsnowwolf/lede C 132
354
368
  | 25 QwenLM/Qwen Python 377
355
369
 
356
- EOS
370
+ OUTPUT
357
371
  end
358
372
 
359
373
  def dummy_monthly_result
360
- <<-'EOS'.unindent
374
+ <<-OUTPUT.unindent
361
375
  |No. Name Lang Star
362
376
  |--- ---------------------------------------- ---------------- ------
363
377
  | 1 SawyerHood/draw-a-ui TypeScript 11761
@@ -386,6 +400,6 @@ RSpec.describe GitTrend::CLI do
386
400
  | 24 SillyTavern/SillyTavern JavaScript 1566
387
401
  | 25 1Panel-dev/1Panel Go 1950
388
402
 
389
- EOS
403
+ OUTPUT
390
404
  end
391
405
  end
@@ -1,17 +1,20 @@
1
- include GitTrend
1
+ include GitTrend # rubocop:disable Style/MixinUsage
2
2
  RSpec.describe GitTrend::Scraper do
3
3
  let(:scraper) { Scraper.new }
4
4
 
5
5
  describe "settings" do
6
+ subject { scraper.instance_variable_get(:@agent) }
7
+
6
8
  before do
7
9
  allow(ENV).to receive(:[]).with("http_proxy").and_return("http://#{proxy_user}:#{proxy_pass}@#{proxy_addr}:#{proxy_port}")
8
10
  end
11
+
9
12
  let(:proxy_addr) { "192.168.1.99" }
10
13
  let(:proxy_port) { 9999 }
11
14
  let(:proxy_user) { "proxy_user" }
12
15
  let(:proxy_pass) { "proxy_pass" }
13
- subject { scraper.instance_variable_get(:@agent) }
14
- it "should use proxy settings of ENV" do
16
+
17
+ it "uses proxy settings of ENV" do
15
18
  aggregate_failures do
16
19
  expect(subject.proxy_addr).to eq proxy_addr
17
20
  expect(subject.proxy_user).to eq proxy_user
@@ -28,6 +31,7 @@ RSpec.describe GitTrend::Scraper do
28
31
  stub_request(:get, Scraper::BASE_URL)
29
32
  .to_return(status: 500, body: "[]")
30
33
  end
34
+
31
35
  it { expect { scraper.get }.to raise_error(Exception) }
32
36
  end
33
37
  end
@@ -1,81 +1,97 @@
1
1
  RSpec.describe GitTrend do
2
+ include described_class
3
+ let(:scraper_mock) { instance_double(Scraper) }
4
+
2
5
  before do
6
+ allow(Scraper).to receive(:new).and_return(scraper_mock)
3
7
  stub_request(:get, /.*/)
4
8
  .to_return(status: 200, headers: { content_type: "text/html" }, body: load_http_stub("trending"))
5
9
  end
6
10
 
7
11
  describe "#get" do
8
- context "without options" do
9
- it "Scraper#get call without options" do
10
- expect_any_instance_of(Scraper).to receive(:get).with(no_args)
11
- GitTrend.get
12
+ context "normal" do
13
+ before do
14
+ allow(scraper_mock).to receive(:get)
12
15
  end
13
- end
14
16
 
15
- context "parameter is 'ruby'" do
16
- it "Scraper#get call with 'ruby'" do
17
- expect_any_instance_of(Scraper).to receive(:get).with("ruby")
18
- GitTrend.get("ruby")
17
+ context "without options" do
18
+ it "Scraper#get call without options" do
19
+ described_class.get
20
+ expect(scraper_mock).to have_received(:get).with(no_args)
21
+ end
19
22
  end
20
- end
21
23
 
22
- context "parameter is :ruby" do
23
- it "Scraper#get call with :ruby" do
24
- expect_any_instance_of(Scraper).to receive(:get).with(:ruby)
25
- GitTrend.get(:ruby)
24
+ context "parameter is 'ruby'" do
25
+ it "Scraper#get call with 'ruby'" do
26
+ described_class.get("ruby")
27
+ expect(scraper_mock).to have_received(:get).with("ruby")
28
+ end
26
29
  end
27
- end
28
30
 
29
- context "parameter is since: :weekly" do
30
- it "Scraper#get call with [nil, :weekly]" do
31
- expect_any_instance_of(Scraper).to receive(:get).with(nil, :weekly)
32
- GitTrend.get(since: :weekly)
31
+ context "parameter is :ruby" do
32
+ it "Scraper#get call with :ruby" do
33
+ described_class.get(:ruby)
34
+ expect(scraper_mock).to have_received(:get).with(:ruby)
35
+ end
33
36
  end
34
- end
35
37
 
36
- context "parameter is since: :week" do
37
- it "Scraper#get call with [nil, :week]" do
38
- expect_any_instance_of(Scraper).to receive(:get).with(nil, :week)
39
- GitTrend.get(since: :week)
38
+ context "parameter is since: :weekly" do
39
+ it "Scraper#get call with [nil, :weekly]" do
40
+ described_class.get(since: :weekly)
41
+ expect(scraper_mock).to have_received(:get).with(nil, :weekly)
42
+ end
40
43
  end
41
- end
42
44
 
43
- context "parameter is since: :w" do
44
- it "Scraper#get call with [nil, :w]" do
45
- expect_any_instance_of(Scraper).to receive(:get).with(nil, :w)
46
- GitTrend.get(since: :w)
45
+ context "parameter is since: :week" do
46
+ it "Scraper#get call with [nil, :week]" do
47
+ described_class.get(since: :week)
48
+ expect(scraper_mock).to have_received(:get).with(nil, :week)
49
+ end
47
50
  end
48
- end
49
51
 
50
- context "parameters are 'ruby', 'weekly'" do
51
- it "Scraper#get call with ['ruby', 'weekly']" do
52
- expect_any_instance_of(Scraper).to receive(:get).with("ruby", "weekly")
53
- GitTrend.get("ruby", "weekly")
52
+ context "parameter is since: :w" do
53
+ it "Scraper#get call with [nil, :w]" do
54
+ described_class.get(since: :w)
55
+ expect(scraper_mock).to have_received(:get).with(nil, :w)
56
+ end
54
57
  end
55
- end
56
58
 
57
- context "parameters are :ruby, :weekly" do
58
- it "Scraper#get call with [:ruby, :weekly]" do
59
- expect_any_instance_of(Scraper).to receive(:get).with(:ruby, :weekly)
60
- GitTrend.get(:ruby, :weekly)
59
+ context "parameters are 'ruby', 'weekly'" do
60
+ it "Scraper#get call with ['ruby', 'weekly']" do
61
+ described_class.get("ruby", "weekly")
62
+ expect(scraper_mock).to have_received(:get).with("ruby", "weekly")
63
+ end
64
+ end
65
+
66
+ context "parameters are :ruby, :weekly" do
67
+ it "Scraper#get call with [:ruby, :weekly]" do
68
+ described_class.get(:ruby, :weekly)
69
+ expect(scraper_mock).to have_received(:get).with(:ruby, :weekly)
70
+ end
61
71
  end
62
- end
63
72
 
64
- context "parameters are language: :ruby, since: :weekly" do
65
- it "Scraper#get call with [:ruby, :weekly]" do
66
- expect_any_instance_of(Scraper).to receive(:get).with(:ruby, :weekly)
67
- GitTrend.get(language: :ruby, since: :weekly)
73
+ context "parameters are language: :ruby, since: :weekly" do
74
+ it "Scraper#get call with [:ruby, :weekly]" do
75
+ described_class.get(language: :ruby, since: :weekly)
76
+ expect(scraper_mock).to have_received(:get).with(:ruby, :weekly)
77
+ end
68
78
  end
69
79
  end
70
80
 
71
- context "when too many parameters" do
72
- it { expect { GitTrend.get("ruby", "weekly", "many_params") }.to raise_error(Exception) }
81
+ context "abnormal" do
82
+ context "when too many parameters" do
83
+ it { expect { described_class.get("ruby", "weekly", "many_params") }.to raise_error(Exception) }
84
+ end
73
85
  end
74
86
 
75
87
  describe "#languages" do
88
+ before do
89
+ allow(scraper_mock).to receive(:languages)
90
+ end
91
+
76
92
  it "Scraper#languages call" do
77
- expect_any_instance_of(Scraper).to receive(:languages).with(no_args)
78
- GitTrend.languages
93
+ described_class.languages
94
+ expect(scraper_mock).to have_received(:languages).with(no_args)
79
95
  end
80
96
  end
81
97
  end
data/spec/spec_helper.rb CHANGED
@@ -14,25 +14,14 @@
14
14
  # users commonly want.
15
15
  #
16
16
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
- # require "coveralls"
18
- # Coveralls.wear!
19
-
20
17
  require "simplecov"
21
- require "webmock/rspec"
22
- require "git_trend"
23
-
24
- # require "codeclimate-test-reporter"
25
- dir = File.join(ENV["CIRCLE_ARTIFACTS"] || "coverage")
26
- SimpleCov.coverage_dir(dir)
27
18
  SimpleCov.start do
28
19
  add_filter "/spec/"
29
-
30
- formatter SimpleCov::Formatter::MultiFormatter.new([
31
- SimpleCov::Formatter::HTMLFormatter,
32
- # Coveralls::SimpleCov::Formatter
33
- ])
34
20
  end
35
21
 
22
+ require "webmock/rspec"
23
+ require "git_trend"
24
+
36
25
  RSpec.configure do |config|
37
26
  config.expect_with :rspec do |expectations|
38
27
  expectations.syntax = :expect
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-trend
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - rochefort
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-12-10 00:00:00.000000000 Z
11
+ date: 2023-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -47,7 +47,7 @@ dependencies:
47
47
  version: 2.8.5
48
48
  - - "<"
49
49
  - !ruby/object:Gem::Version
50
- version: 2.9.0
50
+ version: 2.10.0
51
51
  type: :runtime
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
@@ -57,7 +57,7 @@ dependencies:
57
57
  version: 2.8.5
58
58
  - - "<"
59
59
  - !ruby/object:Gem::Version
60
- version: 2.9.0
60
+ version: 2.10.0
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: thor
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -92,146 +92,6 @@ dependencies:
92
92
  - - ">="
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
- - !ruby/object:Gem::Dependency
96
- name: bundler
97
- requirement: !ruby/object:Gem::Requirement
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- version: '0'
102
- type: :development
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- requirements:
106
- - - ">="
107
- - !ruby/object:Gem::Version
108
- version: '0'
109
- - !ruby/object:Gem::Dependency
110
- name: rake
111
- requirement: !ruby/object:Gem::Requirement
112
- requirements:
113
- - - "~>"
114
- - !ruby/object:Gem::Version
115
- version: 13.0.0
116
- type: :development
117
- prerelease: false
118
- version_requirements: !ruby/object:Gem::Requirement
119
- requirements:
120
- - - "~>"
121
- - !ruby/object:Gem::Version
122
- version: 13.0.0
123
- - !ruby/object:Gem::Dependency
124
- name: rubocop
125
- requirement: !ruby/object:Gem::Requirement
126
- requirements:
127
- - - ">="
128
- - !ruby/object:Gem::Version
129
- version: '0'
130
- type: :development
131
- prerelease: false
132
- version_requirements: !ruby/object:Gem::Requirement
133
- requirements:
134
- - - ">="
135
- - !ruby/object:Gem::Version
136
- version: '0'
137
- - !ruby/object:Gem::Dependency
138
- name: rubocop-performance
139
- requirement: !ruby/object:Gem::Requirement
140
- requirements:
141
- - - ">="
142
- - !ruby/object:Gem::Version
143
- version: '0'
144
- type: :development
145
- prerelease: false
146
- version_requirements: !ruby/object:Gem::Requirement
147
- requirements:
148
- - - ">="
149
- - !ruby/object:Gem::Version
150
- version: '0'
151
- - !ruby/object:Gem::Dependency
152
- name: rubocop-rails
153
- requirement: !ruby/object:Gem::Requirement
154
- requirements:
155
- - - ">="
156
- - !ruby/object:Gem::Version
157
- version: '0'
158
- type: :development
159
- prerelease: false
160
- version_requirements: !ruby/object:Gem::Requirement
161
- requirements:
162
- - - ">="
163
- - !ruby/object:Gem::Version
164
- version: '0'
165
- - !ruby/object:Gem::Dependency
166
- name: pry-byebug
167
- requirement: !ruby/object:Gem::Requirement
168
- requirements:
169
- - - ">="
170
- - !ruby/object:Gem::Version
171
- version: '0'
172
- type: :development
173
- prerelease: false
174
- version_requirements: !ruby/object:Gem::Requirement
175
- requirements:
176
- - - ">="
177
- - !ruby/object:Gem::Version
178
- version: '0'
179
- - !ruby/object:Gem::Dependency
180
- name: rspec
181
- requirement: !ruby/object:Gem::Requirement
182
- requirements:
183
- - - "~>"
184
- - !ruby/object:Gem::Version
185
- version: 3.12.0
186
- type: :development
187
- prerelease: false
188
- version_requirements: !ruby/object:Gem::Requirement
189
- requirements:
190
- - - "~>"
191
- - !ruby/object:Gem::Version
192
- version: 3.12.0
193
- - !ruby/object:Gem::Dependency
194
- name: simplecov
195
- requirement: !ruby/object:Gem::Requirement
196
- requirements:
197
- - - "~>"
198
- - !ruby/object:Gem::Version
199
- version: 0.16.1
200
- type: :development
201
- prerelease: false
202
- version_requirements: !ruby/object:Gem::Requirement
203
- requirements:
204
- - - "~>"
205
- - !ruby/object:Gem::Version
206
- version: 0.16.1
207
- - !ruby/object:Gem::Dependency
208
- name: webmock
209
- requirement: !ruby/object:Gem::Requirement
210
- requirements:
211
- - - "~>"
212
- - !ruby/object:Gem::Version
213
- version: 3.18.1
214
- type: :development
215
- prerelease: false
216
- version_requirements: !ruby/object:Gem::Requirement
217
- requirements:
218
- - - "~>"
219
- - !ruby/object:Gem::Version
220
- version: 3.18.1
221
- - !ruby/object:Gem::Dependency
222
- name: coveralls
223
- requirement: !ruby/object:Gem::Requirement
224
- requirements:
225
- - - "~>"
226
- - !ruby/object:Gem::Version
227
- version: 0.8.23
228
- type: :development
229
- prerelease: false
230
- version_requirements: !ruby/object:Gem::Requirement
231
- requirements:
232
- - - "~>"
233
- - !ruby/object:Gem::Version
234
- version: 0.8.23
235
95
  description: CLI-Based tool that show Trending repository on github
236
96
  email:
237
97
  - terasawan@gmail.com
@@ -240,13 +100,13 @@ executables:
240
100
  extensions: []
241
101
  extra_rdoc_files: []
242
102
  files:
243
- - ".coveralls.yml"
244
103
  - ".github/dependabot.yml"
104
+ - ".github/workflows/ci.yml"
245
105
  - ".github/workflows/codeql.yml"
246
106
  - ".gitignore"
247
107
  - ".rspec"
248
108
  - ".rubocop.yml"
249
- - ".travis.yml"
109
+ - ".rubocop_todo.yml"
250
110
  - CHANGELOG.md
251
111
  - Gemfile
252
112
  - LICENSE.txt
@@ -282,7 +142,8 @@ files:
282
142
  homepage: https://github.com/rochefort/git-trend
283
143
  licenses:
284
144
  - MIT
285
- metadata: {}
145
+ metadata:
146
+ rubygems_mfa_required: 'true'
286
147
  post_install_message: "\U0001F37A Thanks for installing!"
287
148
  rdoc_options: []
288
149
  require_paths:
@@ -291,7 +152,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
291
152
  requirements:
292
153
  - - ">="
293
154
  - !ruby/object:Gem::Version
294
- version: 2.5.0
155
+ version: 2.7.0
295
156
  required_rubygems_version: !ruby/object:Gem::Requirement
296
157
  requirements:
297
158
  - - ">="
@@ -302,17 +163,4 @@ rubygems_version: 3.4.10
302
163
  signing_key:
303
164
  specification_version: 4
304
165
  summary: CLI-Based tool that show Trending repository on github
305
- test_files:
306
- - spec/fixtures/trending/alloy
307
- - spec/fixtures/trending/index
308
- - spec/fixtures/trending/ruby
309
- - spec/fixtures/trending/ruby?since=weekly
310
- - spec/fixtures/trending?since=
311
- - spec/fixtures/trending?since=daily
312
- - spec/fixtures/trending?since=monthly
313
- - spec/fixtures/trending?since=monthly.html
314
- - spec/fixtures/trending?since=weekly
315
- - spec/git_trend/cli_spec.rb
316
- - spec/git_trend/scraper_spec.rb
317
- - spec/git_trend_spec.rb
318
- - spec/spec_helper.rb
166
+ test_files: []
data/.coveralls.yml DELETED
@@ -1 +0,0 @@
1
- service_name: travis-ci
data/.travis.yml DELETED
@@ -1,16 +0,0 @@
1
- env:
2
- global:
3
- - CC_TEST_REPORTER_ID=2eb7b0f374e08e909106152c788cb32d24d6440cd41c14fe971a40a8ec971ca2
4
- language: ruby
5
- rvm:
6
- - 2.6.9
7
- - 2.7.5
8
- - 3.0.3
9
- before_script:
10
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
11
- - chmod +x ./cc-test-reporter
12
- - ./cc-test-reporter before-build
13
- script:
14
- - bundle exec rspec
15
- after_script:
16
- - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT