gitlab-dangerfiles 2.6.0 → 2.8.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: af398dd6651e65bb4716c5a2c1aee8ee93a9a98c68f4b71f5da3de3d83a2aff2
4
- data.tar.gz: cb57a546b8f9c15b1c17ebe9fa6936e312c6f0345e74c6778220ceb56b884c6a
3
+ metadata.gz: e0819c79b914e2025eecc3b05a52227a9012ceafeac3300032e1abb129706440
4
+ data.tar.gz: 117a9710932852cf1845d8a8c3a27f331bbe65da0cccdf13f044858d915ea0c1
5
5
  SHA512:
6
- metadata.gz: 3b4df78cdb34004d811fbd711c251151820382a3ed4de31b26f46e90a8a9f121a2111b2d90de1aeaf390129fccb563bfa679ddc50ef84975a9f6da9ad3aeff6d
7
- data.tar.gz: b88f6fb0e0e46d5f089651312fe45a7713ab6f732216d744bf8f24515d6471d08696cd1b2ee1b2290c881972b6ef8c5376a68a74d58fd0ec76e7620009074a16
6
+ metadata.gz: c93c2983a4a0ebba6f3c94d0b81a1da7ba9fad9eb98573a5862e3d6501ff76614501907bb5d492942a47472160d2db5d1a96fcebdad280379cd3e03a43c5f113
7
+ data.tar.gz: 734bbb0e6894d8de57f4d48546aca9f085447556662dbc64ba99f7cb39ea166b5a75f3d1099077e09d17f44d3687a9fe733451fa06310e02d906209b6003bcae
@@ -1,13 +1,13 @@
1
- <!-- Replace `<NEW_VERSION>` with the previous release here, and `<COMMIT_UPDATING_VERSION>`
2
- with the latest commit from this merge request. -->
3
- - Diff: https://gitlab.com/gitlab-org/ruby/gems/gitlab-dangerfiles/compare/v<NEW_VERSION>...<COMMIT_UPDATING_VERSION>
1
+ <!-- Replace `<PREVIOUS_VERSION>` with the previous version number here, `<COMMIT_UPDATING_VERSION>` with the latest
2
+ commit from this merge request, and `<NEW_VERSION>` with the upcoming version number. -->
3
+ ## Diff
4
4
 
5
- - Checklist before merging:
6
- - [ ] Diff link is up-to-date.
7
- - [ ] Based on the diff, `version.rb` is updated, according to [SemVer](https://semver.org).
5
+ https://gitlab.com/gitlab-org/ruby/gems/gitlab-dangerfiles/compare/v<PREVIOUS_VERSION>...<COMMIT_UPDATING_VERSION>
8
6
 
9
- - Checklist after merging:
10
- - [ ] [Update the release notes for the newly created tag](docs/release_process.md#how-to).
11
- - [ ] Check that automatic release notes (generated following the same process as https://docs.gitlab.com/ee/development/changelog.html) are correct.
7
+ ## Checklist
8
+
9
+ - [ ] Diff link is up-to-date.
10
+ - [ ] Check the release notes: https://gitlab.com/api/v4/projects/gitlab-org%2Fruby%2Fgems%2Fgitlab-dangerfiles/repository/changelog?version=<NEW_VERSION>
11
+ - [ ] Based on the diff and the release notes, `version.rb` is updated, according to [SemVer](https://semver.org).
12
12
 
13
13
  /label ~"type::maintenance" ~"static code analysis"
data/.gitlab-ci.yml CHANGED
@@ -28,12 +28,6 @@ workflow:
28
28
  - Gemfile.lock
29
29
  policy: pull
30
30
 
31
- danger-review:
32
- extends: .default
33
- stage: test
34
- script:
35
- - bundle exec danger --fail-on-errors=true --verbose
36
-
37
31
  test:rspec:
38
32
  extends: .default
39
33
  stage: test
@@ -52,7 +46,9 @@ include:
52
46
  - template: Security/SAST.gitlab-ci.yml
53
47
  - template: Security/Secret-Detection.gitlab-ci.yml
54
48
  - project: 'gitlab-org/quality/pipeline-common'
55
- file: '/ci/gem-release.yml'
49
+ file:
50
+ - '/ci/danger-review.yml'
51
+ - '/ci/gem-release.yml'
56
52
 
57
53
  # run security jobs on MRs
58
54
  # see: https://gitlab.com/gitlab-org/gitlab/-/issues/218444#note_478761991
data/README.md CHANGED
@@ -124,6 +124,29 @@ project. To use it in your project, perform the following steps:
124
124
  end
125
125
  ```
126
126
 
127
+ ### CI configuration
128
+
129
+ In order to run `danger` on GitLab CI, perform the following steps:
130
+
131
+ 1. If not yet done, create a `Dangerfile` at the top-level of your project. Refer to [Usage](#usage) to
132
+ see how to set it up.
133
+ 2. In `.gitlab-ci.yml`, include [CI configuration](https://gitlab.com/gitlab-org/quality/pipeline-common/-/blob/master/ci/danger-review.yml)
134
+ which defines `danger-review` [CI job](https://docs.gitlab.com/ee/ci/jobs/):
135
+
136
+ ```yaml
137
+ include:
138
+ - project: 'gitlab-org/quality/pipeline-common'
139
+ file:
140
+ - '/ci/danger-review.yml'
141
+ ```
142
+
143
+ 3. Create a [Project access token](https://docs.gitlab.com/ee/user/project/settings/project_access_tokens.html)
144
+ with scope `api` and role `Maintainer`.
145
+ 4. Add a [CI/CD variable](https://docs.gitlab.com/ee/ci/variables/#add-a-cicd-variable-to-a-project)
146
+ `DANGER_GITLAB_API_TOKEN` (`Masked` but not `Protected`) and use Project access token as value.
147
+
148
+ See a [real world example](https://gitlab.com/gitlab-org/ruby/gems/gitlab-styles/-/merge_requests/105).
149
+
127
150
  ## Documentation
128
151
 
129
152
  Latest documentation can be found at <https://www.rubydoc.info/gems/gitlab-dangerfiles>.
@@ -8,15 +8,15 @@ Gem::Specification.new do |spec|
8
8
 
9
9
  spec.summary = %q{This gem provides common Dangerfile and plugins for GitLab projects.}
10
10
  spec.description = %q{This gem provides common Dangerfile and plugins for GitLab projects.}
11
- spec.homepage = "https://gitlab.com/gitlab-org/gitlab-dangerfiles"
11
+ spec.homepage = "https://gitlab.com/gitlab-org/ruby/gems/gitlab-dangerfiles"
12
12
  spec.license = "MIT"
13
13
  spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
14
14
 
15
15
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
16
 
17
17
  spec.metadata["homepage_uri"] = spec.homepage
18
- spec.metadata["source_code_uri"] = "https://gitlab.com/gitlab-org/gitlab-dangerfiles"
19
- spec.metadata["changelog_uri"] = "https://gitlab.com/gitlab-org/gitlab-dangerfiles/-/releases"
18
+ spec.metadata["source_code_uri"] = "https://gitlab.com/gitlab-org/ruby/gems/gitlab-dangerfiles"
19
+ spec.metadata["changelog_uri"] = "https://gitlab.com/gitlab-org/ruby/gems/gitlab-dangerfiles/-/releases"
20
20
 
21
21
  # Specify which files should be added to the gem when it is released.
22
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -3,10 +3,10 @@
3
3
  require "net/http"
4
4
  require "json"
5
5
 
6
- require_relative "../../gitlab/dangerfiles/changes"
7
- require_relative "../../gitlab/dangerfiles/config"
8
- require_relative "../../gitlab/dangerfiles/teammate"
9
- require_relative "../../gitlab/dangerfiles/title_linting"
6
+ require_relative "../../../gitlab/dangerfiles/changes"
7
+ require_relative "../../../gitlab/dangerfiles/config"
8
+ require_relative "../../../gitlab/dangerfiles/teammate"
9
+ require_relative "../../../gitlab/dangerfiles/title_linting"
10
10
 
11
11
  module Danger
12
12
  # Common helper functions for our danger scripts.
@@ -218,7 +218,7 @@ module Danger
218
218
  #
219
219
  # @return [Array<Symbol>] the categories a file is in, e.g., +[:frontend]+, +[:backend]+, or +%i[frontend tooling]+
220
220
  # using filename regex (+filename_regex+) and specific change regex (+changes_regex+) from the given +categories+ hash.
221
- def categories_for_file(filename, files_to_category = [])
221
+ def categories_for_file(filename, files_to_category = {})
222
222
  files_to_category = Array(files_to_category).compact
223
223
  files_to_category = helper.config.files_to_category if files_to_category.empty?
224
224
 
@@ -22,7 +22,7 @@ module Danger
22
22
  #
23
23
  # @return [Gitlab::Dangerfiles::Teammate]
24
24
  def team_mr_author
25
- company_members.find { |person| person.username == helper.mr_author }
25
+ @team_mr_author ||= company_members.find { |person| person.username == helper.mr_author }
26
26
  end
27
27
 
28
28
  # Assigns GitLab team members to be reviewer and maintainer
@@ -36,6 +36,7 @@ module Danger
36
36
  def spin(project = nil, categories = [nil], timezone_experiment: false)
37
37
  project = (project || helper.config.project_name).downcase
38
38
  categories = categories.map { |category| category&.downcase }
39
+ categories.reject! { |category| integrations_reject_category?(category, project) }
39
40
 
40
41
  spins = categories.sort_by(&:to_s).map do |category|
41
42
  including_timezone = INCLUDE_TIMEZONE_FOR_CATEGORY.fetch(category, timezone_experiment)
@@ -106,6 +107,14 @@ module Danger
106
107
  person.username == helper.mr_author
107
108
  end
108
109
 
110
+ # @param [String] category name
111
+ # @return [Boolean]
112
+ def integrations_reject_category?(category, project)
113
+ # Reject integrations categories if the MR author has reviewing abilities for the category.
114
+ team_mr_author&.integrations_be?(project, category, helper.mr_labels) ||
115
+ team_mr_author&.integrations_fe?(project, category, helper.mr_labels)
116
+ end
117
+
109
118
  def new_random(seed)
110
119
  Random.new(Digest::MD5.hexdigest(seed).to_i(16))
111
120
  end
@@ -15,19 +15,33 @@ TABLE_MARKDOWN = <<MARKDOWN
15
15
  To spread load more evenly across eligible reviewers, Danger has picked a candidate for each
16
16
  review slot. Feel free to
17
17
  [override these selections](https://about.gitlab.com/handbook/engineering/projects/##{PROJECT_NAME})
18
- if you think someone else would be better-suited.
18
+ if you think someone else would be better-suited
19
+ or use the [GitLab Review Workload Dashboard](https://gitlab-org.gitlab.io/gitlab-roulette/) to find other available reviewers.
19
20
 
20
21
  To read more on how to use the reviewer roulette, please take a look at the
21
22
  [Engineering workflow](https://about.gitlab.com/handbook/engineering/workflow/#basics)
22
23
  and [code review guidelines](https://docs.gitlab.com/ee/development/code_review.html).
24
+ Please consider assigning a reviewer or maintainer who is a
25
+ [domain expert](https://about.gitlab.com/handbook/engineering/projects/#gitlab-development-kit) in the area of the merge request.
23
26
 
24
27
  Once you've decided who will review this merge request, mention them as you
25
28
  normally would! Danger does not automatically notify them for you.
26
29
 
30
+ MARKDOWN
31
+
32
+ TABLE_HEADER_WITH_CATEGORIES = <<MARKDOWN
33
+ | Category | Reviewer | Maintainer |
34
+ | -------- | -------- | ---------- |
35
+ MARKDOWN
36
+
37
+ TABLE_HEADER_WITHOUT_CATEGORIES = <<MARKDOWN
27
38
  | Reviewer | Maintainer |
28
39
  | -------- | ---------- |
29
40
  MARKDOWN
30
41
 
42
+ OPTIONAL_REVIEW_TEMPLATE = '%{role} review is optional'
43
+ NOT_AVAILABLE_TEMPLATE = 'No %{role} available'
44
+
31
45
  def note_for_spins_role(spins, role)
32
46
  spins.each do |spin|
33
47
  note = note_for_spin_role(spin, role)
@@ -35,27 +49,48 @@ def note_for_spins_role(spins, role)
35
49
  return note if note
36
50
  end
37
51
 
38
- 'No %{role} available' % { role: role }
52
+ NOT_AVAILABLE_TEMPLATE % { role: role }
39
53
  end
40
54
 
41
55
  def note_for_spin_role(spin, role)
56
+ if spin.optional_role == role
57
+ return OPTIONAL_REVIEW_TEMPLATE % { role: role.capitalize }
58
+ end
59
+
42
60
  spin.public_send(role)&.markdown_name(author: roulette.team_mr_author)
43
61
  end
44
62
 
45
- def markdown_row_for_spins(spins_array)
63
+ def markdown_row_for_spins(category = nil, spins_array)
46
64
  reviewer_note = note_for_spins_role(spins_array, :reviewer)
47
65
  maintainer_note = note_for_spins_role(spins_array, :maintainer)
48
66
 
49
- "#{reviewer_note} | #{maintainer_note} |"
67
+ row = +"| #{reviewer_note} | #{maintainer_note} |"
68
+ row.prepend("| #{helper.label_for_category(category)} ") if categories_defined?
69
+
70
+ row
50
71
  end
51
72
 
52
- if helper.changes.any?
53
- random_roulette_spins = roulette.spin
73
+ def categories_defined?
74
+ helper.config.files_to_category.any?
75
+ end
76
+
77
+ def categories(changes)
78
+ categories_defined? ? changes.keys : [nil]
79
+ end
80
+
81
+ def table_header
82
+ categories_defined? ? TABLE_HEADER_WITH_CATEGORIES : TABLE_HEADER_WITHOUT_CATEGORIES
83
+ end
84
+
85
+ changes = helper.changes_by_category
86
+
87
+ if changes.any?
88
+ random_roulette_spins = roulette.spin(nil, categories(changes))
54
89
 
55
90
  rows = random_roulette_spins.map do |spin|
56
- markdown_row_for_spins([spin])
91
+ markdown_row_for_spins(spin.category, [spin])
57
92
  end
58
93
 
59
94
  markdown(MESSAGE)
60
- markdown(TABLE_MARKDOWN + rows.join("\n")) unless rows.empty?
95
+ markdown(TABLE_MARKDOWN + table_header + rows.join("\n")) unless rows.empty?
61
96
  end
@@ -25,7 +25,7 @@ module Gitlab
25
25
  DEFAULT_COMMIT_MESSAGES_MAX_COMMITS_COUNT = 10
26
26
 
27
27
  def initialize
28
- @files_to_category = []
28
+ @files_to_category = {}
29
29
  @project_name = ENV["CI_PROJECT_NAME"]
30
30
  @code_size_thresholds = DEFAULT_CHANGES_SIZE_THRESHOLDS
31
31
  @max_commits_count = DEFAULT_COMMIT_MESSAGES_MAX_COMMITS_COUNT
@@ -1,5 +1,5 @@
1
1
  module Gitlab
2
2
  module Dangerfiles
3
- VERSION = "2.6.0"
3
+ VERSION = "2.8.0"
4
4
  end
5
5
  end
@@ -42,6 +42,9 @@ module Gitlab
42
42
  # @return [Gitlab::Dangerfiles::Engine]
43
43
  def initialize(dangerfile)
44
44
  @dangerfile = dangerfile
45
+
46
+ # Import internal plugins eagerly, since other functionality in this class may depend on them.
47
+ danger_plugin.import_plugin(File.expand_path("../danger/plugins/internal/*.rb", __dir__))
45
48
  end
46
49
 
47
50
  # Import all available plugins.
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: 2.6.0
4
+ version: 2.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitLab
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-30 00:00:00.000000000 Z
11
+ date: 2022-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-gitlab
@@ -149,7 +149,7 @@ files:
149
149
  - fixtures/emojis/aliases.json
150
150
  - fixtures/emojis/digests.json
151
151
  - gitlab-dangerfiles.gemspec
152
- - lib/danger/plugins/helper.rb
152
+ - lib/danger/plugins/internal/helper.rb
153
153
  - lib/danger/plugins/roulette.rb
154
154
  - lib/danger/rules/changes_size/Dangerfile
155
155
  - lib/danger/rules/commit_messages/Dangerfile
@@ -170,14 +170,14 @@ files:
170
170
  - lib/gitlab/dangerfiles/weightage.rb
171
171
  - lib/gitlab/dangerfiles/weightage/maintainers.rb
172
172
  - lib/gitlab/dangerfiles/weightage/reviewers.rb
173
- homepage: https://gitlab.com/gitlab-org/gitlab-dangerfiles
173
+ homepage: https://gitlab.com/gitlab-org/ruby/gems/gitlab-dangerfiles
174
174
  licenses:
175
175
  - MIT
176
176
  metadata:
177
177
  allowed_push_host: https://rubygems.org
178
- homepage_uri: https://gitlab.com/gitlab-org/gitlab-dangerfiles
179
- source_code_uri: https://gitlab.com/gitlab-org/gitlab-dangerfiles
180
- changelog_uri: https://gitlab.com/gitlab-org/gitlab-dangerfiles/-/releases
178
+ homepage_uri: https://gitlab.com/gitlab-org/ruby/gems/gitlab-dangerfiles
179
+ source_code_uri: https://gitlab.com/gitlab-org/ruby/gems/gitlab-dangerfiles
180
+ changelog_uri: https://gitlab.com/gitlab-org/ruby/gems/gitlab-dangerfiles/-/releases
181
181
  post_install_message:
182
182
  rdoc_options: []
183
183
  require_paths: