bundler-alive 0.1.2 → 0.1.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.
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bundler
4
+ module Alive
5
+ #
6
+ # Represents Report
7
+ #
8
+ class Report
9
+ attr_reader :result, :error_messages, :rate_limit_exceeded
10
+
11
+ #
12
+ # A result of report
13
+ #
14
+ # @param [StatusResult] result
15
+ #
16
+ def initialize(result)
17
+ @result = result.collection
18
+ @error_messages = result.error_messages
19
+ @rate_limit_exceeded = result.rate_limit_exceeded
20
+
21
+ freeze
22
+ end
23
+
24
+ #
25
+ # Save result to file
26
+ #
27
+ # @param [String] file_path
28
+ #
29
+ def save_as_file(file_path)
30
+ body = TomlRB.dump(result.to_h)
31
+ File.write(file_path, body)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler"
4
+
5
+ require "thor"
6
+
7
+ module Bundler
8
+ module Alive
9
+ class CLI < ::Thor
10
+ #
11
+ # Reports
12
+ #
13
+ module Reportable
14
+ #
15
+ # Reports result
16
+ #
17
+ # @param [Report] report
18
+ #
19
+ def print_report(report)
20
+ result = report.result
21
+ error_messages = report.error_messages
22
+ print_error(error_messages)
23
+
24
+ gems = result.need_to_report_gems
25
+ $stdout.puts if gems.size.positive?
26
+ gems.each do |_name, gem|
27
+ $stdout.puts gem.report
28
+ end
29
+
30
+ print_summary(result)
31
+ print_message(result, report.rate_limit_exceeded)
32
+ end
33
+
34
+ private
35
+
36
+ def print_error(error_messages)
37
+ return if error_messages.nil?
38
+
39
+ $stdout.puts <<~ERROR
40
+
41
+ #{error_messages.join("\n")}
42
+ ERROR
43
+ end
44
+
45
+ def print_summary(result)
46
+ $stdout.puts <<~RESULT
47
+ Total: #{result.total_size} (Dead: #{result.dead_size}, Alive: #{result.alive_size}, Unknown: #{result.unknown_size})
48
+ RESULT
49
+ end
50
+
51
+ def print_message(result, rate_limit_exceeded)
52
+ if result.all_alive?
53
+ say "All gems are alive!", :green
54
+ return
55
+ end
56
+
57
+ say "Too many requested! Retry later.", :yellow if rate_limit_exceeded
58
+ if result.dead_size.positive?
59
+ say "Not alive gems are found!", :red
60
+ return
61
+ end
62
+ say "Unknown gems are found!", :yellow if result.unknown_size.positive?
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -17,21 +17,11 @@ module Bundler
17
17
  raise ArgumentError, "Unknown url: #{url}" unless url.instance_of?(SourceCodeRepositoryUrl)
18
18
 
19
19
  @url = url
20
- @client = Client::SourceCodeClient.new(service_name: url.service_name)
21
- end
22
-
23
- #
24
- # Returns alive or not
25
- #
26
- # @return [Boolean]
27
- #
28
- def alive?
29
- !client.archived?(url)
30
20
  end
31
21
 
32
22
  private
33
23
 
34
- attr_reader :url, :client
24
+ attr_reader :url
35
25
  end
36
26
  end
37
27
  end
@@ -4,41 +4,74 @@ module Bundler
4
4
  module Alive
5
5
  # Represents a source code repository
6
6
  class SourceCodeRepositoryUrl
7
+ # service domain with service
7
8
  DOMAIN_WITH_SERVICES = {
8
- "github.com" => SourceCodeRepository::Service::GITHUB
9
+ "github.com" => SourceCodeRepository::Service::GITHUB,
10
+ "www.github.com" => SourceCodeRepository::Service::GITHUB
9
11
  }.freeze
10
12
 
11
13
  private_constant :DOMAIN_WITH_SERVICES
12
14
 
15
+ #
16
+ # Judge supported url or not
17
+ #
18
+ # @param [String] url
19
+ #
20
+ # @return [Boolean]
21
+ #
22
+ def self.support_url?(url)
23
+ return false if url.nil?
24
+
25
+ uri = URI.parse(url)
26
+ host = uri.host
27
+
28
+ DOMAIN_WITH_SERVICES.key?(host)
29
+ end
30
+
13
31
  # No supported URL Error
14
32
  class UnSupportedUrl < StandardError
15
- def initialize(url)
16
- message = "UnSupported URL: #{url}"
33
+ #
34
+ # @param [String] :url
35
+ # @param [String] :name
36
+ #
37
+ # @return [UnSupportedUrl]
38
+ #
39
+ def initialize(url:, name:)
40
+ decorated_url = if url.nil? || url == ""
41
+ "(blank)"
42
+ else
43
+ url
44
+ end
45
+ message = "[#{name}] is not support URL: #{decorated_url}"
17
46
  super(message)
18
47
  end
19
48
  end
20
49
 
21
- attr_reader :url, :service_name
50
+ attr_reader :url, :service_name, :gem_name
22
51
 
23
52
  #
24
53
  # Creates a `SourceCodeRepositoryUrl`
25
54
  #
26
55
  # @param [String] url
56
+ # @param [String] name
27
57
  #
28
58
  # @raise [UnSupportedUrl]
29
59
  #
30
- def initialize(url)
60
+ def initialize(url, name)
61
+ raise UnSupportedUrl.new(url: url, name: name) if url.nil?
62
+
31
63
  @url = url
32
- @service_name = service(url)
64
+ @service_name = service(url: url, name: name)
65
+ @gem_name = name
33
66
  end
34
67
 
35
68
  private
36
69
 
37
- def service(url)
70
+ def service(url:, name:)
38
71
  uri = URI.parse(url)
39
72
  host = uri.host
40
73
 
41
- raise UnSupportedUrl, url unless DOMAIN_WITH_SERVICES.key?(host)
74
+ raise UnSupportedUrl.new(url: url, name: name) unless DOMAIN_WITH_SERVICES.key?(host)
42
75
 
43
76
  DOMAIN_WITH_SERVICES[host]
44
77
  end
@@ -3,15 +3,30 @@
3
3
  module Bundler
4
4
  module Alive
5
5
  #
6
- # Result of gem status
6
+ # Represents Status
7
7
  #
8
- class GemStatus
9
- REPOSITORY_URL_UNKNOWN = :unknown
10
- ALIVE_UNKNOWN = :unknown
8
+ class Status
9
+ # Value of repository URL unknown
10
+ REPOSITORY_URL_UNKNOWN = "unknown"
11
+
12
+ # Value off alive unknown
13
+ ALIVE_UNKNOWN = "unknown"
11
14
 
12
15
  attr_reader :name, :repository_url, :alive, :checked_at
13
16
 
17
+ #
18
+ # Creates instance of `Status`
19
+ #
20
+ # @param [String] :name
21
+ # @param [SourceCodeRepositoryUrl] :repository_url
22
+ # @param [Boolean] :alive
23
+ # @param [] :checked_at
24
+ #
25
+ # @return [Status]
26
+ #
14
27
  def initialize(name:, repository_url:, alive:, checked_at:)
28
+ raise ArgumentError if !repository_url.nil? && !repository_url.instance_of?(SourceCodeRepositoryUrl)
29
+
15
30
  repository_url = REPOSITORY_URL_UNKNOWN if repository_url.nil?
16
31
  alive = ALIVE_UNKNOWN if alive.nil?
17
32
 
@@ -24,7 +39,7 @@ module Bundler
24
39
  end
25
40
 
26
41
  #
27
- # Alive?
42
+ # Is status of alive unknown?
28
43
  #
29
44
  # @return [Boolean]
30
45
  #
@@ -39,7 +54,7 @@ module Bundler
39
54
  {
40
55
  repository_url: decorated_repository_url,
41
56
  alive: decorated_alive,
42
- checked_at: checked_at
57
+ checked_at: checked_at || ""
43
58
  }
44
59
  end
45
60
 
@@ -61,7 +76,7 @@ module Bundler
61
76
 
62
77
  def decorated_repository_url
63
78
  if repository_url == REPOSITORY_URL_UNKNOWN
64
- REPOSITORY_URL_UNKNOWN.to_s
79
+ REPOSITORY_URL_UNKNOWN
65
80
  else
66
81
  repository_url.url
67
82
  end
@@ -69,7 +84,7 @@ module Bundler
69
84
 
70
85
  def decorated_alive
71
86
  if alive == ALIVE_UNKNOWN
72
- ALIVE_UNKNOWN.to_s
87
+ ALIVE_UNKNOWN
73
88
  else
74
89
  alive
75
90
  end
@@ -0,0 +1,149 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "forwardable"
4
+
5
+ module Bundler
6
+ module Alive
7
+ # Collection of `Status`
8
+ class StatusCollection
9
+ extend Forwardable
10
+ delegate each: :collection
11
+ delegate values: :collection
12
+
13
+ attr_reader :alive_size, :dead_size, :unknown_size
14
+
15
+ #
16
+ # Creates `StatusCollection` from TOML file
17
+ #
18
+ # @param [String] path
19
+ #
20
+ # @return [StatusCollection]
21
+ #
22
+ def self.new_from_toml_file(path)
23
+ return new unless File.exist?(path)
24
+
25
+ collection = new
26
+ TomlRB.load_file(path).each do |name, v|
27
+ next if v["alive"] == Status::ALIVE_UNKNOWN
28
+
29
+ url = SourceCodeRepositoryUrl.new(v["repository_url"], name)
30
+ status = Status.new(name: name, repository_url: url,
31
+ alive: v["alive"], checked_at: v["checked_at"])
32
+ collection = collection.add(name, status)
33
+ end
34
+
35
+ collection
36
+ end
37
+
38
+ #
39
+ # Generates instance of `StatusCollection`
40
+ #
41
+ # @param [StatusCollection|nil] collection
42
+ #
43
+ # @return [StatusCollection]
44
+ #
45
+ def initialize(collection = {})
46
+ @collection = collection
47
+ @statuses_values = collection.values || []
48
+
49
+ @alive_size = _alive_size
50
+ @unknown_size = _unknown_size
51
+ @dead_size = _dead_size
52
+ freeze
53
+ end
54
+
55
+ #
56
+ # Fetch `Status` of `name`
57
+ #
58
+ # @param [String] name
59
+ #
60
+ # @return [Status]
61
+ #
62
+ def [](name)
63
+ collection[name]
64
+ end
65
+
66
+ #
67
+ # Names of gems
68
+ #
69
+ # @return [Array<String>]
70
+ #
71
+ def names
72
+ values.map(&:name)
73
+ end
74
+
75
+ #
76
+ # Add status
77
+ #
78
+ # @param [String] name
79
+ # @param [Status] status
80
+ #
81
+ # @return [StatusCollection]
82
+ #
83
+ def add(name, status)
84
+ collection[name] = status
85
+
86
+ self.class.new(collection)
87
+ end
88
+
89
+ #
90
+ # Merge collection
91
+ #
92
+ # @param [StatusCollection] collection
93
+ #
94
+ # @return [StatusCollection]
95
+ #
96
+ def merge(collection)
97
+ return self.class.new(self.collection) if collection.nil?
98
+
99
+ collection.each do |k, v|
100
+ self.collection[k] = v
101
+ end
102
+
103
+ self.class.new(self.collection)
104
+ end
105
+
106
+ def to_h
107
+ collection.transform_values(&:to_h)
108
+ end
109
+
110
+ def need_to_report_gems
111
+ collection.find_all { |_name, gem| !!!gem.alive }
112
+ end
113
+
114
+ #
115
+ # All of statuses are alive nor not
116
+ #
117
+ # @return [Boolean]
118
+ #
119
+ def all_alive?
120
+ collection.find { |_name, status| !!!status.alive || status.unknown? }.nil?
121
+ end
122
+
123
+ #
124
+ # Total size of collection
125
+ #
126
+ # @return [Integer]
127
+ #
128
+ def total_size
129
+ collection.size
130
+ end
131
+
132
+ private
133
+
134
+ attr_reader :collection, :statuses_values
135
+
136
+ def _alive_size
137
+ statuses_values.count { |gem| !!gem.alive && !gem.unknown? }
138
+ end
139
+
140
+ def _dead_size
141
+ statuses_values.count { |gem| !gem.alive && !gem.unknown? }
142
+ end
143
+
144
+ def _unknown_size
145
+ statuses_values.count { |gem| gem.alive == Status::ALIVE_UNKNOWN }
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bundler
4
+ module Alive
5
+ #
6
+ # Represents Result of Status
7
+ #
8
+ class StatusResult
9
+ attr_reader :collection, :error_messages, :rate_limit_exceeded
10
+
11
+ #
12
+ # Creates a new StatusResult instance
13
+ #
14
+ # @param [StatusCollection|nil] :collection
15
+ # @param [Array|nil] :error_messages
16
+ # @param [Boolean|nil] :rate_limit_exceeded
17
+ #
18
+ # @return [StatusResult]
19
+ #
20
+ def initialize(collection: nil, error_messages: nil, rate_limit_exceeded: nil)
21
+ @collection = collection
22
+ @error_messages = error_messages
23
+ @rate_limit_exceeded = rate_limit_exceeded
24
+ end
25
+
26
+ #
27
+ # Merge `StatusResult`, then returns new one
28
+ #
29
+ # @param [StatusResult] result
30
+ #
31
+ # @return [StatusResult]
32
+ #
33
+ def merge(result)
34
+ self.class.new(collection: result.collection,
35
+ error_messages: result.error_messages,
36
+ rate_limit_exceeded: result.rate_limit_exceeded)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Bundler
4
4
  module Alive
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.3"
6
6
  end
7
7
  end
data/lib/bundler/alive.rb CHANGED
@@ -4,8 +4,13 @@ require_relative "alive/version"
4
4
  require_relative "alive/doctor"
5
5
  require_relative "alive/source_code_repository"
6
6
  require_relative "alive/source_code_repository_url"
7
- require_relative "alive/gem_status"
8
- require_relative "alive/gem_status_collection"
9
- require_relative "alive/client/gems_api"
7
+ require_relative "alive/status"
8
+ require_relative "alive/status_result"
9
+ require_relative "alive/status_collection"
10
+ require_relative "alive/announcer"
11
+ require_relative "alive/report"
12
+ require_relative "alive/client/gems_api_client"
13
+ require_relative "alive/client/gems_api_response"
10
14
  require_relative "alive/client/git_hub_api"
11
15
  require_relative "alive/client/source_code_client"
16
+ require_relative "alive/reportable"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bundler-alive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katsuhiko YOSHIDA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-08 00:00:00.000000000 Z
11
+ date: 2022-05-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: bundler-alive reports gems are archived or not.
14
14
  email:
@@ -22,7 +22,6 @@ files:
22
22
  - ".rspec"
23
23
  - ".rubocop.yml"
24
24
  - Gemfile
25
- - Gemfile.lock
26
25
  - LICENSE
27
26
  - README.md
28
27
  - Rakefile
@@ -30,15 +29,20 @@ files:
30
29
  - bin/bundler-alive
31
30
  - bundler-alive.gemspec
32
31
  - lib/bundler/alive.rb
32
+ - lib/bundler/alive/announcer.rb
33
33
  - lib/bundler/alive/cli.rb
34
- - lib/bundler/alive/client/gems_api.rb
34
+ - lib/bundler/alive/client/gems_api_client.rb
35
+ - lib/bundler/alive/client/gems_api_response.rb
35
36
  - lib/bundler/alive/client/git_hub_api.rb
36
37
  - lib/bundler/alive/client/source_code_client.rb
37
38
  - lib/bundler/alive/doctor.rb
38
- - lib/bundler/alive/gem_status.rb
39
- - lib/bundler/alive/gem_status_collection.rb
39
+ - lib/bundler/alive/report.rb
40
+ - lib/bundler/alive/reportable.rb
40
41
  - lib/bundler/alive/source_code_repository.rb
41
42
  - lib/bundler/alive/source_code_repository_url.rb
43
+ - lib/bundler/alive/status.rb
44
+ - lib/bundler/alive/status_collection.rb
45
+ - lib/bundler/alive/status_result.rb
42
46
  - lib/bundler/alive/version.rb
43
47
  homepage: https://github.com/kyoshidajp/bundler-alive
44
48
  licenses: []
data/Gemfile.lock DELETED
@@ -1,119 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- bundler-alive (0.1.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- addressable (2.8.0)
10
- public_suffix (>= 2.0.2, < 5.0)
11
- ast (2.4.2)
12
- citrus (3.0.2)
13
- crack (0.4.5)
14
- rexml
15
- diff-lcs (1.5.0)
16
- docile (1.4.0)
17
- faraday (1.10.0)
18
- faraday-em_http (~> 1.0)
19
- faraday-em_synchrony (~> 1.0)
20
- faraday-excon (~> 1.1)
21
- faraday-httpclient (~> 1.0)
22
- faraday-multipart (~> 1.0)
23
- faraday-net_http (~> 1.0)
24
- faraday-net_http_persistent (~> 1.0)
25
- faraday-patron (~> 1.0)
26
- faraday-rack (~> 1.0)
27
- faraday-retry (~> 1.0)
28
- ruby2_keywords (>= 0.0.4)
29
- faraday-em_http (1.0.0)
30
- faraday-em_synchrony (1.0.0)
31
- faraday-excon (1.1.0)
32
- faraday-httpclient (1.0.1)
33
- faraday-multipart (1.0.3)
34
- multipart-post (>= 1.2, < 3)
35
- faraday-net_http (1.0.1)
36
- faraday-net_http_persistent (1.2.0)
37
- faraday-patron (1.0.0)
38
- faraday-rack (1.0.0)
39
- faraday-retry (1.0.3)
40
- hashdiff (1.0.1)
41
- multipart-post (2.1.1)
42
- octokit (4.22.0)
43
- faraday (>= 0.9)
44
- sawyer (~> 0.8.0, >= 0.5.3)
45
- parallel (1.22.1)
46
- parser (3.1.2.0)
47
- ast (~> 2.4.1)
48
- public_suffix (4.0.7)
49
- rainbow (3.1.1)
50
- rake (13.0.6)
51
- regexp_parser (2.3.1)
52
- rexml (3.2.5)
53
- rspec (3.11.0)
54
- rspec-core (~> 3.11.0)
55
- rspec-expectations (~> 3.11.0)
56
- rspec-mocks (~> 3.11.0)
57
- rspec-core (3.11.0)
58
- rspec-support (~> 3.11.0)
59
- rspec-expectations (3.11.0)
60
- diff-lcs (>= 1.2.0, < 2.0)
61
- rspec-support (~> 3.11.0)
62
- rspec-mocks (3.11.1)
63
- diff-lcs (>= 1.2.0, < 2.0)
64
- rspec-support (~> 3.11.0)
65
- rspec-support (3.11.0)
66
- rubocop (1.29.0)
67
- parallel (~> 1.10)
68
- parser (>= 3.1.0.0)
69
- rainbow (>= 2.2.2, < 4.0)
70
- regexp_parser (>= 1.8, < 3.0)
71
- rexml (>= 3.2.5, < 4.0)
72
- rubocop-ast (>= 1.17.0, < 2.0)
73
- ruby-progressbar (~> 1.7)
74
- unicode-display_width (>= 1.4.0, < 3.0)
75
- rubocop-ast (1.17.0)
76
- parser (>= 3.1.1.0)
77
- ruby-progressbar (1.11.0)
78
- ruby2_keywords (0.0.5)
79
- sawyer (0.8.2)
80
- addressable (>= 2.3.5)
81
- faraday (> 0.8, < 2.0)
82
- simplecov (0.21.2)
83
- docile (~> 1.1)
84
- simplecov-html (~> 0.11)
85
- simplecov_json_formatter (~> 0.1)
86
- simplecov-html (0.12.3)
87
- simplecov_json_formatter (0.1.4)
88
- thor (1.2.1)
89
- toml-rb (2.1.2)
90
- citrus (~> 3.0, > 3.0)
91
- unicode-display_width (2.1.0)
92
- vcr (6.1.0)
93
- webmock (3.14.0)
94
- addressable (>= 2.8.0)
95
- crack (>= 0.3.2)
96
- hashdiff (>= 0.4.0, < 2.0.0)
97
- yard (0.9.20)
98
-
99
- PLATFORMS
100
- arm64-darwin-20
101
- ruby
102
- x86_64-darwin-20
103
-
104
- DEPENDENCIES
105
- bundler-alive!
106
- faraday
107
- octokit
108
- rake (~> 13.0)
109
- rspec (~> 3.0)
110
- rubocop (~> 1.21)
111
- simplecov
112
- thor
113
- toml-rb
114
- vcr
115
- webmock
116
- yard
117
-
118
- BUNDLED WITH
119
- 2.3.13