gitlab-dangerfiles 2.6.1 → 2.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: 7c22945b63f8eda2553d2324e3b309d1d2ae52634648325b20247e4888160abf
4
- data.tar.gz: 4227fa40a95128828aae1a29bd1f777132644a875d9a633c360e7a5515bf521b
3
+ metadata.gz: 5d547fabe6901fa966c63b46205d60383a37876720750d659b1efc911f5ff5a9
4
+ data.tar.gz: c2acf1003771ac3e206388e51bd5c6c55df9aab6e554f122cdac7c55de446619
5
5
  SHA512:
6
- metadata.gz: 3d3cda663afcc94f252d397c4b683a4143c0b60c758d279addbfe0816460962bc9679c0ce6424ae72e7829603eaf34ea3bffa3ad63c89facf6789dfc531a951d
7
- data.tar.gz: 5df8ecd28fc500aaf2d61bb069c59461239f1e8f427211eac88a56fe68e105e8c0dfdc9b7d8371667c4e63e218c461052ac80341291f0074339f9affb3e886f7
6
+ metadata.gz: 8e8ea522c518333c74741b7c7f1fa9647117a2c181c05c2c6603a72e3ea0bc635e56dff1f5b8f0369d840f9adb55341571863f898cbc67d523ca6dbef6bc8603
7
+ data.tar.gz: 4ef5aa8b96aa69a98daec6bdc2f721aed505dd96c52f931e427269bd8f789b987273cc3be364746bdd26c00154da8a974883ac503c35e0b6edb701990f7ea48d
@@ -7,7 +7,6 @@ with the latest commit from this merge request. -->
7
7
  - [ ] Based on the diff, `version.rb` is updated, according to [SemVer](https://semver.org).
8
8
 
9
9
  - Checklist after merging:
10
- - [ ] [Update the release notes for the newly created tag](docs/release_process.md#how-to).
11
10
  - [ ] Check that automatic release notes (generated following the same process as https://docs.gitlab.com/ee/development/changelog.html) are correct.
12
11
 
13
12
  /label ~"type::maintenance" ~"static code analysis"
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>.
@@ -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
 
@@ -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.1"
3
+ VERSION = "2.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: 2.6.1
4
+ version: 2.7.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-12-01 00:00:00.000000000 Z
11
+ date: 2021-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-gitlab