danger-gem_changes 0.0.3 → 0.0.5

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: 59d7f53a0aa74339b86b9847b1b3416b5cb5a8d918ebe969cdca2b936407fc19
4
- data.tar.gz: 000fa34400b3392649ae437f94ee55bdea025b212f3711bfd0e3ac07a7f0c6d2
3
+ metadata.gz: 1a1b559abd29ece1800694f42e76a86d23d76902ad050b077fd2b0fd65835d3d
4
+ data.tar.gz: 0a97f435483472da2d0ddc1967f327b642d9a8d9bb74dec0d1ac812f5bfe21c1
5
5
  SHA512:
6
- metadata.gz: 06ddb79761d667e5c894ed43af76481cd18a3728ddf9a5fa7dbe2fcb397173906a156caa30222baff4c3ce4adecc830f02d9649aea7d194c65de7be0560b0f01
7
- data.tar.gz: eaba10548ca556d7cada7e59c5171d27d4539c0ba98fe18d780ac9bb4e4400daa13c486d2cdeba14034c96863e56d2430c543a57be0dd80ef9d7d130b1141b55
6
+ metadata.gz: fb6de489fbed7d6df7f3be17148e0eb8c3b0081c12b624cc128bb24e93f7633131b470072d417c875f5d4bb84868de49824f3df66dc8c1f34a9229411dd4b006
7
+ data.tar.gz: 854c978b2c48d5322d2b6be3ac30ed543fa25e4ef2b8b9ae81893bc47ec69c83ab3019604f844a6c7331cf6166ab8526f0f9c5e691f4eb786a4dd8013da5ecf1
data/.rubocop.yml CHANGED
@@ -3,11 +3,12 @@
3
3
  # If you don't like these settings, just delete this file :)
4
4
 
5
5
  require:
6
+ - rubocop-performance
6
7
  - rubocop-rake
7
8
  - rubocop-rspec
8
9
 
9
10
  AllCops:
10
- TargetRubyVersion: 2.7
11
+ TargetRubyVersion: 3.1
11
12
  NewCops: enable
12
13
 
13
14
  Style/StringLiterals:
data/Gemfile CHANGED
@@ -14,6 +14,7 @@ gem "rspec"
14
14
 
15
15
  # Linting code and docs
16
16
  gem "rubocop"
17
+ gem "rubocop-performance"
17
18
  gem "rubocop-rake"
18
19
  gem "rubocop-rspec"
19
20
  gem "yard"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-gem_changes (0.0.3)
4
+ danger-gem_changes (0.0.5)
5
5
  danger-plugin-api (~> 1.0)
6
6
  nokogiri (~> 1.0)
7
7
 
@@ -80,11 +80,15 @@ GEM
80
80
  rb-inotify (~> 0.9, >= 0.9.10)
81
81
  lumberjack (1.2.10)
82
82
  method_source (1.1.0)
83
+ mini_portile2 (2.8.6)
83
84
  nap (1.1.0)
84
85
  nenv (0.3.0)
85
86
  net-http (0.4.1)
86
87
  uri
87
88
  no_proxy_fix (0.1.2)
89
+ nokogiri (1.16.4)
90
+ mini_portile2 (~> 2.8.2)
91
+ racc (~> 1.4)
88
92
  nokogiri (1.16.4-arm64-darwin)
89
93
  racc (~> 1.4)
90
94
  notiffany (0.1.3)
@@ -148,6 +152,9 @@ GEM
148
152
  rubocop (~> 1.41)
149
153
  rubocop-factory_bot (2.25.1)
150
154
  rubocop (~> 1.41)
155
+ rubocop-performance (1.21.0)
156
+ rubocop (>= 1.48.1, < 2.0)
157
+ rubocop-ast (>= 1.31.1, < 2.0)
151
158
  rubocop-rake (0.6.0)
152
159
  rubocop (~> 1.0)
153
160
  rubocop-rspec (2.29.2)
@@ -184,6 +191,7 @@ DEPENDENCIES
184
191
  rake
185
192
  rspec
186
193
  rubocop
194
+ rubocop-performance
187
195
  rubocop-rake
188
196
  rubocop-rspec
189
197
  yard
data/README.md CHANGED
@@ -1,15 +1,73 @@
1
1
  # danger-gem_changes
2
2
 
3
- A description of danger-gem_changes.
3
+ This is a Danger plugin that can assist with reviews involving Gemfile
4
+ dependency changes. It can display a helpful table with links to changelogs and
5
+ diffs, and provides a DSL for evaluating changes to your depdencies.
4
6
 
5
7
  ## Installation
6
8
 
7
- $ gem install danger-gem_changes
9
+ ```shell
10
+ $ gem install danger-gem_changes
11
+ ```
8
12
 
9
13
  ## Usage
10
14
 
11
- Methods and attributes from this plugin are available in
12
- your `Dangerfile` under the `gem_changes` namespace.
15
+ The following examples are changes to your Dangerfile.
16
+
17
+ ### Summary Table
18
+
19
+ ```ruby
20
+ # Print a markdown table summarizing Gemfile.lock changes, if any.
21
+ gem_changes.summarize_changes
22
+ ```
23
+
24
+ > ### Gemfile.lock Changes
25
+ > | Gem | Source | Changelog | Change | Version | Level |
26
+ > | :-: | :----: | :-------: | :----: | :-----: | :---: |
27
+ > | [rubocop-factory_bot](https://rubygems.org/gems/rubocop-factory_bot) | [Source](https://github.com/rubocop/rubocop-factory_bot) | [Changelog](https://github.com/rubocop/rubocop-factory_bot/blob/master/CHANGELOG.md) | Downgraded | [2.25.0 <- 2.25.1](https://github.com/rubocop/rubocop-factory_bot/compare/v2.25.0...v2.25.1) | Patch |
28
+ > | [rubocop-performance](https://rubygems.org/gems/rubocop-performance) | [Source](https://github.com/rubocop/rubocop-performance) | [Changelog](https://github.com/rubocop/rubocop-performance/blob/master/CHANGELOG.md) | Added | 1.21.0 | |
29
+ > | [rubocop-rake](https://rubygems.org/gems/rubocop-rake) | [Source](https://github.com/rubocop/rubocop-rake) | [Changelog](https://github.com/rubocop/rubocop-rake/blob/master/CHANGELOG.md) | Upgraded | [0.5.0 -> 0.6.0](https://github.com/rubocop/rubocop-rake/compare/v0.5.0...v0.6.0) | Minor |
30
+ > | [rubocop-rspec](https://rubygems.org/gems/rubocop-rspec) | [Source](https://github.com/rubocop/rubocop-rspec) | [Changelog](https://github.com/rubocop/rubocop-rspec/blob/master/CHANGELOG.md) | Removed | 2.29.2 | |
31
+
32
+ ### Changes DSL
33
+
34
+ This gem provides a DSL for accessing metadata about changes to your Gemfile dependencies:
35
+
36
+ | Method | Description |
37
+ | :----: | ----------- |
38
+ | `changes` | All dependency changes |
39
+ | `additions` | Dependencies that were not present before |
40
+ | `removals` | Dependencies that are no longer present |
41
+ | `upgrades` | Dependencies that have a newer version than before |
42
+ | `downgrades` | Dependencies that have a lower version than before |
43
+
44
+ Each dependency change has information about the gem and version change:
45
+
46
+ | Method | Example |
47
+ | :----: | ------- |
48
+ | `gem.name` | `rubocop-rake` |
49
+ | `from` | `0.6.0` |
50
+ | `to` | `0.6.1` |
51
+ | `change?` | `true` |
52
+ | `addition?` | `false` |
53
+ | `removal?` | `false` |
54
+ | `upgrade?` | `true` |
55
+ | `downgrade?` | `false` |
56
+
57
+ The `from` attribute will be nil for additions, and `to` will be nil for removals.
58
+
59
+ ### More Examples
60
+
61
+ ```ruby
62
+ # Print a warning if new dependencies were added.
63
+ warn "Dependencies added" if gem_changes.additions.any?
64
+ ```
65
+
66
+ ```ruby
67
+ # Print a table of dependency downgrades, if any
68
+ downgrades = gem_changes.downgrades
69
+ gem_changes.summarize_changes changes: downgrades, title: "Dependency Downgrades"
70
+ ```
13
71
 
14
72
  ## Development
15
73
 
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.metadata["rubygems_mfa_required"] = "true"
22
22
  spec.metadata["source_code_uri"] = spec.homepage
23
23
  spec.metadata["issue_tracker_uri"] = "#{spec.homepage}/issues"
24
- spec.required_ruby_version = ">= 2.7"
24
+ spec.required_ruby_version = ">= 3.1"
25
25
  spec.add_runtime_dependency "danger-plugin-api", "~> 1.0"
26
26
  spec.add_runtime_dependency "nokogiri", "~> 1.0"
27
27
  end
data/lib/danger_plugin.rb CHANGED
@@ -26,13 +26,13 @@ module Danger
26
26
 
27
27
  string = "### #{title}\n"
28
28
 
29
- string += GemChanges::SummaryTable.new(changes: changes).markdown
29
+ string += GemChanges::SummaryTable.new(changes:).markdown
30
30
 
31
31
  markdown string
32
32
  end
33
33
 
34
34
  def changes
35
- GemChanges::Gemfile.changes(git: git)
35
+ GemChanges::Gemfile.changes(git:)
36
36
  end
37
37
 
38
38
  def additions
@@ -3,7 +3,7 @@
3
3
  module GemChanges
4
4
  Change = Struct.new(:gem, :from, :to, keyword_init: true) do
5
5
  def initialize(gem:, from:, to:)
6
- super(gem: gem, from: Version(from), to: Version(to))
6
+ super(gem:, from: Version(from), to: Version(to))
7
7
  end
8
8
 
9
9
  def change?
@@ -26,6 +26,24 @@ module GemChanges
26
26
  change? and to < from
27
27
  end
28
28
 
29
+ def major?
30
+ change? &&
31
+ from.segments[0] && to.segments[0] &&
32
+ from.segments[0] != to.segments[0]
33
+ end
34
+
35
+ def minor?
36
+ change? && !major? &&
37
+ from.segments[1] && to.segments[1] &&
38
+ from.segments[1] != to.segments[1]
39
+ end
40
+
41
+ def patch?
42
+ change? && !major? && !minor? &&
43
+ from.segments[2] && to.segments[2] &&
44
+ from.segments[2] != to.segments[2]
45
+ end
46
+
29
47
  private
30
48
 
31
49
  def Version(something)
@@ -2,8 +2,8 @@
2
2
 
3
3
  module GemChanges
4
4
  module Gemfile
5
- REMOVAL_REGEX = /^- ([^ ]*) \((.*)\)/.freeze
6
- ADDITION_REGEX = /^\+ ([^ ]*) \((.*)\)/.freeze
5
+ REMOVAL_REGEX = /^- ([^ ]*) \((.*)\)/
6
+ ADDITION_REGEX = /^\+ ([^ ]*) \((.*)\)/
7
7
 
8
8
  module_function def changes(git:)
9
9
  diff = git.diff_for_file("Gemfile.lock")
@@ -27,7 +27,7 @@ module GemChanges
27
27
  all_gems.map do |gem_name|
28
28
  gem = Gem.new(name: gem_name)
29
29
 
30
- Change.new(gem: gem, from: removed[gem_name], to: added[gem_name])
30
+ Change.new(gem:, from: removed[gem_name], to: added[gem_name])
31
31
  end
32
32
  end
33
33
  end
@@ -11,10 +11,10 @@ module GemChanges
11
11
  def markdown
12
12
  string = ""
13
13
 
14
- string += "| Gem | Source | Changelog | Change |\n"
15
- string += "| --- | ------ | --------- | ------ |\n"
14
+ string += "| Gem | Source | Changelog | Change | Version | Level |\n"
15
+ string += "| :-: | :----: | :-------: | :----: | :-----: | :---: |\n"
16
16
 
17
- rows = changes.map { |change| Row.new(change: change) }
17
+ rows = changes.map { |change| Row.new(change:) }
18
18
 
19
19
  string += rows.map(&:markdown).join
20
20
 
@@ -36,7 +36,9 @@ module GemChanges
36
36
  rubygems_link,
37
37
  source_link,
38
38
  changelog_link,
39
- change_link
39
+ change_description,
40
+ compare_link,
41
+ level
40
42
  ].join(" | ")
41
43
 
42
44
  string += " |\n"
@@ -44,6 +46,8 @@ module GemChanges
44
46
  string
45
47
  end
46
48
 
49
+ private
50
+
47
51
  def rubygems_link
48
52
  "[#{gem.name}](#{gem.rubygems_uri})"
49
53
  end
@@ -64,8 +68,20 @@ module GemChanges
64
68
  end
65
69
  end
66
70
 
67
- def change_link
68
- text = change_text
71
+ def change_description
72
+ if change.addition?
73
+ "Added"
74
+ elsif change.removal?
75
+ "Removed"
76
+ elsif change.upgrade?
77
+ "Upgraded"
78
+ elsif change.downgrade?
79
+ "Downgraded"
80
+ end
81
+ end
82
+
83
+ def compare_link
84
+ text = compare_text
69
85
  link = compare_uri
70
86
 
71
87
  if link
@@ -75,17 +91,15 @@ module GemChanges
75
91
  end
76
92
  end
77
93
 
78
- private
79
-
80
- def change_text
94
+ def compare_text
81
95
  if change.addition?
82
- "Added at #{change.to}"
96
+ change.to
83
97
  elsif change.removal?
84
- "Removed at #{change.from}"
98
+ change.from
85
99
  elsif change.upgrade?
86
- "v#{change.from} -> v#{change.to}"
100
+ "#{change.from} -> #{change.to}"
87
101
  elsif change.downgrade?
88
- "v#{change.to} <- v#{change.from}"
102
+ "#{change.to} <- #{change.from}"
89
103
  else
90
104
  fail "Unknown change type"
91
105
  end
@@ -98,6 +112,16 @@ module GemChanges
98
112
 
99
113
  "#{gem.source_code_uri}/compare/v#{from}...v#{to}"
100
114
  end
115
+
116
+ def level
117
+ if change.major?
118
+ "Major"
119
+ elsif change.minor?
120
+ "Minor"
121
+ elsif change.patch?
122
+ "Patch"
123
+ end
124
+ end
101
125
  end
102
126
  end
103
127
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GemChanges
4
- VERSION = "0.0.3"
4
+ VERSION = "0.0.5"
5
5
  end
@@ -16,8 +16,8 @@ index eabec13..f4353d2 100644
16
16
  + rubocop-performance (1.21.0)
17
17
  + rubocop (>= 1.48.1, < 2.0)
18
18
  + rubocop-ast (>= 1.31.1, < 2.0)
19
- - rubocop-rake (0.6.0)
20
- + rubocop-rake (0.6.1)
19
+ - rubocop-rake (0.5.0)
20
+ + rubocop-rake (0.6.0)
21
21
  rubocop (~> 1.0)
22
22
  - rubocop-rspec (2.29.2)
23
23
  @@ -181,6 +184,7 @@ DEPENDENCIES
@@ -0,0 +1,7 @@
1
+ ### Gemfile.lock Changes
2
+ | Gem | Source | Changelog | Change | Version | Level |
3
+ | :-: | :----: | :-------: | :----: | :-----: | :---: |
4
+ | [rubocop-factory_bot](https://rubygems.org/gems/rubocop-factory_bot) | [Source](https://github.com/rubocop/rubocop-factory_bot) | [Changelog](https://github.com/rubocop/rubocop-factory_bot/blob/master/CHANGELOG.md) | Downgraded | [2.25.0 <- 2.25.1](https://github.com/rubocop/rubocop-factory_bot/compare/v2.25.0...v2.25.1) | Patch |
5
+ | [rubocop-performance](https://rubygems.org/gems/rubocop-performance) | [Source](https://github.com/rubocop/rubocop-performance) | [Changelog](https://github.com/rubocop/rubocop-performance/blob/master/CHANGELOG.md) | Added | 1.21.0 | |
6
+ | [rubocop-rake](https://rubygems.org/gems/rubocop-rake) | [Source](https://github.com/rubocop/rubocop-rake) | [Changelog](https://github.com/rubocop/rubocop-rake/blob/master/CHANGELOG.md) | Upgraded | [0.5.0 -> 0.6.0](https://github.com/rubocop/rubocop-rake/compare/v0.5.0...v0.6.0) | Minor |
7
+ | [rubocop-rspec](https://rubygems.org/gems/rubocop-rspec) | [Source](https://github.com/rubocop/rubocop-rspec) | [Changelog](https://github.com/rubocop/rubocop-rspec/blob/master/CHANGELOG.md) | Removed | 2.29.2 | |
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ describe GemChanges::Change do
6
+ let(:gem) { GemChanges::Gem.new(name: "bummr") }
7
+
8
+ describe "patch levels" do
9
+ let(:major) { described_class.new(gem:, from: "1.1.1", to: "2.1.1") }
10
+
11
+ let(:minor) { described_class.new(gem:, from: "1.1.1", to: "1.2.1") }
12
+
13
+ let(:patch) { described_class.new(gem:, from: "1.1.1", to: "1.1.2") }
14
+
15
+ describe "#major?" do
16
+ it "is true for major changes" do
17
+ expect(major).to be_major
18
+ end
19
+
20
+ it "is false for minor changes" do
21
+ expect(minor).not_to be_major
22
+ end
23
+
24
+ it "is false for patch changes" do
25
+ expect(patch).not_to be_major
26
+ end
27
+ end
28
+
29
+ describe "#minor?" do
30
+ it "is false for major changes" do
31
+ expect(major).not_to be_minor
32
+ end
33
+
34
+ it "is true for minor changes" do
35
+ expect(minor).to be_minor
36
+ end
37
+
38
+ it "is false for patch changes" do
39
+ expect(patch).not_to be_minor
40
+ end
41
+ end
42
+
43
+ describe "#patch?" do
44
+ it "is false for major changes" do
45
+ expect(major).not_to be_patch
46
+ end
47
+
48
+ it "is false for minor changes" do
49
+ expect(minor).not_to be_patch
50
+ end
51
+
52
+ it "is true for patch changes" do
53
+ expect(patch).to be_patch
54
+ end
55
+ end
56
+ end
57
+ end
@@ -66,8 +66,8 @@ module Danger
66
66
  [
67
67
  GemChanges::Change.new(
68
68
  gem: GemChanges::Gem.new(name: "rubocop-rake"),
69
- from: "0.6.0",
70
- to: "0.6.1"
69
+ from: "0.5.0",
70
+ to: "0.6.0"
71
71
  )
72
72
  ]
73
73
  )
@@ -90,17 +90,11 @@ module Danger
90
90
  it "can generate a markdown table" do
91
91
  @my_plugin.summarize_changes
92
92
 
93
- markdown = @dangerfile.status_report[:markdowns].last.message
94
-
95
- expect(markdown).to eq(<<~MARKDOWN)
96
- ### Gemfile.lock Changes
97
- | Gem | Source | Changelog | Change |
98
- | --- | ------ | --------- | ------ |
99
- | [rubocop-factory_bot](https://rubygems.org/gems/rubocop-factory_bot) | [Source](https://github.com/rubocop/rubocop-factory_bot) | [Changelog](https://github.com/rubocop/rubocop-factory_bot/blob/master/CHANGELOG.md) | [v2.25.0 <- v2.25.1](https://github.com/rubocop/rubocop-factory_bot/compare/v2.25.0...v2.25.1) |
100
- | [rubocop-performance](https://rubygems.org/gems/rubocop-performance) | [Source](https://github.com/rubocop/rubocop-performance) | [Changelog](https://github.com/rubocop/rubocop-performance/blob/master/CHANGELOG.md) | Added at 1.21.0 |
101
- | [rubocop-rake](https://rubygems.org/gems/rubocop-rake) | [Source](https://github.com/rubocop/rubocop-rake) | [Changelog](https://github.com/rubocop/rubocop-rake/blob/master/CHANGELOG.md) | [v0.6.0 -> v0.6.1](https://github.com/rubocop/rubocop-rake/compare/v0.6.0...v0.6.1) |
102
- | [rubocop-rspec](https://rubygems.org/gems/rubocop-rspec) | [Source](https://github.com/rubocop/rubocop-rspec) | [Changelog](https://github.com/rubocop/rubocop-rspec/blob/master/CHANGELOG.md) | Removed at 2.29.2 |
103
- MARKDOWN
93
+ actual = @dangerfile.status_report[:markdowns].last.message
94
+
95
+ expected = File.read("spec/fixtures/summary_table.markdown")
96
+
97
+ expect(actual).to eq(expected)
104
98
  end
105
99
  end
106
100
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-gem_changes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - John DeSilva
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-12 00:00:00.000000000 Z
11
+ date: 2024-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api
@@ -47,7 +47,6 @@ extra_rdoc_files: []
47
47
  files:
48
48
  - ".gitignore"
49
49
  - ".rubocop.yml"
50
- - ".travis.yml"
51
50
  - Gemfile
52
51
  - Gemfile.lock
53
52
  - Guardfile
@@ -63,6 +62,8 @@ files:
63
62
  - lib/gem_changes/summary_table.rb
64
63
  - lib/gem_changes/version.rb
65
64
  - spec/fixtures/Gemfile.lock.patch
65
+ - spec/fixtures/summary_table.markdown
66
+ - spec/gem_changes/change_spec.rb
66
67
  - spec/gem_changes_spec.rb
67
68
  - spec/spec_helper.rb
68
69
  homepage: https://github.com/Aesthetikx/danger-gem_changes
@@ -80,7 +81,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
81
  requirements:
81
82
  - - ">="
82
83
  - !ruby/object:Gem::Version
83
- version: '2.7'
84
+ version: '3.1'
84
85
  required_rubygems_version: !ruby/object:Gem::Requirement
85
86
  requirements:
86
87
  - - ">="
data/.travis.yml DELETED
@@ -1,10 +0,0 @@
1
- language: ruby
2
- cache:
3
- directories:
4
- - bundle
5
-
6
- rvm:
7
- - 2.7
8
-
9
- script:
10
- - bundle exec rake spec