git-trend 1.3.0 → 1.4.1
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 +4 -4
- data/.github/workflows/ci.yml +42 -0
- data/.rubocop.yml +85 -2
- data/.rubocop_todo.yml +15 -0
- data/CHANGELOG.md +13 -6
- data/Gemfile +11 -0
- data/README.md +6 -4
- data/git-trend.gemspec +6 -20
- data/lib/git-trend.rb +1 -1
- data/lib/git_trend/cli.rb +6 -4
- data/lib/git_trend/core_ext/string.rb +27 -0
- data/lib/git_trend/formatter.rb +1 -0
- data/lib/git_trend/formatters/json_formatter.rb +2 -2
- data/lib/git_trend/formatters/text_formatter.rb +8 -5
- data/lib/git_trend/scraper.rb +8 -6
- data/lib/git_trend/version.rb +1 -1
- data/lib/git_trend.rb +1 -0
- data/spec/git_trend/cli_spec.rb +47 -33
- data/spec/git_trend/core_ext/string_spec.rb +36 -0
- data/spec/git_trend/scraper_spec.rb +8 -3
- data/spec/git_trend_spec.rb +65 -48
- data/spec/spec_helper.rb +3 -14
- metadata +15 -195
- data/.coveralls.yml +0 -1
- data/.travis.yml +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48d85d080f7f9e48254ad02bbdb327ac0e4c811ce2db883a8b6f712119892028
|
4
|
+
data.tar.gz: 8f083dfb30dc9af3aefd6c1a33facebbd77cf5704cdd534c867260d84affd829
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4d7b80c1f86a6e8756854c08d86c3047d717438e8fe7a162bf18a7d1f0835604424cf50edf51cfba690778b5be258a1cf9ff8cb2a45daea6ffa4176f0c9b9d8
|
7
|
+
data.tar.gz: 1bcae8a943eeeeb5f2185b156cfc7f26e2b5165d84712de3619a199d25c786f4656097e048a74c826fbadfc3721bda74da6d46ca5afbc23c14d9d537c4d7e5e1
|
@@ -0,0 +1,42 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
pull_request:
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
test:
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
timeout-minutes: 10
|
11
|
+
strategy:
|
12
|
+
matrix:
|
13
|
+
ruby-version: ['3.2.9', '3.3.9', '3.4.7']
|
14
|
+
include:
|
15
|
+
- ruby-version: '3.4.7'
|
16
|
+
upload-coverage: true
|
17
|
+
|
18
|
+
steps:
|
19
|
+
- name: Checkout code
|
20
|
+
uses: actions/checkout@v4
|
21
|
+
|
22
|
+
- name: Setup Ruby
|
23
|
+
uses: ruby/setup-ruby@v1
|
24
|
+
with:
|
25
|
+
ruby-version: ${{ matrix.ruby-version }}
|
26
|
+
bundler-cache: true
|
27
|
+
|
28
|
+
- name: Show ruby version
|
29
|
+
run: ruby -v
|
30
|
+
|
31
|
+
- name: Run tests
|
32
|
+
run: bundle exec rspec
|
33
|
+
|
34
|
+
- name: Run lint
|
35
|
+
run: bundle exec rubocop
|
36
|
+
|
37
|
+
- name: Upload coverage reports to Codecov
|
38
|
+
if: matrix.upload-coverage
|
39
|
+
uses: codecov/codecov-action@v3
|
40
|
+
with:
|
41
|
+
files: ./coverage/.resultset.json
|
42
|
+
token: ${{ secrets.CODECOV_TOKEN }}
|
data/.rubocop.yml
CHANGED
@@ -1,5 +1,88 @@
|
|
1
|
-
inherit_from:
|
2
|
-
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
plugins:
|
4
|
+
- rubocop-performance
|
5
|
+
- rubocop-rake
|
6
|
+
- rubocop-rspec
|
7
|
+
|
8
|
+
AllCops:
|
9
|
+
TargetRubyVersion: 3.2
|
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,10 @@
|
|
1
|
+
## v1.4.1 (Tue Oct 14 2025)
|
2
|
+
- Drop support of Ruby 3.1 and earlier [d2b4080]
|
3
|
+
|
4
|
+
## v1.4.0 (Mon Mar 13 2023)
|
5
|
+
|
6
|
+
- Drop support of Ruby 2.6 and earlier [41e871e]
|
7
|
+
|
1
8
|
## v1.3.0 (Mon Mar 13 2023)
|
2
9
|
|
3
10
|
- Fix changing HTML structure [8de4920]
|
@@ -24,11 +31,11 @@
|
|
24
31
|
|
25
32
|
## v1.2.4 (Mon Mar 2 2020)
|
26
33
|
|
27
|
-
- Fix languages without
|
34
|
+
- Fix languages without linefeed [ecc63af]
|
28
35
|
|
29
36
|
## v1.2.3 (Mon Mar 2 2020)
|
30
37
|
|
31
|
-
- Fix wrong
|
38
|
+
- Fix wrong integer format of star [dbdc344]
|
32
39
|
|
33
40
|
## v1.2.2 (Sun Dec 15 2019)
|
34
41
|
|
@@ -44,7 +51,7 @@
|
|
44
51
|
|
45
52
|
## v1.1.9 (Sat Mar 16 2017)
|
46
53
|
|
47
|
-
- Fix
|
54
|
+
- Fix language result is zero (#24) [9bb8785]
|
48
55
|
|
49
56
|
## v1.1.8 (Sat Jul 22 2017)
|
50
57
|
|
@@ -98,7 +105,7 @@
|
|
98
105
|
- Update gems [29bc2a9]
|
99
106
|
|
100
107
|
## v0.2.1 (Sun Dec 6 2015)
|
101
|
-
- Fix #6 redundancy line feeds when including
|
108
|
+
- Fix #6 redundancy line feeds when including multi-byte characters [61fd81c]
|
102
109
|
- Update gems [ea5a018]
|
103
110
|
|
104
111
|
## v0.2.0 (Tue Dec 3 2015)
|
@@ -125,7 +132,7 @@
|
|
125
132
|
- Add number option #3 [7cff5b4]
|
126
133
|
|
127
134
|
## v0.1.3
|
128
|
-
- The `
|
135
|
+
- The `description` option of `list` command was changed into the default. [3602272]
|
129
136
|
|
130
137
|
## v0.1.2
|
131
138
|
- Fix travis ci error #24 [6752e1d]
|
@@ -156,7 +163,7 @@ Add a magic comment for ruby1.9 #2
|
|
156
163
|
- Fix lack of addressable gem when installing [54ca275]
|
157
164
|
|
158
165
|
## v0.0.4
|
159
|
-
- Implement
|
166
|
+
- Implement description option [4587e56]
|
160
167
|
|
161
168
|
## v0.0.3
|
162
169
|
- 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
|
-
[](https://coveralls.io/github/rochefort/git-trend?branch=master)
|
3
|
-
[](https://codeclimate.com/github/rochefort/git-trend/maintainability)
|
1
|
+
[](https://codecov.io/gh/rochefort/git-trend)
|
4
2
|
[](http://badge.fury.io/rb/git-trend)
|
5
3
|
|
6
4
|
|
@@ -9,6 +7,10 @@
|
|
9
7
|
`git-trend` is a gem that fetches [Trending repositories on GitHub](https://github.com/trending).
|
10
8
|
And this also work as a command line utility.
|
11
9
|
|
10
|
+
## Buy me a coffee
|
11
|
+
|
12
|
+
If you can contribute or you want to, feel free to do it at [__Buy me a coffee! :coffee:__](https://www.buymeacoffee.com/rochefort), I will be really thankfull for anything even if it is a coffee or just a kind comment towards my work, because that helps me a lot. Whenever you contribute with a donation, I will read your message and it will be shown in my main site.
|
13
|
+
|
12
14
|
# TOC
|
13
15
|
* [Requirements](#requirements)
|
14
16
|
* [Installation](#installation)
|
@@ -20,7 +22,7 @@ And this also work as a command line utility.
|
|
20
22
|
|
21
23
|
## Requirements
|
22
24
|
|
23
|
-
Ruby versions is 2
|
25
|
+
Ruby versions is 3.2 or later.
|
24
26
|
|
25
27
|
## Installation
|
26
28
|
Add this line to your application's Gemfile:
|
data/git-trend.gemspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
lib = File.expand_path("
|
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,19 @@ 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.
|
20
|
+
spec.required_ruby_version = ">= 3.2.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
|
-
spec.add_dependency "
|
32
|
-
spec.add_dependency "
|
33
|
-
spec.add_dependency "thor", ">= 0.20.0", "< 1.3.0"
|
34
|
-
spec.add_dependency "unicode-display_width"
|
30
|
+
spec.add_dependency "mechanize", ">= 2.8.5", "< 2.11.0"
|
31
|
+
spec.add_dependency "thor", ">= 0.20.0", "< 1.4.0"
|
35
32
|
|
36
|
-
|
37
|
-
spec.
|
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"
|
33
|
+
# FIXME: mfa
|
34
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
49
35
|
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"
|
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
|
38
|
+
say e.message unless e.message == e.class.to_s # エラー内容がクラス名の場合は表示しない
|
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,
|
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
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class String
|
2
|
+
def mb_truncate(truncate_at)
|
3
|
+
return self if display_width <= truncate_at
|
4
|
+
|
5
|
+
ellipsis = "..."
|
6
|
+
return ellipsis if truncate_at <= ellipsis.length
|
7
|
+
|
8
|
+
max_width = truncate_at - ellipsis.length
|
9
|
+
result = ""
|
10
|
+
current_width = 0
|
11
|
+
each_char do |char|
|
12
|
+
char_width = char.bytesize == 1 ? 1 : 2
|
13
|
+
break if current_width + char_width > max_width
|
14
|
+
|
15
|
+
result += char
|
16
|
+
current_width += char_width
|
17
|
+
end
|
18
|
+
|
19
|
+
"#{result}#{ellipsis}"
|
20
|
+
rescue
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
def display_width
|
25
|
+
each_char.sum { |char| char.bytesize == 1 ? 1 : 2 }
|
26
|
+
end
|
27
|
+
end
|
data/lib/git_trend/formatter.rb
CHANGED
@@ -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
|
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)
|
@@ -1,9 +1,7 @@
|
|
1
|
-
require "mb_string"
|
2
|
-
|
3
1
|
module GitTrend::Formatters
|
4
2
|
class TextFormatter
|
5
|
-
HEADER_COLUMNS = %w
|
6
|
-
DEFAULT_COLUMNS_SIZES = [3, 40, 10, 6, 20]
|
3
|
+
HEADER_COLUMNS = %w[no. name lang star description].freeze
|
4
|
+
DEFAULT_COLUMNS_SIZES = [3, 40, 10, 6, 20].freeze
|
7
5
|
|
8
6
|
def print(projects, options)
|
9
7
|
if projects.empty?
|
@@ -27,6 +25,7 @@ module GitTrend::Formatters
|
|
27
25
|
end
|
28
26
|
|
29
27
|
private
|
28
|
+
|
30
29
|
def render_zero
|
31
30
|
puts "It looks like we don’t have any trending repositories."
|
32
31
|
puts
|
@@ -42,7 +41,7 @@ module GitTrend::Formatters
|
|
42
41
|
|
43
42
|
def rule_max_description_size
|
44
43
|
terminal_width, _terminal_height = detect_terminal_size
|
45
|
-
description_width = terminal_width - @columns_sizes[0..-2].
|
44
|
+
description_width = terminal_width - @columns_sizes[0..-2].sum - (@columns_sizes.size - 1)
|
46
45
|
if description_width >= DEFAULT_COLUMNS_SIZES.last
|
47
46
|
@columns_sizes[-1] = description_width
|
48
47
|
else
|
@@ -71,6 +70,7 @@ module GitTrend::Formatters
|
|
71
70
|
puts fmt % @columns_sizes.map { |column| "-" * column }
|
72
71
|
end
|
73
72
|
|
73
|
+
# rubocop:disable Metrics/AbcSize
|
74
74
|
def render_body(projects)
|
75
75
|
f = @columns_sizes
|
76
76
|
fmt = "%#{f[0]}s %-#{f[1]}s %-#{f[2]}s %#{f[3]}s"
|
@@ -87,12 +87,14 @@ module GitTrend::Formatters
|
|
87
87
|
puts result.rstrip
|
88
88
|
end
|
89
89
|
end
|
90
|
+
# rubocop:enable Metrics/AbcSize
|
90
91
|
|
91
92
|
def render_footer
|
92
93
|
puts
|
93
94
|
end
|
94
95
|
|
95
96
|
# https://github.com/cldwalker/hirb/blob/master/lib/hirb/util.rb#L61-71
|
97
|
+
# rubocop:disable all
|
96
98
|
def detect_terminal_size
|
97
99
|
if (ENV["COLUMNS"] =~ /^\d+$/) && (ENV["LINES"] =~ /^\d+$/)
|
98
100
|
[ENV["COLUMNS"].to_i, ENV["LINES"].to_i]
|
@@ -104,6 +106,7 @@ module GitTrend::Formatters
|
|
104
106
|
rescue
|
105
107
|
nil
|
106
108
|
end
|
109
|
+
# rubocop:enable all
|
107
110
|
|
108
111
|
def command_exists?(command)
|
109
112
|
ENV["PATH"].split(File::PATH_SEPARATOR).any? { |d| File.exist? File.join(d, command) }
|
data/lib/git_trend/scraper.rb
CHANGED
@@ -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.
|
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
|
data/lib/git_trend/version.rb
CHANGED