gitlab-dangerfiles 0.6.0 → 0.9.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: a41237cf8c1b948162962ffd5712cac36034d6e3f6ddbd551f7b7f5c64315ac6
4
- data.tar.gz: 9416beb3ed3688db58d83bfafb103a3f21b15c7a1e1dae83fe08dae33b13d329
3
+ metadata.gz: 953603fac4ea1f44a40296e63e5d67943f0a0ec2d67631eb24822d3c01b76749
4
+ data.tar.gz: 47c1026b0081cbd279cd097f122b29a6ef382dbb43ea5ce7a714935ead7288d9
5
5
  SHA512:
6
- metadata.gz: 294c63c0dad1685a71e4110ab5248d96e7efa97ef448dc861c6a443a8123fd490b1fbdf303b87bf7c18802074b24b3b371a433b3ef06c831cc368559c4c832a0
7
- data.tar.gz: aa3bc70fe5068018df9dd1eee9010732b4df231033434ba02c3872b0902e3850adde1b97b6228dbda9f58e10c032b7d4b6467c96f18392d3e74dfab497638835
6
+ metadata.gz: 6e36bec78c26703d1b964ea580b9d3cd1425926d968c80480a901f7c14ebb6f0a0509820adc612587796d85ed29e83ca0c3e9569a288a90a5beab1c1693f92da
7
+ data.tar.gz: b7fa2dcf949685dd1c24382e8b83c1b06b57c5abc75e85c6123313dae8d9936d8c90b3d8c58e9af237c07a497b6d0eb3c9e929c2dab840baec42bf338883b8c0
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
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "helper"
3
4
  require_relative "../gitlab/dangerfiles/teammate"
4
5
  require_relative "../gitlab/dangerfiles/weightage/maintainers"
5
6
  require_relative "../gitlab/dangerfiles/weightage/reviewers"
@@ -25,7 +26,7 @@ module Danger
25
26
  # for each change category that a Merge Request contains.
26
27
  #
27
28
  # @return [Array<Spin>]
28
- def spin(project, categories, timezone_experiment: false)
29
+ def spin(project, categories = [nil], timezone_experiment: false)
29
30
  spins = categories.sort.map do |category|
30
31
  including_timezone = INCLUDE_TIMEZONE_FOR_CATEGORY.fetch(category, timezone_experiment)
31
32
 
@@ -2,5 +2,8 @@ require "gitlab/dangerfiles/version"
2
2
 
3
3
  module Gitlab
4
4
  module Dangerfiles
5
+ def self.import_plugins(danger)
6
+ danger.import_plugin(File.expand_path("../danger/*.rb", __dir__))
7
+ end
5
8
  end
6
9
  end
@@ -59,7 +59,7 @@ module Gitlab
59
59
  private
60
60
 
61
61
  def subject
62
- TitleLinting.remove_draft_flag(message_parts[0])
62
+ @subject ||= TitleLinting.remove_draft_flag(message_parts[0])
63
63
  end
64
64
 
65
65
  def subject_too_short?
@@ -75,6 +75,7 @@ module Gitlab
75
75
  end
76
76
 
77
77
  def subject_starts_with_lowercase?
78
+ return false if subject.empty?
78
79
  return false if ("A".."Z").cover?(subject[0])
79
80
 
80
81
  first_char = subject.sub(/\A(\[.+\]|\w+:)\s/, "")[0]
@@ -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
@@ -1,10 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "base_linter"
3
4
  require_relative "emoji_checker"
4
5
 
5
6
  module Gitlab
6
7
  module Dangerfiles
7
- class CommitLinter
8
+ class CommitLinter < BaseLinter
9
+ MAX_CHANGED_FILES_IN_COMMIT = 3
8
10
  MAX_CHANGED_LINES_IN_COMMIT = 30
9
11
  SHORT_REFERENCE_REGEX = %r{([\w\-\/]+)?(?<!`)(#|!|&|%)\d+(?<!`)}.freeze
10
12
 
@@ -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
@@ -101,6 +101,8 @@ module Gitlab
101
101
  return true if capabilities(project).include?("#{kind} engineering_productivity")
102
102
 
103
103
  capabilities(project).include?("#{kind} backend")
104
+ when nil
105
+ capabilities(project).include?("#{kind}")
104
106
  else
105
107
  capabilities(project).include?("#{kind} #{category}")
106
108
  end
@@ -1,5 +1,5 @@
1
1
  module Gitlab
2
2
  module Dangerfiles
3
- VERSION = "0.6.0"
3
+ VERSION = "0.9.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.0
4
+ version: 0.9.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-17 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