bundle_update_interactive 0.1.1 → 0.2.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: 79f73540a0e6abc4e9cf56c3333420d4fede8f87694e12e4881670201a47313c
4
- data.tar.gz: 3dc401815571eec01c46306dc76df3b741fa5506c944498dad56f4237543b1ba
3
+ metadata.gz: 29c88bba35c4c9dc4c8240fc82afaa24c6ca1285ceceef1a43eef812b40cf090
4
+ data.tar.gz: a2fe1b8c99049ace9618297eebe954f3f744219eb11dc7298364611069ed0eb8
5
5
  SHA512:
6
- metadata.gz: 2c295be43958998c5c3680890f5652aff27828bca804e682aa2eef6d057963122c33168843337d0f177dce13c5a689098882e47b849d157b8f68d6b4af0f2409
7
- data.tar.gz: '01549bc47257811dd3fc9088cbba0efffa7e0b4dd9208eb82f0279f47cad558e07a4aba087703f6ec2aa21f441834ba7c49660d4635ac58812e0a388bb0abe62'
6
+ metadata.gz: 534ea176d1c50e3caaafcf10c35fbd4f3ca5732cde8beab21bb3889ea6c85e7011dd52118f1d161dad9f0fb93a2046115fa3e30fc5b637764c02cb35d646b21f
7
+ data.tar.gz: 2c9fee79c3d3404daac0558c44ed79717e493d47155d58a73fa4485470e119d51cd6be315e4830f449c3c8f96a18ea726eb56bd992db3485d0e3e1cfe692ccf2
@@ -39,6 +39,8 @@ class BundleUpdateInteractive::CLI
39
39
  exit(130)
40
40
  }
41
41
  )
42
+ add_keybindings
43
+
42
44
  @pastel = BundleUpdateInteractive.pastel
43
45
  end
44
46
 
@@ -51,6 +53,13 @@ class BundleUpdateInteractive::CLI
51
53
 
52
54
  attr_reader :pastel, :table, :tty_prompt, :title
53
55
 
56
+ def add_keybindings
57
+ tty_prompt.on(:keypress) do |event|
58
+ tty_prompt.trigger(:keyup) if %w[k p].include?(event.value)
59
+ tty_prompt.trigger(:keydown) if %w[j n].include?(event.value)
60
+ end
61
+ end
62
+
54
63
  def help
55
64
  [
56
65
  pastel.dim("\nPress <space> to select, ↑/↓ move, <ctrl-a> all, <ctrl-r> reverse, <enter> to finish."),
@@ -28,7 +28,7 @@ class BundleUpdateInteractive::CLI
28
28
 
29
29
  def render
30
30
  lines = [render_header]
31
- rows.each_key { |name| lines << render_gem(name) }
31
+ rows.keys.sort.each { |name| lines << render_gem(name) }
32
32
  lines.join("\n")
33
33
  end
34
34
 
@@ -50,7 +50,7 @@ class BundleUpdateInteractive::CLI
50
50
 
51
51
  if given_args.first == "help"
52
52
  retry_with_args = ["help"] if given_args.length > 1
53
- elsif e.unknown.intersect?(%w[-h --help])
53
+ elsif (e.unknown & %w[-h --help]).any?
54
54
  retry_with_args = ["help", (given_args - e.unknown).first]
55
55
  end
56
56
  raise unless retry_with_args.any?
@@ -2,19 +2,21 @@
2
2
 
3
3
  module BundleUpdateInteractive
4
4
  class OutdatedGem
5
- attr_reader :current_lockfile_entry, :updated_lockfile_entry, :gemfile_groups
6
- attr_writer :vulnerable
5
+ attr_accessor :name,
6
+ :gemfile_groups,
7
+ :git_source_uri,
8
+ :current_version,
9
+ :current_git_version,
10
+ :updated_version,
11
+ :updated_git_version
7
12
 
8
- def initialize(current_lockfile_entry:, updated_lockfile_entry:, gemfile_groups:)
9
- @current_lockfile_entry = current_lockfile_entry
10
- @updated_lockfile_entry = updated_lockfile_entry
11
- @gemfile_groups = gemfile_groups
12
- @changelog_locator = ChangelogLocator.new
13
+ attr_writer :rubygems_source, :vulnerable
14
+
15
+ def initialize(**attrs)
13
16
  @vulnerable = nil
14
- end
17
+ @changelog_locator = ChangelogLocator.new
15
18
 
16
- def name
17
- current_lockfile_entry.name
19
+ attrs.each { |name, value| public_send(:"#{name}=", value) }
18
20
  end
19
21
 
20
22
  def semver_change
@@ -25,13 +27,17 @@ module BundleUpdateInteractive
25
27
  @vulnerable
26
28
  end
27
29
 
30
+ def rubygems_source?
31
+ @rubygems_source
32
+ end
33
+
28
34
  def changelog_uri
29
35
  return @changelog_uri if defined?(@changelog_uri)
30
36
 
31
37
  @changelog_uri =
32
38
  if git_version_changed?
33
39
  "https://github.com/#{github_repo}/compare/#{current_git_version}...#{updated_git_version}"
34
- elsif updated_lockfile_entry.rubygems_source?
40
+ elsif rubygems_source?
35
41
  changelog_locator.find_changelog_uri(name: name, version: updated_version.to_s)
36
42
  else
37
43
  begin
@@ -42,22 +48,6 @@ module BundleUpdateInteractive
42
48
  end
43
49
  end
44
50
 
45
- def current_version
46
- current_lockfile_entry.version
47
- end
48
-
49
- def updated_version
50
- updated_lockfile_entry.version
51
- end
52
-
53
- def current_git_version
54
- current_lockfile_entry.git_version
55
- end
56
-
57
- def updated_git_version
58
- updated_lockfile_entry.git_version
59
- end
60
-
61
51
  def git_version_changed?
62
52
  current_git_version && updated_git_version && current_git_version != updated_git_version
63
53
  end
@@ -69,8 +59,7 @@ module BundleUpdateInteractive
69
59
  def github_repo
70
60
  return nil unless updated_git_version
71
61
 
72
- updated_lockfile_entry.git_source_uri.to_s[%r{^(?:git@github.com:|https://github.com/)([^/]+/[^/]+?)(:?\.git)?(?:$|/)}i,
73
- 1]
62
+ git_source_uri.to_s[%r{^(?:git@github.com:|https://github.com/)([^/]+/[^/]+?)(:?\.git)?(?:$|/)}i, 1]
74
63
  end
75
64
  end
76
65
  end
@@ -21,16 +21,12 @@ module BundleUpdateInteractive
21
21
 
22
22
  def initialize(gemfile:, current_lockfile:, updated_lockfile:)
23
23
  @current_lockfile = current_lockfile
24
- outdated_names = current_lockfile.entries.each_with_object([]) do |current_entry, arr|
25
- updated_entry = updated_lockfile[current_entry.name]
26
- arr << current_entry.name if current_entry.older_than?(updated_entry)
27
- end
28
- @outdated_gems ||= outdated_names.sort.each_with_object({}) do |name, hash|
29
- hash[name] = OutdatedGem.new(
30
- current_lockfile_entry: current_lockfile[name],
31
- updated_lockfile_entry: updated_lockfile[name],
32
- gemfile_groups: gemfile[name]&.groups
33
- )
24
+ @outdated_gems ||= current_lockfile.entries.each_with_object({}) do |current_lockfile_entry, hash|
25
+ name = current_lockfile_entry.name
26
+ updated_lockfile_entry = updated_lockfile[name]
27
+ next unless current_lockfile_entry.older_than?(updated_lockfile_entry)
28
+
29
+ hash[name] = build_outdated_gem(current_lockfile_entry, updated_lockfile_entry, gemfile[name]&.groups)
34
30
  end.freeze
35
31
  end
36
32
 
@@ -39,12 +35,14 @@ module BundleUpdateInteractive
39
35
  end
40
36
 
41
37
  def updateable_gems
42
- outdated_gems.reject { |_, gem| gem.current_lockfile_entry.exact_dependency? }
38
+ @updateable_gems ||= outdated_gems.reject do |name, _|
39
+ current_lockfile[name].exact_dependency?
40
+ end.freeze
43
41
  end
44
42
 
45
43
  def expand_gems_with_exact_dependencies(*gem_names)
46
44
  gem_names.flatten!
47
- gem_names.flat_map { [_1, *outdated_gems[_1].current_lockfile_entry.exact_dependencies] }.uniq
45
+ gem_names.flat_map { |name| [name, *current_lockfile[name].exact_dependencies] }.uniq
48
46
  end
49
47
 
50
48
  def scan_for_vulnerabilities!
@@ -55,7 +53,7 @@ module BundleUpdateInteractive
55
53
  vulnerable_gem_names = Set.new(audit_report.vulnerable_gems.map(&:name))
56
54
 
57
55
  outdated_gems.each do |name, gem|
58
- gem.vulnerable = vulnerable_gem_names.intersect?([name, *current_lockfile[name].exact_dependencies])
56
+ gem.vulnerable = (vulnerable_gem_names & [name, *current_lockfile[name].exact_dependencies]).any?
59
57
  end
60
58
  true
61
59
  end
@@ -68,5 +66,18 @@ module BundleUpdateInteractive
68
66
  private
69
67
 
70
68
  attr_reader :current_lockfile
69
+
70
+ def build_outdated_gem(current_lockfile_entry, updated_lockfile_entry, gemfile_groups)
71
+ OutdatedGem.new(
72
+ name: current_lockfile_entry.name,
73
+ gemfile_groups: gemfile_groups,
74
+ rubygems_source: updated_lockfile_entry.rubygems_source?,
75
+ git_source_uri: updated_lockfile_entry.git_source_uri&.to_s,
76
+ current_version: current_lockfile_entry.version.to_s,
77
+ current_git_version: current_lockfile_entry.git_version&.strip,
78
+ updated_version: updated_lockfile_entry.version.to_s,
79
+ updated_git_version: updated_lockfile_entry.git_version&.strip
80
+ )
81
+ end
71
82
  end
72
83
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BundleUpdateInteractive
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bundle_update_interactive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Brictson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-11 00:00:00.000000000 Z
11
+ date: 2024-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler