git-trend 1.4.2 → 1.4.3

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: b0a5d08b3b8f8d009ba85dd7ab54217e4d16adcb0aaa96451022849913adc835
4
- data.tar.gz: 3de4819956a0e80b90c22fda6f16bb6372b7d7df663bcb59cf6d212f8698414c
3
+ metadata.gz: e0c6af8c115c7e95f285ed7dfbe9d984ab0027b3408ca2be9e59e3d06e0a704a
4
+ data.tar.gz: 15455086c781a10e6d796246e96b840cf72c73b3ce3984a7d1002bb1102f5b3a
5
5
  SHA512:
6
- metadata.gz: 4367a719bb7ed8f6bdb4c84f9ae0f646d625bba405f8cee7dde2ec61da4af83e16a899755eb2754f71dc7071f8e9f45c7cf07668b74a7500f1138eed0f6e67e9
7
- data.tar.gz: 26163edd6624b21eb092e432f32fc7fc8819744c2a8f6f9fe87697d2c8b1eee068583ffd97b756f972deda931aacbd5fe2c5e6597610468ab65243a665fa8df7
6
+ metadata.gz: 0eb3f104aab30a8d551d51e965baaf06381f522905c81ea9817e33f72bc22e9c766650ef519e0595d2d58cf25b583114c85e38f6c3e590dc28cb7ed16f60ddb6
7
+ data.tar.gz: 8c9b103328283c9ff4c4011f7f400f94488aa30aab52e214f88b23bf96d9dad3046d72772540e20cda7f27f128da7a00826bfb30bb5bee377dea94752d272088
@@ -0,0 +1,24 @@
1
+ name: Smoke test
2
+
3
+ on:
4
+ schedule:
5
+ - cron: '0 0 * * *'
6
+ workflow_dispatch:
7
+
8
+ jobs:
9
+ smoke:
10
+ runs-on: ubuntu-latest
11
+ timeout-minutes: 10
12
+
13
+ steps:
14
+ - name: Checkout code
15
+ uses: actions/checkout@v7
16
+
17
+ - name: Setup Ruby
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: '3.4.12'
21
+ bundler-cache: true
22
+
23
+ - name: Run smoke test against github.com
24
+ run: bundle exec rake smoke
data/.rspec CHANGED
@@ -2,3 +2,4 @@
2
2
  --warnings
3
3
  --require spec_helper
4
4
  --format doc
5
+ --order random
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## v1.4.3 (Wed Nov 4 2026)
2
+
3
+ - Fix changing HTML structure: descriptions were always empty [3003619]
4
+ - Fix NameError when showing backtrace with --verbose [3266694]
5
+ - Fix crash when the terminal width cannot be detected [a51276c]
6
+ - Fix load path in exe/git-trend [4827161]
7
+ - Fix misaligned descriptions containing multi-byte characters such as "é" or emoji by using unicode-display_width [f7a3e7a]
8
+ - Exclude spec files from the gem package [f5b6ddc]
9
+ - Fix typos [db9877b]
10
+
1
11
  ## v1.4.2 (Tue Nov 3 2026)
2
12
 
3
13
  - Security fixes [aea1049, 08e02ee]
data/Rakefile CHANGED
@@ -17,3 +17,23 @@ task :update_fixtures do
17
17
  sh "curl -o spec/fixtures/trending?since=weekly https://github.com/trending?since=weekly"
18
18
  sh "curl -o spec/fixtures/trending?since=monthly https://github.com/trending?since=monthly"
19
19
  end
20
+
21
+ desc "check that scraping works against the live GitHub trending page"
22
+ task :smoke do
23
+ require_relative "lib/git_trend"
24
+
25
+ projects = GitTrend.get
26
+ errors = []
27
+ errors << "no projects" if projects.empty?
28
+ errors << "invalid names" unless projects.all? { |p| p.name.match?(%r{\A[\w.-]+/[\w.-]+\z}) }
29
+ errors << "no descriptions" if projects.none? { |p| !p.description.empty? }
30
+ errors << "no languages" if projects.none? { |p| !p.lang.empty? }
31
+ errors << "no all star counts" unless projects.all? { |p| p.all_star_count.positive? }
32
+ errors << "no fork counts" if projects.none? { |p| p.fork_count.positive? }
33
+ errors << "no star counts" if projects.none? { |p| p.star_count.positive? }
34
+ errors << "no selectable languages" if GitTrend.languages.empty?
35
+
36
+ abort "Smoke test failed: #{errors.join(', ')}" unless errors.empty?
37
+
38
+ puts "Smoke test passed: #{projects.size} projects"
39
+ end
data/exe/git-trend CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $LOAD_PATH.unshift(File.expand_path("/../lib", __dir__))
3
+ $LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
4
4
 
5
5
  require "git_trend"
6
6
 
data/git-trend.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.license = "MIT"
20
20
  spec.required_ruby_version = ">= 3.3.0"
21
21
 
22
- spec.files = `git ls-files -z`.split("\x0")
22
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.start_with?("spec/") }
23
23
  spec.bindir = "exe"
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
25
  spec.require_paths = ["lib"]
@@ -28,7 +28,8 @@ Gem::Specification.new do |spec|
28
28
 
29
29
  spec.add_dependency "addressable", "~> 2.9", ">= 2.9.1"
30
30
  spec.add_dependency "mechanize", ">= 2.14.1", "< 2.15.0"
31
- spec.add_dependency "thor", ">= 0.20.0", "< 1.4.0"
31
+ spec.add_dependency "thor", ">= 0.20.0", "< 1.6.0"
32
+ spec.add_dependency "unicode-display_width", "~> 3.2"
32
33
 
33
34
  spec.metadata["rubygems_mfa_required"] = "true"
34
35
  end
data/lib/git_trend/cli.rb CHANGED
@@ -22,7 +22,7 @@ module GitTrend
22
22
  desc :list, "\033[32m(DEFAULT COMMAND)\e[0m List Trending repository on github [-l, -s, -d]"
23
23
  option :language, aliases: "-l", required: false, desc: "Specify a language"
24
24
  option :since, aliases: "-s", required: false, desc: "Enable: [d, day, daily, w, week, weekly, m, month, monthly]"
25
- option :description, aliases: "-d", required: false, default: true, type: :boolean, desc: "\033[32m(DEFAULT OPTION)\e[0m Dislpay descriptions"
25
+ option :description, aliases: "-d", required: false, default: true, type: :boolean, desc: "\033[32m(DEFAULT OPTION)\e[0m Display descriptions"
26
26
  option :format, aliases: "-f", required: false, default: "text", desc: "Choose a formatter as text or json. Enable: [t, text, j, json]"
27
27
  option :number, aliases: "-n", required: false, type: :numeric, desc: "Number of lines"
28
28
  option :help, aliases: "-h", required: false, type: :boolean
@@ -37,7 +37,7 @@ module GitTrend
37
37
  say "An unexpected #{e.class} has occurred.", :red
38
38
  say e.message unless e.message == e.class.to_s # エラー内容がクラス名の場合は表示しない
39
39
 
40
- puts exception.backtrace if options[:verbose]
40
+ puts e.backtrace if options[:verbose]
41
41
  end
42
42
 
43
43
  desc :languages, "Show selectable languages"
@@ -0,0 +1,31 @@
1
+ require "unicode/display_width"
2
+
3
+ module GitTrend
4
+ module DisplayText
5
+ ELLIPSIS = "...".freeze
6
+
7
+ module_function
8
+
9
+ def width(str)
10
+ Unicode::DisplayWidth.of(str)
11
+ end
12
+
13
+ def truncate(str, truncate_at)
14
+ return str if width(str) <= truncate_at
15
+ return ELLIPSIS if truncate_at <= ELLIPSIS.length
16
+
17
+ max_width = truncate_at - ELLIPSIS.length
18
+ result = +""
19
+ current_width = 0
20
+ str.each_grapheme_cluster do |char|
21
+ char_width = width(char)
22
+ break if current_width + char_width > max_width
23
+
24
+ result << char
25
+ current_width += char_width
26
+ end
27
+
28
+ "#{result}#{ELLIPSIS}"
29
+ end
30
+ end
31
+ end
@@ -1,7 +1,10 @@
1
+ require "io/console"
2
+
1
3
  module GitTrend::Formatters
2
4
  class TextFormatter
3
5
  HEADER_COLUMNS = %w[no. name lang star description].freeze
4
6
  DEFAULT_COLUMNS_SIZES = [3, 40, 10, 6, 20].freeze
7
+ DEFAULT_TERMINAL_WIDTH = 80
5
8
 
6
9
  def print(projects, options)
7
10
  if projects.empty?
@@ -20,7 +23,7 @@ module GitTrend::Formatters
20
23
  puts
21
24
  puts "#{languages.size} languages"
22
25
  puts "you can get only selected language list with '-l' option."
23
- puts "if languages is unknown, you can specify 'unkown'."
26
+ puts "if languages is unknown, you can specify 'unknown'."
24
27
  puts
25
28
  end
26
29
 
@@ -40,8 +43,7 @@ module GitTrend::Formatters
40
43
  end
41
44
 
42
45
  def rule_max_description_size
43
- terminal_width, _terminal_height = detect_terminal_size
44
- description_width = terminal_width - @columns_sizes[0..-2].sum - (@columns_sizes.size - 1)
46
+ description_width = detect_terminal_width - @columns_sizes[0..-2].sum - (@columns_sizes.size - 1)
45
47
  if description_width >= DEFAULT_COLUMNS_SIZES.last
46
48
  @columns_sizes[-1] = description_width
47
49
  else
@@ -78,9 +80,9 @@ module GitTrend::Formatters
78
80
  projects.each_with_index do |project, i|
79
81
  data = [i + 1, [project.name, project.lang, project.star_count.to_s]].flatten
80
82
  if @enable_description
81
- description = project.description.mb_truncate(f.last)
83
+ description = GitTrend::DisplayText.truncate(project.description, f.last)
82
84
  data << description
83
- mb_char_size = description.display_width - description.size
85
+ mb_char_size = GitTrend::DisplayText.width(description) - description.size
84
86
  description_fmt = " %-#{f.last - mb_char_size}s"
85
87
  end
86
88
  result = "#{fmt}#{description_fmt}" % data
@@ -92,23 +94,12 @@ module GitTrend::Formatters
92
94
  puts
93
95
  end
94
96
 
95
- # https://github.com/cldwalker/hirb/blob/master/lib/hirb/util.rb#L61-71
96
- # rubocop:disable all
97
- def detect_terminal_size
98
- if (ENV["COLUMNS"] =~ /^\d+$/) && (ENV["LINES"] =~ /^\d+$/)
99
- [ENV["COLUMNS"].to_i, ENV["LINES"].to_i]
100
- elsif (RUBY_PLATFORM =~ /java/ || (!STDIN.tty? && ENV["TERM"])) && command_exists?("tput")
101
- [`tput cols`.to_i, `tput lines`.to_i]
102
- elsif STDIN.tty? && command_exists?("stty")
103
- `stty size`.scan(/\d+/).map(&:to_i).reverse
104
- end
105
- rescue
106
- nil
107
- end
108
- # rubocop:enable all
97
+ def detect_terminal_width
98
+ return ENV["COLUMNS"].to_i if ENV["COLUMNS"]&.match?(/\A\d+\z/)
109
99
 
110
- def command_exists?(command)
111
- ENV["PATH"].split(File::PATH_SEPARATOR).any? { |d| File.exist? File.join(d, command) }
100
+ IO.console&.winsize&.last || DEFAULT_TERMINAL_WIDTH
101
+ rescue SystemCallError
102
+ DEFAULT_TERMINAL_WIDTH
112
103
  end
113
104
  end
114
105
  end
@@ -55,7 +55,7 @@ module GitTrend
55
55
  icon_area = content.search(".f6.color-fg-muted.mt-2")
56
56
  Project.new(
57
57
  name: content.search("h2 a").attr("href").to_s.delete_prefix("/"),
58
- description: content.search(".col-9.color-fg-muted.my-1.pr-4").text.strip,
58
+ description: content.search("p.col-9").text.strip,
59
59
  lang: content.search('span[itemprop="programmingLanguage"]').text.strip,
60
60
  all_star_count: comma_to_i(icon_area.search("a:has(svg.octicon-star)").text.strip),
61
61
  fork_count: comma_to_i(icon_area.search("a:has(svg.octicon-repo-forked)").text.strip),
@@ -1,3 +1,3 @@
1
1
  module GitTrend
2
- VERSION = "1.4.2".freeze
2
+ VERSION = "1.4.3".freeze
3
3
  end
data/lib/git_trend.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require "git_trend/cli"
2
- require "git_trend/core_ext/string"
2
+ require "git_trend/display_text"
3
3
  require "git_trend/formatter"
4
4
  require "git_trend/formatters/text_formatter"
5
5
  require "git_trend/formatters/json_formatter"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-trend
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.2
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - rochefort
@@ -58,7 +58,7 @@ dependencies:
58
58
  version: 0.20.0
59
59
  - - "<"
60
60
  - !ruby/object:Gem::Version
61
- version: 1.4.0
61
+ version: 1.6.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
@@ -68,7 +68,21 @@ dependencies:
68
68
  version: 0.20.0
69
69
  - - "<"
70
70
  - !ruby/object:Gem::Version
71
- version: 1.4.0
71
+ version: 1.6.0
72
+ - !ruby/object:Gem::Dependency
73
+ name: unicode-display_width
74
+ requirement: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - "~>"
77
+ - !ruby/object:Gem::Version
78
+ version: '3.2'
79
+ type: :runtime
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: '3.2'
72
86
  description: CLI-Based tool that show Trending repository on github
73
87
  email:
74
88
  - terasawan@gmail.com
@@ -80,6 +94,7 @@ files:
80
94
  - ".github/dependabot.yml"
81
95
  - ".github/workflows/ci.yml"
82
96
  - ".github/workflows/codeql.yml"
97
+ - ".github/workflows/smoke.yml"
83
98
  - ".gitignore"
84
99
  - ".rspec"
85
100
  - ".rubocop.yml"
@@ -96,28 +111,13 @@ files:
96
111
  - lib/git-trend.rb
97
112
  - lib/git_trend.rb
98
113
  - lib/git_trend/cli.rb
99
- - lib/git_trend/core_ext/string.rb
114
+ - lib/git_trend/display_text.rb
100
115
  - lib/git_trend/formatter.rb
101
116
  - lib/git_trend/formatters/json_formatter.rb
102
117
  - lib/git_trend/formatters/text_formatter.rb
103
118
  - lib/git_trend/project.rb
104
119
  - lib/git_trend/scraper.rb
105
120
  - lib/git_trend/version.rb
106
- - note.txt
107
- - spec/fixtures/trending/alloy
108
- - spec/fixtures/trending/index
109
- - spec/fixtures/trending/ruby
110
- - spec/fixtures/trending/ruby?since=weekly
111
- - spec/fixtures/trending?since=
112
- - spec/fixtures/trending?since=daily
113
- - spec/fixtures/trending?since=monthly
114
- - spec/fixtures/trending?since=monthly.html
115
- - spec/fixtures/trending?since=weekly
116
- - spec/git_trend/cli_spec.rb
117
- - spec/git_trend/core_ext/string_spec.rb
118
- - spec/git_trend/scraper_spec.rb
119
- - spec/git_trend_spec.rb
120
- - spec/spec_helper.rb
121
121
  homepage: https://github.com/rochefort/git-trend
122
122
  licenses:
123
123
  - MIT
@@ -1,27 +0,0 @@
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/note.txt DELETED
@@ -1,8 +0,0 @@
1
- wget https://github.com/trending
2
- wget https://github.com/trending\?l=ruby
3
- wget https://github.com/trending\?l=objective-c%2B%2B
4
- wget https://github.com/trending\?since=weekly
5
- wget https://github.com/trending\?since=
6
- wget https://github.com/trending\?since=daily
7
- wget https://github.com/trending\?since=monthly
8
- wget https://github.com/trending\?l\=ruby\&since\=weekly