gitlab-dangerfiles 0.6.1 → 0.7.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: 1376c48a26c7b3a10cc3e649d1cf28f49fdf58fd7b317713b9ac9a0f3771e5a5
4
- data.tar.gz: 9ecd1d0db0f583740a73f96f6ffd14905f7a66157e427c6a11410a7bc7c70e55
3
+ metadata.gz: d8a22cec902c95d63352af51b2b0460e7cb761ddda7ee7ab2833077686ee5428
4
+ data.tar.gz: 1eb6288e842695e9811d6f8ba88cf43d8c75caa1c441a3419aed3f5988c11864
5
5
  SHA512:
6
- metadata.gz: e1684cb0a7b5367b37f099cad0dca796cdb5cf01fc71f36e4896268b4abc8c0ee59ed122459261f47ec1b873da8aa2355644c6074b92285ddd1b3f4215bbba86
7
- data.tar.gz: 8e8644fa64222def924524b8545397615f7335198e88d35f47fc07c450793879c0c710c380b496eb0c80a6bf856c855ec4bb58266670aff6a526ff3b9c84bc5a
6
+ metadata.gz: 81214e30c00e1b8c3f164a8b3bdfbc135902b5292a1064a8f4acbcd26ef5f9d9b0e83ebea83c51621e1742b2b6df13af1e81732fb4c9256bb254cac153370170
7
+ data.tar.gz: dd5be048537a4604d21774622effdb3e02d82aa3aefaaecb5bdcf598a96efcbff9ade89100c753cb26cff12b85b7cded1fdde71bbae10035ea341717b9704c67
data/lib/danger/helper.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require "net/http"
4
4
  require "json"
5
5
  require "danger"
6
+ require_relative "../gitlab/dangerfiles/changes"
6
7
  require_relative "../gitlab/dangerfiles/teammate"
7
8
  require_relative "../gitlab/dangerfiles/title_linting"
8
9
 
@@ -22,52 +23,6 @@ module Danger
22
23
 
23
24
  HTTPError = Class.new(StandardError)
24
25
 
25
- Change = Struct.new(:file, :change_type, :category)
26
-
27
- class Changes < ::SimpleDelegator
28
- def added
29
- select_by_change_type(:added)
30
- end
31
-
32
- def modified
33
- select_by_change_type(:modified)
34
- end
35
-
36
- def deleted
37
- select_by_change_type(:deleted)
38
- end
39
-
40
- def renamed_before
41
- select_by_change_type(:renamed_before)
42
- end
43
-
44
- def renamed_after
45
- select_by_change_type(:renamed_after)
46
- end
47
-
48
- def has_category?(category)
49
- any? { |change| change.category == category }
50
- end
51
-
52
- def by_category(category)
53
- Changes.new(select { |change| change.category == category })
54
- end
55
-
56
- def categories
57
- map(&:category).uniq
58
- end
59
-
60
- def files
61
- map(&:file)
62
- end
63
-
64
- private
65
-
66
- def select_by_change_type(change_type)
67
- Changes.new(select { |change| change.change_type == change_type })
68
- end
69
- end
70
-
71
26
  def gitlab_helper
72
27
  # Unfortunately the following does not work:
73
28
  # - respond_to?(:gitlab)
@@ -159,27 +114,27 @@ module Danger
159
114
  end
160
115
  end
161
116
 
162
- # @return [Changes]
117
+ # @return [Gitlab::Dangerfiles::Changes]
163
118
  def changes(categories)
164
- Changes.new([]).tap do |changes|
119
+ Gitlab::Dangerfiles::Changes.new([]).tap do |changes|
165
120
  git.added_files.each do |file|
166
- categories_for_file(file, categories).each { |category| changes << Change.new(file, :added, category) }
121
+ categories_for_file(file, categories).each { |category| changes << Gitlab::Dangerfiles::Change.new(file, :added, category) }
167
122
  end
168
123
 
169
124
  git.modified_files.each do |file|
170
- categories_for_file(file, categories).each { |category| changes << Change.new(file, :modified, category) }
125
+ categories_for_file(file, categories).each { |category| changes << Gitlab::Dangerfiles::Change.new(file, :modified, category) }
171
126
  end
172
127
 
173
128
  git.deleted_files.each do |file|
174
- categories_for_file(file, categories).each { |category| changes << Change.new(file, :deleted, category) }
129
+ categories_for_file(file, categories).each { |category| changes << Gitlab::Dangerfiles::Change.new(file, :deleted, category) }
175
130
  end
176
131
 
177
132
  git.renamed_files.map { |x| x[:before] }.each do |file|
178
- categories_for_file(file, categories).each { |category| changes << Change.new(file, :renamed_before, category) }
133
+ categories_for_file(file, categories).each { |category| changes << Gitlab::Dangerfiles::Change.new(file, :renamed_before, category) }
179
134
  end
180
135
 
181
136
  git.renamed_files.map { |x| x[:after] }.each do |file|
182
- categories_for_file(file, categories).each { |category| changes << Change.new(file, :renamed_after, category) }
137
+ categories_for_file(file, categories).each { |category| changes << Gitlab::Dangerfiles::Change.new(file, :renamed_after, category) }
183
138
  end
184
139
  end
185
140
  end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "title_linting"
4
+
5
+ module Gitlab
6
+ module Dangerfiles
7
+ Change = Struct.new(:file, :change_type, :category)
8
+
9
+ class Changes < ::SimpleDelegator
10
+ def added
11
+ select_by_change_type(:added)
12
+ end
13
+
14
+ def modified
15
+ select_by_change_type(:modified)
16
+ end
17
+
18
+ def deleted
19
+ select_by_change_type(:deleted)
20
+ end
21
+
22
+ def renamed_before
23
+ select_by_change_type(:renamed_before)
24
+ end
25
+
26
+ def renamed_after
27
+ select_by_change_type(:renamed_after)
28
+ end
29
+
30
+ def has_category?(category)
31
+ any? { |change| change.category == category }
32
+ end
33
+
34
+ def by_category(category)
35
+ Changes.new(select { |change| change.category == category })
36
+ end
37
+
38
+ def categories
39
+ map(&:category).uniq
40
+ end
41
+
42
+ def files
43
+ map(&:file)
44
+ end
45
+
46
+ private
47
+
48
+ def select_by_change_type(change_type)
49
+ Changes.new(select { |change| change.change_type == change_type })
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,66 @@
1
+ require "danger"
2
+ require "gitlab/dangerfiles/changes"
3
+
4
+ module DangerSpecHelper
5
+ # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
6
+ # If you are expanding these files, see if it's already been done ^.
7
+
8
+ # A silent version of the user interface
9
+ def self.testing_ui
10
+ Cork::Board.new(silent: true)
11
+ end
12
+
13
+ # Example environment (ENV) that would come from
14
+ # running a PR on TravisCI
15
+ def self.testing_env
16
+ {
17
+ "GITLAB_CI" => "true",
18
+ "DANGER_GITLAB_HOST" => "gitlab.example.com",
19
+ "CI_MERGE_REQUEST_IID" => 28_493,
20
+ "DANGER_GITLAB_API_TOKEN" => "123sbdq54erfsd3422gdfio",
21
+ }
22
+ end
23
+
24
+ # A stubbed out Dangerfile for use in tests
25
+ def self.testing_dangerfile
26
+ env = Danger::EnvironmentManager.new(testing_env)
27
+ Danger::Dangerfile.new(env, testing_ui)
28
+ end
29
+
30
+ def self.fake_danger
31
+ Class.new do
32
+ attr_reader :git, :gitlab, :helper
33
+
34
+ # rubocop:disable Gitlab/ModuleWithInstanceVariables
35
+ def initialize(git: nil, gitlab: nil, helper: nil)
36
+ @git = git
37
+ @gitlab = gitlab
38
+ @helper = helper
39
+ end
40
+
41
+ # rubocop:enable Gitlab/ModuleWithInstanceVariables
42
+ end
43
+ end
44
+ end
45
+
46
+ RSpec.shared_context "with dangerfile" do
47
+ let(:dangerfile) { DangerSpecHelper.testing_dangerfile }
48
+ let(:added_files) { %w[added1] }
49
+ let(:modified_files) { %w[modified1] }
50
+ let(:deleted_files) { %w[deleted1] }
51
+ let(:renamed_before_file) { "renamed_before" }
52
+ let(:renamed_after_file) { "renamed_after" }
53
+ let(:renamed_files) { [{ before: renamed_before_file, after: renamed_after_file }] }
54
+ let(:change_class) { Gitlab::Dangerfiles::Change }
55
+ let(:changes_class) { Gitlab::Dangerfiles::Changes }
56
+ let(:changes) { changes_class.new([]) }
57
+ let(:mr_title) { "Fake Title" }
58
+ let(:mr_labels) { [] }
59
+
60
+ let(:fake_git) { double("fake-git", added_files: added_files, modified_files: modified_files, deleted_files: deleted_files, renamed_files: renamed_files) }
61
+ let(:fake_helper) { double("fake-helper", changes: changes, mr_iid: 1234, mr_title: mr_title, mr_labels: mr_labels) }
62
+
63
+ before do
64
+ allow(dangerfile).to receive(:git).and_return(fake_git)
65
+ end
66
+ end
@@ -1,5 +1,5 @@
1
1
  module Gitlab
2
2
  module Dangerfiles
3
- VERSION = "0.6.1"
3
+ VERSION = "0.7.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-dangerfiles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rémy Coutable
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-03 00:00:00.000000000 Z
11
+ date: 2021-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger
@@ -136,9 +136,11 @@ files:
136
136
  - lib/gitlab/Dangerfile
137
137
  - lib/gitlab/dangerfiles.rb
138
138
  - lib/gitlab/dangerfiles/base_linter.rb
139
+ - lib/gitlab/dangerfiles/changes.rb
139
140
  - lib/gitlab/dangerfiles/commit_linter.rb
140
141
  - lib/gitlab/dangerfiles/emoji_checker.rb
141
142
  - lib/gitlab/dangerfiles/merge_request_linter.rb
143
+ - lib/gitlab/dangerfiles/spec_helper.rb
142
144
  - lib/gitlab/dangerfiles/teammate.rb
143
145
  - lib/gitlab/dangerfiles/title_linting.rb
144
146
  - lib/gitlab/dangerfiles/version.rb