danger-gem_changes 0.0.3 → 0.0.4

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: 1aa4a02bac66b8ac99978fed97167df34e24c05c66dc0268a65cda27dcb79cc7
4
+ data.tar.gz: 931055c624a1b1b4eb9b4d359ea61256f070cf164f2100c639e4b6c234559dbd
5
5
  SHA512:
6
- metadata.gz: 06ddb79761d667e5c894ed43af76481cd18a3728ddf9a5fa7dbe2fcb397173906a156caa30222baff4c3ce4adecc830f02d9649aea7d194c65de7be0560b0f01
7
- data.tar.gz: eaba10548ca556d7cada7e59c5171d27d4539c0ba98fe18d780ac9bb4e4400daa13c486d2cdeba14034c96863e56d2430c543a57be0dd80ef9d7d130b1141b55
6
+ metadata.gz: 5378d77c339d86a046df91fe6df74f08e9ef9c8c81bad05abce7493634f368be087f4f6fb25a7dfec3576802229d605bbd1b492a8efc07a2ff2f5e0474ae033f
7
+ data.tar.gz: 15a6335a13ea154405a70e1654e971cbd919dd940228cf019fc7e4f680d9a51a4ccc2b3eb8f398eed87f09b30fd01c39392a142582df6956432016e0f6317ecb
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.4)
5
5
  danger-plugin-api (~> 1.0)
6
6
  nokogiri (~> 1.0)
7
7
 
@@ -148,6 +148,9 @@ GEM
148
148
  rubocop (~> 1.41)
149
149
  rubocop-factory_bot (2.25.1)
150
150
  rubocop (~> 1.41)
151
+ rubocop-performance (1.21.0)
152
+ rubocop (>= 1.48.1, < 2.0)
153
+ rubocop-ast (>= 1.31.1, < 2.0)
151
154
  rubocop-rake (0.6.0)
152
155
  rubocop (~> 1.0)
153
156
  rubocop-rspec (2.29.2)
@@ -184,6 +187,7 @@ DEPENDENCIES
184
187
  rake
185
188
  rspec
186
189
  rubocop
190
+ rubocop-performance
187
191
  rubocop-rake
188
192
  rubocop-rspec
189
193
  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 | 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) | [v2.25.0 <- v2.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 at 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) | [v0.5.0 -> v0.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 at 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 | 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,8 @@ module GemChanges
36
36
  rubygems_link,
37
37
  source_link,
38
38
  changelog_link,
39
- change_link
39
+ change_link,
40
+ level
40
41
  ].join(" | ")
41
42
 
42
43
  string += " |\n"
@@ -44,6 +45,8 @@ module GemChanges
44
45
  string
45
46
  end
46
47
 
48
+ private
49
+
47
50
  def rubygems_link
48
51
  "[#{gem.name}](#{gem.rubygems_uri})"
49
52
  end
@@ -75,7 +78,15 @@ module GemChanges
75
78
  end
76
79
  end
77
80
 
78
- private
81
+ def level
82
+ if change.major?
83
+ "Major"
84
+ elsif change.minor?
85
+ "Minor"
86
+ elsif change.patch?
87
+ "Patch"
88
+ end
89
+ end
79
90
 
80
91
  def change_text
81
92
  if change.addition?
@@ -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.4"
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,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
  )
@@ -94,12 +94,12 @@ module Danger
94
94
 
95
95
  expect(markdown).to eq(<<~MARKDOWN)
96
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 |
97
+ | Gem | Source | Changelog | Change | Level |
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) | Patch |
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.5.0 -> v0.6.0](https://github.com/rubocop/rubocop-rake/compare/v0.5.0...v0.6.0) | Minor |
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
103
  MARKDOWN
104
104
  end
105
105
  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.4
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,7 @@ 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/gem_changes/change_spec.rb
66
66
  - spec/gem_changes_spec.rb
67
67
  - spec/spec_helper.rb
68
68
  homepage: https://github.com/Aesthetikx/danger-gem_changes
@@ -80,7 +80,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
- version: '2.7'
83
+ version: '3.1'
84
84
  required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - ">="
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