gitlab-dangerfiles 0.1.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/lib/danger/helper.rb +155 -113
  3. data/lib/danger/roulette.rb +68 -36
  4. data/lib/gitlab/dangerfiles.rb +0 -34
  5. data/lib/gitlab/dangerfiles/base_linter.rb +96 -0
  6. data/lib/gitlab/dangerfiles/commit_linter.rb +25 -103
  7. data/lib/gitlab/dangerfiles/merge_request_linter.rb +30 -0
  8. data/lib/gitlab/dangerfiles/teammate.rb +23 -9
  9. data/lib/gitlab/dangerfiles/title_linting.rb +38 -0
  10. data/lib/gitlab/dangerfiles/version.rb +1 -1
  11. data/lib/gitlab/dangerfiles/weightage.rb +10 -0
  12. data/lib/gitlab/dangerfiles/weightage/maintainers.rb +33 -0
  13. data/lib/gitlab/dangerfiles/weightage/reviewers.rb +65 -0
  14. metadata +9 -25
  15. data/lib/danger/changelog.rb +0 -39
  16. data/lib/danger/sidekiq_queues.rb +0 -37
  17. data/lib/gitlab/dangerfiles/bundle_size/Dangerfile +0 -38
  18. data/lib/gitlab/dangerfiles/ce_ee_vue_templates/Dangerfile +0 -56
  19. data/lib/gitlab/dangerfiles/changelog/Dangerfile +0 -90
  20. data/lib/gitlab/dangerfiles/changes_size/Dangerfile +0 -17
  21. data/lib/gitlab/dangerfiles/commit_messages/Dangerfile +0 -135
  22. data/lib/gitlab/dangerfiles/database/Dangerfile +0 -67
  23. data/lib/gitlab/dangerfiles/documentation/Dangerfile +0 -29
  24. data/lib/gitlab/dangerfiles/duplicate_yarn_dependencies/Dangerfile +0 -29
  25. data/lib/gitlab/dangerfiles/eslint/Dangerfile +0 -31
  26. data/lib/gitlab/dangerfiles/frozen_string/Dangerfile +0 -28
  27. data/lib/gitlab/dangerfiles/karma/Dangerfile +0 -51
  28. data/lib/gitlab/dangerfiles/metadata/Dangerfile +0 -50
  29. data/lib/gitlab/dangerfiles/popen.rb +0 -55
  30. data/lib/gitlab/dangerfiles/prettier/Dangerfile +0 -41
  31. data/lib/gitlab/dangerfiles/roulette/Dangerfile +0 -97
  32. data/lib/gitlab/dangerfiles/sidekiq_queues/Dangerfile +0 -27
  33. data/lib/gitlab/dangerfiles/specs/Dangerfile +0 -42
  34. data/lib/gitlab/dangerfiles/tasks.rb +0 -19
  35. data/lib/gitlab/dangerfiles/telemetry/Dangerfile +0 -32
  36. data/lib/gitlab/dangerfiles/utility_css/Dangerfile +0 -51
@@ -1,5 +1,5 @@
1
1
  module Gitlab
2
2
  module Dangerfiles
3
- VERSION = "0.1.0"
3
+ VERSION = "0.6.0"
4
4
  end
5
5
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gitlab
4
+ module Dangerfiles
5
+ module Weightage
6
+ CAPACITY_MULTIPLIER = 2 # change this number to change what it means to be a reduced capacity reviewer 1/this number
7
+ BASE_REVIEWER_WEIGHT = 1
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../weightage"
4
+
5
+ module Gitlab
6
+ module Dangerfiles
7
+ module Weightage
8
+ class Maintainers
9
+ def initialize(maintainers)
10
+ @maintainers = maintainers
11
+ end
12
+
13
+ def execute
14
+ maintainers.each_with_object([]) do |maintainer, weighted_maintainers|
15
+ add_weighted_reviewer(weighted_maintainers, maintainer, Gitlab::Dangerfiles::Weightage::BASE_REVIEWER_WEIGHT)
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :maintainers
22
+
23
+ def add_weighted_reviewer(reviewers, reviewer, weight)
24
+ if reviewer.reduced_capacity
25
+ reviewers.fill(reviewer, reviewers.size, weight)
26
+ else
27
+ reviewers.fill(reviewer, reviewers.size, weight * Gitlab::Dangerfiles::Weightage::CAPACITY_MULTIPLIER)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../weightage"
4
+
5
+ module Gitlab
6
+ module Dangerfiles
7
+ module Weightage
8
+ # Weights after (current multiplier of 2)
9
+ #
10
+ # +------------------------------+--------------------------------+
11
+ # | reviewer type | weight(times in reviewer pool) |
12
+ # +------------------------------+--------------------------------+
13
+ # | reduced capacity reviewer | 1 |
14
+ # | reviewer | 2 |
15
+ # | hungry reviewer | 4 |
16
+ # | reduced capacity traintainer | 3 |
17
+ # | traintainer | 6 |
18
+ # | hungry traintainer | 8 |
19
+ # +------------------------------+--------------------------------+
20
+ #
21
+ class Reviewers
22
+ DEFAULT_REVIEWER_WEIGHT = Gitlab::Dangerfiles::Weightage::CAPACITY_MULTIPLIER * Gitlab::Dangerfiles::Weightage::BASE_REVIEWER_WEIGHT
23
+ TRAINTAINER_WEIGHT = 3
24
+
25
+ def initialize(reviewers, traintainers)
26
+ @reviewers = reviewers
27
+ @traintainers = traintainers
28
+ end
29
+
30
+ def execute
31
+ # TODO: take CODEOWNERS into account?
32
+ # https://gitlab.com/gitlab-org/gitlab/issues/26723
33
+
34
+ weighted_reviewers + weighted_traintainers
35
+ end
36
+
37
+ private
38
+
39
+ attr_reader :reviewers, :traintainers
40
+
41
+ def weighted_reviewers
42
+ reviewers.each_with_object([]) do |reviewer, total_reviewers|
43
+ add_weighted_reviewer(total_reviewers, reviewer, Gitlab::Dangerfiles::Weightage::BASE_REVIEWER_WEIGHT)
44
+ end
45
+ end
46
+
47
+ def weighted_traintainers
48
+ traintainers.each_with_object([]) do |reviewer, total_traintainers|
49
+ add_weighted_reviewer(total_traintainers, reviewer, TRAINTAINER_WEIGHT)
50
+ end
51
+ end
52
+
53
+ def add_weighted_reviewer(reviewers, reviewer, weight)
54
+ if reviewer.reduced_capacity
55
+ reviewers.fill(reviewer, reviewers.size, weight)
56
+ elsif reviewer.hungry
57
+ reviewers.fill(reviewer, reviewers.size, weight * Gitlab::Dangerfiles::Weightage::CAPACITY_MULTIPLIER + DEFAULT_REVIEWER_WEIGHT)
58
+ else
59
+ reviewers.fill(reviewer, reviewers.size, weight * Gitlab::Dangerfiles::Weightage::CAPACITY_MULTIPLIER)
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ 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.1.0
4
+ version: 0.6.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: 2020-08-27 00:00:00.000000000 Z
11
+ date: 2021-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger
@@ -130,37 +130,21 @@ files:
130
130
  - fixtures/emojis/aliases.json
131
131
  - fixtures/emojis/digests.json
132
132
  - gitlab-dangerfiles.gemspec
133
- - lib/danger/changelog.rb
134
133
  - lib/danger/helper.rb
135
134
  - lib/danger/roulette.rb
136
- - lib/danger/sidekiq_queues.rb
137
135
  - lib/gitlab-dangerfiles.rb
138
136
  - lib/gitlab/Dangerfile
139
137
  - lib/gitlab/dangerfiles.rb
140
- - lib/gitlab/dangerfiles/bundle_size/Dangerfile
141
- - lib/gitlab/dangerfiles/ce_ee_vue_templates/Dangerfile
142
- - lib/gitlab/dangerfiles/changelog/Dangerfile
143
- - lib/gitlab/dangerfiles/changes_size/Dangerfile
138
+ - lib/gitlab/dangerfiles/base_linter.rb
144
139
  - lib/gitlab/dangerfiles/commit_linter.rb
145
- - lib/gitlab/dangerfiles/commit_messages/Dangerfile
146
- - lib/gitlab/dangerfiles/database/Dangerfile
147
- - lib/gitlab/dangerfiles/documentation/Dangerfile
148
- - lib/gitlab/dangerfiles/duplicate_yarn_dependencies/Dangerfile
149
140
  - lib/gitlab/dangerfiles/emoji_checker.rb
150
- - lib/gitlab/dangerfiles/eslint/Dangerfile
151
- - lib/gitlab/dangerfiles/frozen_string/Dangerfile
152
- - lib/gitlab/dangerfiles/karma/Dangerfile
153
- - lib/gitlab/dangerfiles/metadata/Dangerfile
154
- - lib/gitlab/dangerfiles/popen.rb
155
- - lib/gitlab/dangerfiles/prettier/Dangerfile
156
- - lib/gitlab/dangerfiles/roulette/Dangerfile
157
- - lib/gitlab/dangerfiles/sidekiq_queues/Dangerfile
158
- - lib/gitlab/dangerfiles/specs/Dangerfile
159
- - lib/gitlab/dangerfiles/tasks.rb
141
+ - lib/gitlab/dangerfiles/merge_request_linter.rb
160
142
  - lib/gitlab/dangerfiles/teammate.rb
161
- - lib/gitlab/dangerfiles/telemetry/Dangerfile
162
- - lib/gitlab/dangerfiles/utility_css/Dangerfile
143
+ - lib/gitlab/dangerfiles/title_linting.rb
163
144
  - lib/gitlab/dangerfiles/version.rb
145
+ - lib/gitlab/dangerfiles/weightage.rb
146
+ - lib/gitlab/dangerfiles/weightage/maintainers.rb
147
+ - lib/gitlab/dangerfiles/weightage/reviewers.rb
164
148
  homepage: https://gitlab.com/gitlab-org/gitlab-dangerfiles
165
149
  licenses:
166
150
  - MIT
@@ -184,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
168
  - !ruby/object:Gem::Version
185
169
  version: '0'
186
170
  requirements: []
187
- rubygems_version: 3.1.2
171
+ rubygems_version: 3.1.4
188
172
  signing_key:
189
173
  specification_version: 4
190
174
  summary: This gem provides common Dangerfile and plugins for GitLab projects.
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Danger
4
- # Common helper functions for our danger scripts. See Danger::Helper
5
- # for more details
6
- class Changelog < Danger::Plugin
7
- NO_CHANGELOG_LABELS = [
8
- "backstage", # To be removed by https://gitlab.com/gitlab-org/gitlab/-/issues/222360.
9
- "tooling",
10
- "tooling::pipelines",
11
- "tooling::workflow",
12
- "ci-build",
13
- "meta",
14
- ].freeze
15
- NO_CHANGELOG_CATEGORIES = %i[docs none].freeze
16
-
17
- def needed?
18
- categories_need_changelog? && (gitlab.mr_labels & NO_CHANGELOG_LABELS).empty?
19
- end
20
-
21
- def found
22
- @found ||= git.added_files.find { |path| path =~ %r{\A(ee/)?(changelogs/unreleased)(-ee)?/} }
23
- end
24
-
25
- def sanitized_mr_title
26
- gitlab.mr_json["title"].gsub(/^WIP: */, "").gsub(/`/, '\\\`')
27
- end
28
-
29
- def ee_changelog?
30
- found.start_with?("ee/")
31
- end
32
-
33
- private
34
-
35
- def categories_need_changelog?
36
- (helper.changes_by_category.keys - NO_CHANGELOG_CATEGORIES).any?
37
- end
38
- end
39
- end
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Danger
4
- # Common helper functions for our danger scripts. See Danger::Helper
5
- # for more details
6
- class SidekiqQueues < Danger::Plugin
7
- def changed_queue_files
8
- @changed_queue_files ||= git.modified_files.grep(%r{\A(ee/)?app/workers/all_queues\.yml})
9
- end
10
-
11
- def added_queue_names
12
- @added_queue_names ||= new_queues.keys - old_queues.keys
13
- end
14
-
15
- def changed_queue_names
16
- @changed_queue_names ||=
17
- (new_queues.values_at(*old_queues.keys) - old_queues.values)
18
- .compact.map { |queue| queue[:name] }
19
- end
20
-
21
- private
22
-
23
- def old_queues
24
- @old_queues ||= queues_for(gitlab.base_commit)
25
- end
26
-
27
- def new_queues
28
- @new_queues ||= queues_for(gitlab.head_commit)
29
- end
30
-
31
- def queues_for(branch)
32
- changed_queue_files
33
- .flat_map { |file| YAML.safe_load(`git show #{branch}:#{file}`, permitted_classes: [Symbol]) }
34
- .to_h { |queue| [queue[:name], queue] }
35
- end
36
- end
37
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- analysis_result = "./bundle-size-review/analysis.json"
4
- markdown_result = "./bundle-size-review/comparison.md"
5
-
6
- # Executing the webpack-entry-point-analyser
7
- # We would like to do that in the CI file directly,
8
- # but unfortunately the head_commit SHA is not available
9
- # as a CI variable due to our merge into master simulation
10
- analyze_cmd = [
11
- "webpack-entry-point-analyser",
12
- "--from-file ./webpack-report/stats.json",
13
- "--json #{analysis_result}",
14
- " --sha #{gitlab&.head_commit}"
15
- ].join(" ")
16
-
17
- # execute analysis
18
- `#{analyze_cmd}`
19
-
20
- # We are executing the comparison by comparing the start_sha
21
- # to the current pipeline result. The start_sha is the commit
22
- # from master that was merged into for the merged pipeline.
23
- comparison_cmd = [
24
- "webpack-compare-reports",
25
- "--job #{ENV["CI_JOB_ID"]}",
26
- "--to-file #{analysis_result}",
27
- "--html ./bundle-size-review/comparison.html",
28
- "--markdown #{markdown_result}"
29
- ].join(" ")
30
-
31
- # execute comparison
32
- `#{comparison_cmd}`
33
-
34
- comment = `cat #{markdown_result}`
35
-
36
- markdown(<<~MARKDOWN)
37
- #{comment}
38
- MARKDOWN
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'cgi'
3
-
4
- def get_vue_files_with_ce_and_ee_versions(files)
5
- files.select do |file|
6
- if file.end_with?('.vue')
7
- counterpart_path = if file.start_with?('ee/')
8
- file.delete_prefix('ee/')
9
- else
10
- "ee/#{file}"
11
- end
12
-
13
- escaped_path = CGI.escape(counterpart_path)
14
- api_endpoint = "https://gitlab.com/api/v4/projects/gitlab-org%2Fgitlab-ee/repository/files/#{escaped_path}?ref=master"
15
- response = HTTParty.get(api_endpoint) # rubocop:disable Gitlab/HTTParty
16
- response.code != 404
17
- else
18
- false
19
- end
20
- end
21
- end
22
-
23
- vue_candidates = get_vue_files_with_ce_and_ee_versions(helper.all_changed_files)
24
-
25
- return if vue_candidates.empty?
26
-
27
- message 'This merge request includes changes to Vue files that have both CE and EE versions.'
28
-
29
- markdown(<<~MARKDOWN)
30
- ## Vue `<template>` in CE and EE
31
-
32
- Some Vue files in CE have a counterpart in EE.
33
- (For example, `path/to/file.vue` and `ee/path/to/file.vue`.)
34
-
35
- When run in the context of CE, the `<template>` of the CE Vue file is used.
36
- When run in the context of EE, the `<template>` of the EE Vue file is used.
37
-
38
- It's easy to accidentally make a change to a CE `<template>` that _should_
39
- appear in both CE and EE without making the change in both places.
40
- When this happens, the change only takes effect in CE.
41
-
42
- The following Vue files were changed as part of this merge request that
43
- include both a CE and EE version of the file:
44
-
45
- * #{vue_candidates.map { |path| "`#{path}`" }.join("\n* ")}
46
-
47
- If you made a change to the `<template>` of any of these Vue files that
48
- should be visible in both CE and EE, please ensure you have made your
49
- change to both versions of the file.
50
-
51
- ### A better alternative
52
-
53
- An even _better_ alternative is to refactor this component to only use
54
- a single template for both CE and EE. More info on this approach here:
55
- https://docs.gitlab.com/ee/development/ee_features.html#template-tag
56
- MARKDOWN
@@ -1,90 +0,0 @@
1
- # frozen_string_literal: true
2
- # rubocop:disable Style/SignalException
3
-
4
- require 'yaml'
5
-
6
- SEE_DOC = "See the [changelog documentation](https://docs.gitlab.com/ee/development/changelog.html)."
7
- CREATE_CHANGELOG_MESSAGE = <<~MSG
8
- If you want to create a changelog entry for GitLab FOSS, run the following:
9
-
10
- ```
11
- bin/changelog -m %<mr_iid>s "%<mr_title>s"
12
- ```
13
-
14
- If you want to create a changelog entry for GitLab EE, run the following instead:
15
-
16
- ```
17
- bin/changelog --ee -m %<mr_iid>s "%<mr_title>s"
18
- ```
19
-
20
- If this merge request [doesn't need a CHANGELOG entry](https://docs.gitlab.com/ee/development/changelog.html#what-warrants-a-changelog-entry), feel free to ignore this message.
21
- MSG
22
-
23
- SUGGEST_MR_COMMENT = <<~SUGGEST_COMMENT
24
- ```suggestion
25
- merge_request: %<mr_iid>s
26
- ```
27
-
28
- #{SEE_DOC}
29
- SUGGEST_COMMENT
30
-
31
- def check_changelog_yaml(path)
32
- raw_file = File.read(path)
33
- yaml = YAML.safe_load(raw_file)
34
-
35
- fail "`title` should be set, in #{helper.html_link(path)}! #{SEE_DOC}" if yaml["title"].nil?
36
- fail "`type` should be set, in #{helper.html_link(path)}! #{SEE_DOC}" if yaml["type"].nil?
37
-
38
- return if helper.security_mr?
39
-
40
- cherry_pick_against_stable_branch = helper.cherry_pick_mr? && helper.stable_branch?
41
-
42
- if yaml["merge_request"].nil?
43
- mr_line = raw_file.lines.find_index("merge_request:\n")
44
-
45
- if mr_line
46
- markdown(format(SUGGEST_MR_COMMENT, mr_iid: gitlab.mr_json["iid"]), file: path, line: mr_line.succ)
47
- else
48
- message "Consider setting `merge_request` to #{gitlab.mr_json["iid"]} in #{helper.html_link(path)}. #{SEE_DOC}"
49
- end
50
- elsif yaml["merge_request"] != gitlab.mr_json["iid"] && !cherry_pick_against_stable_branch
51
- fail "Merge request ID was not set to #{gitlab.mr_json["iid"]}! #{SEE_DOC}"
52
- end
53
- rescue Psych::SyntaxError, Psych::DisallowedClass, Psych::BadAlias
54
- # YAML could not be parsed, fail the build.
55
- fail "#{helper.html_link(path)} isn't valid YAML! #{SEE_DOC}"
56
- rescue StandardError => e
57
- warn "There was a problem trying to check the Changelog. Exception: #{e.class.name} - #{e.message}"
58
- end
59
-
60
- def check_changelog_path(path)
61
- ee_changes = helper.all_ee_changes.dup
62
- ee_changes.delete(path)
63
-
64
- if ee_changes.any? && !changelog.ee_changelog?
65
- warn "This MR has a Changelog file outside `ee/`, but code changes in `ee/`. Consider moving the Changelog file into `ee/`."
66
- end
67
-
68
- if ee_changes.empty? && changelog.ee_changelog?
69
- warn "This MR has a Changelog file in `ee/`, but no code changes in `ee/`. Consider moving the Changelog file outside `ee/`."
70
- end
71
- end
72
-
73
- def sanitized_mr_title
74
- helper.sanitize_mr_title(gitlab.mr_json["title"])
75
- end
76
-
77
- if git.modified_files.include?("CHANGELOG.md")
78
- fail "**CHANGELOG.md was edited.** Please remove the additions and create a CHANGELOG entry.\n\n" +
79
- format(CREATE_CHANGELOG_MESSAGE, mr_iid: gitlab.mr_json["iid"], mr_title: sanitized_mr_title)
80
- end
81
-
82
- changelog_found = changelog.found
83
-
84
- if changelog_found
85
- check_changelog_yaml(changelog_found)
86
- check_changelog_path(changelog_found)
87
- elsif changelog.needed?
88
- message "**[CHANGELOG missing](https://docs.gitlab.com/ee/development/changelog.html)**:\n\n" +
89
- format(CREATE_CHANGELOG_MESSAGE, mr_iid: gitlab.mr_json["iid"], mr_title: sanitized_mr_title)
90
- end