Commit 496517e9 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'caalberts-move-danger-out-of-lib' into 'master'

Move Danger code from lib/ to tooling/ [RUN ALL RSPEC]

See merge request gitlab-org/gitlab!51566
parents ce7382e7 4ec103c6
...@@ -173,7 +173,7 @@ ...@@ -173,7 +173,7 @@
/.gitlab/CODEOWNERS @gl-quality/eng-prod /.gitlab/CODEOWNERS @gl-quality/eng-prod
Dangerfile @gl-quality/eng-prod Dangerfile @gl-quality/eng-prod
/danger/ @gl-quality/eng-prod /danger/ @gl-quality/eng-prod
/lib/gitlab/danger/ @gl-quality/eng-prod /tooling/danger/ @gl-quality/eng-prod
/scripts/ @gl-quality/eng-prod /scripts/ @gl-quality/eng-prod
/scripts/frontend/ @gl-quality/eng-prod @gitlab-org/maintainers/frontend /scripts/frontend/ @gl-quality/eng-prod @gitlab-org/maintainers/frontend
/scripts/review_apps/seed-dast-test-data.sh @dappelt @ngeorge1 @gl-quality/eng-prod /scripts/review_apps/seed-dast-test-data.sh @dappelt @ngeorge1 @gl-quality/eng-prod
......
...@@ -242,7 +242,7 @@ Gitlab/Json: ...@@ -242,7 +242,7 @@ Gitlab/Json:
- 'scripts/**/*' - 'scripts/**/*'
- 'lib/rspec_flaky/**/*' - 'lib/rspec_flaky/**/*'
- 'lib/quality/**/*' - 'lib/quality/**/*'
- 'lib/gitlab/danger/**/*' - 'tooling/danger/**/*'
Gitlab/AvoidUploadedFileFromParams: Gitlab/AvoidUploadedFileFromParams:
Enabled: true Enabled: true
......
...@@ -141,7 +141,7 @@ Lint/BinaryOperatorWithIdenticalOperands: ...@@ -141,7 +141,7 @@ Lint/BinaryOperatorWithIdenticalOperands:
- 'ee/spec/lib/ee/gitlab/application_context_spec.rb' - 'ee/spec/lib/ee/gitlab/application_context_spec.rb'
- 'spec/helpers/visibility_level_helper_spec.rb' - 'spec/helpers/visibility_level_helper_spec.rb'
- 'spec/lib/gitlab/conan_token_spec.rb' - 'spec/lib/gitlab/conan_token_spec.rb'
- 'spec/lib/gitlab/danger/sidekiq_queues_spec.rb' - 'spec/tooling/danger/sidekiq_queues_spec.rb'
- 'spec/lib/gitlab/git/conflict/parser_spec.rb' - 'spec/lib/gitlab/git/conflict/parser_spec.rb'
- 'spec/lib/gitlab/graphql/lazy_spec.rb' - 'spec/lib/gitlab/graphql/lazy_spec.rb'
- 'spec/models/ci/build_trace_chunk_spec.rb' - 'spec/models/ci/build_trace_chunk_spec.rb'
...@@ -185,8 +185,8 @@ Lint/EmptyFile: ...@@ -185,8 +185,8 @@ Lint/EmptyFile:
# Cop supports --auto-correct. # Cop supports --auto-correct.
Lint/IdentityComparison: Lint/IdentityComparison:
Exclude: Exclude:
- 'spec/lib/gitlab/danger/weightage/maintainers_spec.rb' - 'spec/tooling/danger/weightage/maintainers_spec.rb'
- 'spec/lib/gitlab/danger/weightage/reviewers_spec.rb' - 'spec/tooling/danger/weightage/reviewers_spec.rb'
# Offense count: 184 # Offense count: 184
# Configuration parameters: MaximumRangeSize. # Configuration parameters: MaximumRangeSize.
...@@ -263,7 +263,7 @@ Metrics/CyclomaticComplexity: ...@@ -263,7 +263,7 @@ Metrics/CyclomaticComplexity:
- 'lib/banzai/filter/abstract_reference_filter.rb' - 'lib/banzai/filter/abstract_reference_filter.rb'
- 'lib/declarative_policy/runner.rb' - 'lib/declarative_policy/runner.rb'
- 'lib/gitlab/conflict/file.rb' - 'lib/gitlab/conflict/file.rb'
- 'lib/gitlab/danger/roulette.rb' - 'tooling/danger/roulette.rb'
- 'lib/gitlab/diff/parser.rb' - 'lib/gitlab/diff/parser.rb'
- 'lib/gitlab/rack_attack.rb' - 'lib/gitlab/rack_attack.rb'
- 'lib/gitlab/sidekiq_cluster/cli.rb' - 'lib/gitlab/sidekiq_cluster/cli.rb'
...@@ -285,7 +285,7 @@ Metrics/PerceivedComplexity: ...@@ -285,7 +285,7 @@ Metrics/PerceivedComplexity:
- 'lib/banzai/renderer.rb' - 'lib/banzai/renderer.rb'
- 'lib/declarative_policy/runner.rb' - 'lib/declarative_policy/runner.rb'
- 'lib/gitlab/conflict/file.rb' - 'lib/gitlab/conflict/file.rb'
- 'lib/gitlab/danger/roulette.rb' - 'tooling/danger/roulette.rb'
- 'lib/gitlab/rack_attack.rb' - 'lib/gitlab/rack_attack.rb'
- 'lib/gitlab/sidekiq_cluster/cli.rb' - 'lib/gitlab/sidekiq_cluster/cli.rb'
- 'lib/gitlab/utils/merge_hash.rb' - 'lib/gitlab/utils/merge_hash.rb'
...@@ -629,7 +629,7 @@ Rails/IndexBy: ...@@ -629,7 +629,7 @@ Rails/IndexBy:
- 'ee/lib/gitlab/analytics/type_of_work/tasks_by_type.rb' - 'ee/lib/gitlab/analytics/type_of_work/tasks_by_type.rb'
- 'ee/lib/gitlab/elastic/document_reference.rb' - 'ee/lib/gitlab/elastic/document_reference.rb'
- 'ee/lib/gitlab/group_plans_preloader.rb' - 'ee/lib/gitlab/group_plans_preloader.rb'
- 'lib/gitlab/danger/sidekiq_queues.rb' - 'tooling/danger/sidekiq_queues.rb'
- 'lib/gitlab/database/count/reltuples_count_strategy.rb' - 'lib/gitlab/database/count/reltuples_count_strategy.rb'
- 'lib/gitlab/language_detection.rb' - 'lib/gitlab/language_detection.rb'
......
# frozen_string_literal: true # frozen_string_literal: true
require_relative 'lib/gitlab_danger' require_relative 'tooling/gitlab_danger'
require_relative 'lib/gitlab/danger/request_helper' require_relative 'tooling/danger/request_helper'
danger.import_plugin('danger/plugins/helper.rb') danger.import_plugin('danger/plugins/helper.rb')
danger.import_plugin('danger/plugins/roulette.rb') danger.import_plugin('danger/plugins/roulette.rb')
......
# frozen_string_literal: true # frozen_string_literal: true
require_relative File.expand_path('../../lib/gitlab/danger/commit_linter', __dir__) require_relative File.expand_path('../../tooling/danger/commit_linter', __dir__)
require_relative File.expand_path('../../lib/gitlab/danger/merge_request_linter', __dir__) require_relative File.expand_path('../../tooling/danger/merge_request_linter', __dir__)
COMMIT_MESSAGE_GUIDELINES = "https://docs.gitlab.com/ee/development/contributing/merge_request_workflow.html#commit-messages-guidelines" COMMIT_MESSAGE_GUIDELINES = "https://docs.gitlab.com/ee/development/contributing/merge_request_workflow.html#commit-messages-guidelines"
MORE_INFO = "For more information, take a look at our [Commit message guidelines](#{COMMIT_MESSAGE_GUIDELINES})." MORE_INFO = "For more information, take a look at our [Commit message guidelines](#{COMMIT_MESSAGE_GUIDELINES})."
...@@ -54,7 +54,7 @@ end ...@@ -54,7 +54,7 @@ end
# https://github.com/jonallured/danger-commit_lint because its output is not # https://github.com/jonallured/danger-commit_lint because its output is not
# very helpful, and it doesn't offer the means of ignoring merge commits. # very helpful, and it doesn't offer the means of ignoring merge commits.
def lint_commit(commit) def lint_commit(commit)
linter = Gitlab::Danger::CommitLinter.new(commit) linter = Tooling::Danger::CommitLinter.new(commit)
# For now we'll ignore merge commits, as getting rid of those is a problem # For now we'll ignore merge commits, as getting rid of those is a problem
# separate from enforcing good commit messages. # separate from enforcing good commit messages.
...@@ -93,7 +93,7 @@ end ...@@ -93,7 +93,7 @@ end
def lint_mr_title(mr_title) def lint_mr_title(mr_title)
commit = Struct.new(:message, :sha).new(mr_title) commit = Struct.new(:message, :sha).new(mr_title)
Gitlab::Danger::MergeRequestLinter.new(commit).lint Tooling::Danger::MergeRequestLinter.new(commit).lint
end end
def count_non_fixup_commits(commit_linters) def count_non_fixup_commits(commit_linters)
......
# frozen_string_literal: true # frozen_string_literal: true
require_relative '../../lib/gitlab/danger/changelog' require_relative '../../tooling/danger/changelog'
module Danger module Danger
class Changelog < Plugin class Changelog < Plugin
# Put the helper code somewhere it can be tested # Put the helper code somewhere it can be tested
include Gitlab::Danger::Changelog include Tooling::Danger::Changelog
end end
end end
# frozen_string_literal: true # frozen_string_literal: true
require_relative '../../lib/gitlab/danger/helper' require_relative '../../tooling/danger/helper'
module Danger module Danger
# Common helper functions for our danger scripts. See Gitlab::Danger::Helper # Common helper functions for our danger scripts. See Tooling::Danger::Helper
# for more details # for more details
class Helper < Plugin class Helper < Plugin
# Put the helper code somewhere it can be tested # Put the helper code somewhere it can be tested
include Gitlab::Danger::Helper include Tooling::Danger::Helper
end end
end end
# frozen_string_literal: true # frozen_string_literal: true
require_relative '../../lib/gitlab/danger/roulette' require_relative '../../tooling/danger/roulette'
module Danger module Danger
class Roulette < Plugin class Roulette < Plugin
# Put the helper code somewhere it can be tested # Put the helper code somewhere it can be tested
include Gitlab::Danger::Roulette include Tooling::Danger::Roulette
end end
end end
# frozen_string_literal: true # frozen_string_literal: true
require_relative '../../lib/gitlab/danger/sidekiq_queues' require_relative '../../tooling/danger/sidekiq_queues'
module Danger module Danger
class SidekiqQueues < Plugin class SidekiqQueues < Plugin
# Put the helper code somewhere it can be tested # Put the helper code somewhere it can be tested
include Gitlab::Danger::SidekiqQueues include Tooling::Danger::SidekiqQueues
end end
end end
...@@ -35,7 +35,7 @@ UNKNOWN_FILES_MESSAGE = <<MARKDOWN ...@@ -35,7 +35,7 @@ UNKNOWN_FILES_MESSAGE = <<MARKDOWN
These files couldn't be categorised, so Danger was unable to suggest a reviewer. These files couldn't be categorised, so Danger was unable to suggest a reviewer.
Please consider creating a merge request to Please consider creating a merge request to
[add support](https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/danger/helper.rb) [add support](https://gitlab.com/gitlab-org/gitlab/blob/master/tooling/danger/helper.rb)
for them. for them.
MARKDOWN MARKDOWN
......
...@@ -105,9 +105,9 @@ minimize the number of lines of code in `danger/`. A non-trivial `Dangerfile` ...@@ -105,9 +105,9 @@ minimize the number of lines of code in `danger/`. A non-trivial `Dangerfile`
should mostly call plugin code with arguments derived from the methods provided should mostly call plugin code with arguments derived from the methods provided
by Danger. The plugin code itself should have unit tests. by Danger. The plugin code itself should have unit tests.
At present, we do this by putting the code in a module in `lib/gitlab/danger/...`, At present, we do this by putting the code in a module in `tooling/danger/...`,
and including it in the matching `danger/plugins/...` file. Specs can then be and including it in the matching `danger/plugins/...` file. Specs can then be
added in `spec/lib/gitlab/danger/...`. added in `spec/tooling/danger/...`.
To determine if your `Dangerfile` works, push the branch that contains it to To determine if your `Dangerfile` works, push the branch that contains it to
GitLab. This can be quite frustrating, as it significantly increases the cycle GitLab. This can be quite frustrating, as it significantly increases the cycle
......
desc 'Run local Danger rules' desc 'Run local Danger rules'
task :danger_local do task :danger_local do
require 'gitlab_danger' require_relative '../../tooling/gitlab_danger'
require 'gitlab/popen' require 'gitlab/popen'
puts("#{GitlabDanger.local_warning_message}\n") puts("#{GitlabDanger.local_warning_message}\n")
......
# frozen_string_literal: true # frozen_string_literal: true
require 'fast_spec_helper'
require 'rspec-parameterized' require 'rspec-parameterized'
require_relative 'danger_spec_helper' require_relative 'danger_spec_helper'
require 'gitlab/danger/base_linter' require_relative '../../../tooling/danger/base_linter'
RSpec.describe Gitlab::Danger::BaseLinter do RSpec.describe Tooling::Danger::BaseLinter do
let(:commit_class) do let(:commit_class) do
Struct.new(:message, :sha, :diff_parent) Struct.new(:message, :sha, :diff_parent)
end end
......
# frozen_string_literal: true # frozen_string_literal: true
require 'fast_spec_helper'
require_relative 'danger_spec_helper' require_relative 'danger_spec_helper'
require 'gitlab/danger/changelog' require_relative '../../../tooling/danger/changelog'
RSpec.describe Gitlab::Danger::Changelog do RSpec.describe Tooling::Danger::Changelog do
include DangerSpecHelper include DangerSpecHelper
let(:added_files) { nil } let(:added_files) { nil }
...@@ -53,8 +52,8 @@ RSpec.describe Gitlab::Danger::Changelog do ...@@ -53,8 +52,8 @@ RSpec.describe Gitlab::Danger::Changelog do
describe '#optional?' do describe '#optional?' do
let(:category_with_changelog) { :backend } let(:category_with_changelog) { :backend }
let(:label_with_changelog) { 'frontend' } let(:label_with_changelog) { 'frontend' }
let(:category_without_changelog) { Gitlab::Danger::Changelog::NO_CHANGELOG_CATEGORIES.first } let(:category_without_changelog) { Tooling::Danger::Changelog::NO_CHANGELOG_CATEGORIES.first }
let(:label_without_changelog) { Gitlab::Danger::Changelog::NO_CHANGELOG_LABELS.first } let(:label_without_changelog) { Tooling::Danger::Changelog::NO_CHANGELOG_LABELS.first }
subject { changelog.optional? } subject { changelog.optional? }
......
# frozen_string_literal: true # frozen_string_literal: true
require 'fast_spec_helper'
require 'rspec-parameterized' require 'rspec-parameterized'
require_relative 'danger_spec_helper' require_relative 'danger_spec_helper'
require 'gitlab/danger/commit_linter' require_relative '../../../tooling/danger/commit_linter'
RSpec.describe Gitlab::Danger::CommitLinter do RSpec.describe Tooling::Danger::CommitLinter do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
let(:total_files_changed) { 2 } let(:total_files_changed) { 2 }
......
# frozen_string_literal: true # frozen_string_literal: true
require 'fast_spec_helper'
require 'rspec-parameterized' require 'rspec-parameterized'
require 'gitlab/danger/emoji_checker' require_relative '../../../tooling/danger/emoji_checker'
RSpec.describe Gitlab::Danger::EmojiChecker do RSpec.describe Tooling::Danger::EmojiChecker do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
describe '#includes_text_emoji?' do describe '#includes_text_emoji?' do
......
...@@ -4,9 +4,9 @@ require 'fast_spec_helper' ...@@ -4,9 +4,9 @@ require 'fast_spec_helper'
require 'rspec-parameterized' require 'rspec-parameterized'
require_relative 'danger_spec_helper' require_relative 'danger_spec_helper'
require 'gitlab/danger/helper' require_relative '../../../tooling/danger/helper'
RSpec.describe Gitlab::Danger::Helper do RSpec.describe Tooling::Danger::Helper do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
include DangerSpecHelper include DangerSpecHelper
...@@ -37,7 +37,7 @@ RSpec.describe Gitlab::Danger::Helper do ...@@ -37,7 +37,7 @@ RSpec.describe Gitlab::Danger::Helper do
context 'when danger gitlab plugin is not available' do context 'when danger gitlab plugin is not available' do
it 'returns nil' do it 'returns nil' do
invalid_danger = Class.new do invalid_danger = Class.new do
include Gitlab::Danger::Helper include Tooling::Danger::Helper
end.new end.new
expect(invalid_danger.gitlab_helper).to be_nil expect(invalid_danger.gitlab_helper).to be_nil
...@@ -289,8 +289,8 @@ RSpec.describe Gitlab::Danger::Helper do ...@@ -289,8 +289,8 @@ RSpec.describe Gitlab::Danger::Helper do
'.gitlab/ci/cng.gitlab-ci.yml' | [:engineering_productivity] '.gitlab/ci/cng.gitlab-ci.yml' | [:engineering_productivity]
'.gitlab/ci/ee-specific-checks.gitlab-ci.yml' | [:engineering_productivity] '.gitlab/ci/ee-specific-checks.gitlab-ci.yml' | [:engineering_productivity]
'scripts/foo' | [:engineering_productivity] 'scripts/foo' | [:engineering_productivity]
'lib/gitlab/danger/foo' | [:engineering_productivity] 'tooling/danger/foo' | [:engineering_productivity]
'ee/lib/gitlab/danger/foo' | [:engineering_productivity] 'ee/tooling/danger/foo' | [:engineering_productivity]
'lefthook.yml' | [:engineering_productivity] 'lefthook.yml' | [:engineering_productivity]
'.editorconfig' | [:engineering_productivity] '.editorconfig' | [:engineering_productivity]
'tooling/bin/find_foss_tests' | [:engineering_productivity] 'tooling/bin/find_foss_tests' | [:engineering_productivity]
......
# frozen_string_literal: true # frozen_string_literal: true
require 'fast_spec_helper'
require 'rspec-parameterized' require 'rspec-parameterized'
require_relative 'danger_spec_helper' require_relative 'danger_spec_helper'
require 'gitlab/danger/merge_request_linter' require_relative '../../../tooling/danger/merge_request_linter'
RSpec.describe Gitlab::Danger::MergeRequestLinter do RSpec.describe Tooling::Danger::MergeRequestLinter do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
let(:mr_class) do let(:mr_class) do
......
...@@ -3,10 +3,10 @@ ...@@ -3,10 +3,10 @@
require 'webmock/rspec' require 'webmock/rspec'
require 'timecop' require 'timecop'
require 'gitlab/danger/roulette' require_relative '../../../tooling/danger/roulette'
require 'active_support/testing/time_helpers' require 'active_support/testing/time_helpers'
RSpec.describe Gitlab::Danger::Roulette do RSpec.describe Tooling::Danger::Roulette do
include ActiveSupport::Testing::TimeHelpers include ActiveSupport::Testing::TimeHelpers
around do |example| around do |example|
...@@ -16,7 +16,7 @@ RSpec.describe Gitlab::Danger::Roulette do ...@@ -16,7 +16,7 @@ RSpec.describe Gitlab::Danger::Roulette do
let(:backend_available) { true } let(:backend_available) { true }
let(:backend_tz_offset_hours) { 2.0 } let(:backend_tz_offset_hours) { 2.0 }
let(:backend_maintainer) do let(:backend_maintainer) do
Gitlab::Danger::Teammate.new( Tooling::Danger::Teammate.new(
'username' => 'backend-maintainer', 'username' => 'backend-maintainer',
'name' => 'Backend maintainer', 'name' => 'Backend maintainer',
'role' => 'Backend engineer', 'role' => 'Backend engineer',
...@@ -27,7 +27,7 @@ RSpec.describe Gitlab::Danger::Roulette do ...@@ -27,7 +27,7 @@ RSpec.describe Gitlab::Danger::Roulette do
end end
let(:frontend_reviewer) do let(:frontend_reviewer) do
Gitlab::Danger::Teammate.new( Tooling::Danger::Teammate.new(
'username' => 'frontend-reviewer', 'username' => 'frontend-reviewer',
'name' => 'Frontend reviewer', 'name' => 'Frontend reviewer',
'role' => 'Frontend engineer', 'role' => 'Frontend engineer',
...@@ -38,7 +38,7 @@ RSpec.describe Gitlab::Danger::Roulette do ...@@ -38,7 +38,7 @@ RSpec.describe Gitlab::Danger::Roulette do
end end
let(:frontend_maintainer) do let(:frontend_maintainer) do
Gitlab::Danger::Teammate.new( Tooling::Danger::Teammate.new(
'username' => 'frontend-maintainer', 'username' => 'frontend-maintainer',
'name' => 'Frontend maintainer', 'name' => 'Frontend maintainer',
'role' => 'Frontend engineer', 'role' => 'Frontend engineer',
...@@ -49,7 +49,7 @@ RSpec.describe Gitlab::Danger::Roulette do ...@@ -49,7 +49,7 @@ RSpec.describe Gitlab::Danger::Roulette do
end end
let(:software_engineer_in_test) do let(:software_engineer_in_test) do
Gitlab::Danger::Teammate.new( Tooling::Danger::Teammate.new(
'username' => 'software-engineer-in-test', 'username' => 'software-engineer-in-test',
'name' => 'Software Engineer in Test', 'name' => 'Software Engineer in Test',
'role' => 'Software Engineer in Test, Create:Source Code', 'role' => 'Software Engineer in Test, Create:Source Code',
...@@ -60,7 +60,7 @@ RSpec.describe Gitlab::Danger::Roulette do ...@@ -60,7 +60,7 @@ RSpec.describe Gitlab::Danger::Roulette do
end end
let(:engineering_productivity_reviewer) do let(:engineering_productivity_reviewer) do
Gitlab::Danger::Teammate.new( Tooling::Danger::Teammate.new(
'username' => 'eng-prod-reviewer', 'username' => 'eng-prod-reviewer',
'name' => 'EP engineer', 'name' => 'EP engineer',
'role' => 'Engineering Productivity', 'role' => 'Engineering Productivity',
...@@ -71,7 +71,7 @@ RSpec.describe Gitlab::Danger::Roulette do ...@@ -71,7 +71,7 @@ RSpec.describe Gitlab::Danger::Roulette do
end end
let(:ci_template_reviewer) do let(:ci_template_reviewer) do
Gitlab::Danger::Teammate.new( Tooling::Danger::Teammate.new(
'username' => 'ci-template-maintainer', 'username' => 'ci-template-maintainer',
'name' => 'CI Template engineer', 'name' => 'CI Template engineer',
'role' => '~"ci::templates"', 'role' => '~"ci::templates"',
...@@ -121,7 +121,7 @@ RSpec.describe Gitlab::Danger::Roulette do ...@@ -121,7 +121,7 @@ RSpec.describe Gitlab::Danger::Roulette do
let!(:project) { 'gitlab' } let!(:project) { 'gitlab' }
let!(:mr_source_branch) { 'a-branch' } let!(:mr_source_branch) { 'a-branch' }
let!(:mr_labels) { ['backend', 'devops::create'] } let!(:mr_labels) { ['backend', 'devops::create'] }
let!(:author) { Gitlab::Danger::Teammate.new('username' => 'johndoe') } let!(:author) { Tooling::Danger::Teammate.new('username' => 'johndoe') }
let(:timezone_experiment) { false } let(:timezone_experiment) { false }
let(:spins) do let(:spins) do
# Stub the request at the latest time so that we can modify the raw data, e.g. available fields. # Stub the request at the latest time so that we can modify the raw data, e.g. available fields.
...@@ -330,7 +330,7 @@ RSpec.describe Gitlab::Danger::Roulette do ...@@ -330,7 +330,7 @@ RSpec.describe Gitlab::Danger::Roulette do
describe '#spin_for_person' do describe '#spin_for_person' do
let(:person_tz_offset_hours) { 0.0 } let(:person_tz_offset_hours) { 0.0 }
let(:person1) do let(:person1) do
Gitlab::Danger::Teammate.new( Tooling::Danger::Teammate.new(
'username' => 'user1', 'username' => 'user1',
'available' => true, 'available' => true,
'tz_offset_hours' => person_tz_offset_hours 'tz_offset_hours' => person_tz_offset_hours
...@@ -338,21 +338,21 @@ RSpec.describe Gitlab::Danger::Roulette do ...@@ -338,21 +338,21 @@ RSpec.describe Gitlab::Danger::Roulette do
end end
let(:person2) do let(:person2) do
Gitlab::Danger::Teammate.new( Tooling::Danger::Teammate.new(
'username' => 'user2', 'username' => 'user2',
'available' => true, 'available' => true,
'tz_offset_hours' => person_tz_offset_hours) 'tz_offset_hours' => person_tz_offset_hours)
end end
let(:author) do let(:author) do
Gitlab::Danger::Teammate.new( Tooling::Danger::Teammate.new(
'username' => 'johndoe', 'username' => 'johndoe',
'available' => true, 'available' => true,
'tz_offset_hours' => 0.0) 'tz_offset_hours' => 0.0)
end end
let(:unavailable) do let(:unavailable) do
Gitlab::Danger::Teammate.new( Tooling::Danger::Teammate.new(
'username' => 'janedoe', 'username' => 'janedoe',
'available' => false, 'available' => false,
'tz_offset_hours' => 0.0) 'tz_offset_hours' => 0.0)
......
# frozen_string_literal: true # frozen_string_literal: true
require 'fast_spec_helper'
require 'rspec-parameterized' require 'rspec-parameterized'
require_relative 'danger_spec_helper' require_relative 'danger_spec_helper'
require 'gitlab/danger/sidekiq_queues' require_relative '../../../tooling/danger/sidekiq_queues'
RSpec.describe Gitlab::Danger::SidekiqQueues do RSpec.describe Tooling::Danger::SidekiqQueues do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
include DangerSpecHelper include DangerSpecHelper
......
# frozen_string_literal: true # frozen_string_literal: true
require 'timecop' require_relative '../../../tooling/danger/teammate'
require 'rspec-parameterized'
require 'gitlab/danger/teammate'
require 'active_support/testing/time_helpers' require 'active_support/testing/time_helpers'
RSpec.describe Gitlab::Danger::Teammate do RSpec.describe Tooling::Danger::Teammate do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
subject { described_class.new(options) } subject { described_class.new(options) }
......
# frozen_string_literal: true # frozen_string_literal: true
require 'fast_spec_helper'
require 'rspec-parameterized' require 'rspec-parameterized'
require 'gitlab/danger/title_linting' require_relative '../../../tooling/danger/title_linting'
RSpec.describe Gitlab::Danger::TitleLinting do RSpec.describe Tooling::Danger::TitleLinting do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
describe '#sanitize_mr_title' do describe '#sanitize_mr_title' do
......
# frozen_string_literal: true # frozen_string_literal: true
require 'gitlab/danger/weightage/maintainers' require_relative '../../../../tooling/danger/weightage/maintainers'
RSpec.describe Gitlab::Danger::Weightage::Maintainers do RSpec.describe Tooling::Danger::Weightage::Maintainers do
let(:multiplier) { Gitlab::Danger::Weightage::CAPACITY_MULTIPLIER } let(:multiplier) { Tooling::Danger::Weightage::CAPACITY_MULTIPLIER }
let(:regular_maintainer) { double('Teammate', reduced_capacity: false) } let(:regular_maintainer) { double('Teammate', reduced_capacity: false) }
let(:reduced_capacity_maintainer) { double('Teammate', reduced_capacity: true) } let(:reduced_capacity_maintainer) { double('Teammate', reduced_capacity: true) }
let(:maintainers) do let(:maintainers) do
...@@ -13,8 +13,8 @@ RSpec.describe Gitlab::Danger::Weightage::Maintainers do ...@@ -13,8 +13,8 @@ RSpec.describe Gitlab::Danger::Weightage::Maintainers do
] ]
end end
let(:maintainer_count) { Gitlab::Danger::Weightage::BASE_REVIEWER_WEIGHT * multiplier } let(:maintainer_count) { Tooling::Danger::Weightage::BASE_REVIEWER_WEIGHT * multiplier }
let(:reduced_capacity_maintainer_count) { Gitlab::Danger::Weightage::BASE_REVIEWER_WEIGHT } let(:reduced_capacity_maintainer_count) { Tooling::Danger::Weightage::BASE_REVIEWER_WEIGHT }
subject(:weighted_maintainers) { described_class.new(maintainers).execute } subject(:weighted_maintainers) { described_class.new(maintainers).execute }
......
# frozen_string_literal: true # frozen_string_literal: true
require 'gitlab/danger/weightage/reviewers' require_relative '../../../../tooling/danger/weightage/reviewers'
RSpec.describe Gitlab::Danger::Weightage::Reviewers do RSpec.describe Tooling::Danger::Weightage::Reviewers do
let(:multiplier) { Gitlab::Danger::Weightage::CAPACITY_MULTIPLIER } let(:multiplier) { Tooling::Danger::Weightage::CAPACITY_MULTIPLIER }
let(:regular_reviewer) { double('Teammate', hungry: false, reduced_capacity: false) } let(:regular_reviewer) { double('Teammate', hungry: false, reduced_capacity: false) }
let(:hungry_reviewer) { double('Teammate', hungry: true, reduced_capacity: false) } let(:hungry_reviewer) { double('Teammate', hungry: true, reduced_capacity: false) }
let(:reduced_capacity_reviewer) { double('Teammate', hungry: false, reduced_capacity: true) } let(:reduced_capacity_reviewer) { double('Teammate', hungry: false, reduced_capacity: true) }
...@@ -26,11 +26,11 @@ RSpec.describe Gitlab::Danger::Weightage::Reviewers do ...@@ -26,11 +26,11 @@ RSpec.describe Gitlab::Danger::Weightage::Reviewers do
] ]
end end
let(:hungry_reviewer_count) { Gitlab::Danger::Weightage::BASE_REVIEWER_WEIGHT * multiplier + described_class::DEFAULT_REVIEWER_WEIGHT } let(:hungry_reviewer_count) { Tooling::Danger::Weightage::BASE_REVIEWER_WEIGHT * multiplier + described_class::DEFAULT_REVIEWER_WEIGHT }
let(:hungry_traintainer_count) { described_class::TRAINTAINER_WEIGHT * multiplier + described_class::DEFAULT_REVIEWER_WEIGHT } let(:hungry_traintainer_count) { described_class::TRAINTAINER_WEIGHT * multiplier + described_class::DEFAULT_REVIEWER_WEIGHT }
let(:reviewer_count) { Gitlab::Danger::Weightage::BASE_REVIEWER_WEIGHT * multiplier } let(:reviewer_count) { Tooling::Danger::Weightage::BASE_REVIEWER_WEIGHT * multiplier }
let(:traintainer_count) { Gitlab::Danger::Weightage::BASE_REVIEWER_WEIGHT * described_class::TRAINTAINER_WEIGHT * multiplier } let(:traintainer_count) { Tooling::Danger::Weightage::BASE_REVIEWER_WEIGHT * described_class::TRAINTAINER_WEIGHT * multiplier }
let(:reduced_capacity_reviewer_count) { Gitlab::Danger::Weightage::BASE_REVIEWER_WEIGHT } let(:reduced_capacity_reviewer_count) { Tooling::Danger::Weightage::BASE_REVIEWER_WEIGHT }
let(:reduced_capacity_traintainer_count) { described_class::TRAINTAINER_WEIGHT } let(:reduced_capacity_traintainer_count) { described_class::TRAINTAINER_WEIGHT }
subject(:weighted_reviewers) { described_class.new(reviewers, traintainers).execute } subject(:weighted_reviewers) { described_class.new(reviewers, traintainers).execute }
......
# frozen_string_literal: true # frozen_string_literal: true
require 'fast_spec_helper' require_relative '../../tooling/gitlab_danger'
RSpec.describe GitlabDanger do RSpec.describe GitlabDanger do
let(:gitlab_danger_helper) { nil } let(:gitlab_danger_helper) { nil }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require_relative 'title_linting' require_relative 'title_linting'
module Gitlab module Tooling
module Danger module Danger
class BaseLinter class BaseLinter
MIN_SUBJECT_WORDS_COUNT = 3 MIN_SUBJECT_WORDS_COUNT = 3
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require_relative 'title_linting' require_relative 'title_linting'
module Gitlab module Tooling
module Danger module Danger
module Changelog module Changelog
NO_CHANGELOG_LABELS = [ NO_CHANGELOG_LABELS = [
......
# frozen_string_literal: true # frozen_string_literal: true
emoji_checker_path = File.expand_path('emoji_checker', __dir__) require_relative 'base_linter'
base_linter_path = File.expand_path('base_linter', __dir__) require_relative 'emoji_checker'
if defined?(Rails)
require_dependency(base_linter_path)
require_dependency(emoji_checker_path)
else
require_relative(base_linter_path)
require_relative(emoji_checker_path)
end
module Gitlab module Tooling
module Danger module Danger
class CommitLinter < BaseLinter class CommitLinter < BaseLinter
MAX_CHANGED_FILES_IN_COMMIT = 3 MAX_CHANGED_FILES_IN_COMMIT = 3
...@@ -151,7 +143,7 @@ module Gitlab ...@@ -151,7 +143,7 @@ module Gitlab
end end
def emoji_checker def emoji_checker
@emoji_checker ||= Gitlab::Danger::EmojiChecker.new @emoji_checker ||= Tooling::Danger::EmojiChecker.new
end end
end end
end end
......
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
require 'json' require 'json'
module Gitlab module Tooling
module Danger module Danger
class EmojiChecker class EmojiChecker
DIGESTS = File.expand_path('../../../fixtures/emojis/digests.json', __dir__) DIGESTS = File.expand_path('../../fixtures/emojis/digests.json', __dir__)
ALIASES = File.expand_path('../../../fixtures/emojis/aliases.json', __dir__) ALIASES = File.expand_path('../../fixtures/emojis/aliases.json', __dir__)
# A regex that indicates a piece of text _might_ include an Emoji. The regex # A regex that indicates a piece of text _might_ include an Emoji. The regex
# alone is not enough, as we'd match `:foo:bar:baz`. Instead, we use this # alone is not enough, as we'd match `:foo:bar:baz`. Instead, we use this
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require_relative 'teammate' require_relative 'teammate'
require_relative 'title_linting' require_relative 'title_linting'
module Gitlab module Tooling
module Danger module Danger
module Helper module Helper
RELEASE_TOOLS_BOT = 'gitlab-release-tools-bot' RELEASE_TOOLS_BOT = 'gitlab-release-tools-bot'
...@@ -171,7 +171,7 @@ module Gitlab ...@@ -171,7 +171,7 @@ module Gitlab
%r{\Alefthook.yml\z} => :engineering_productivity, %r{\Alefthook.yml\z} => :engineering_productivity,
%r{\A\.editorconfig\z} => :engineering_productivity, %r{\A\.editorconfig\z} => :engineering_productivity,
%r{Dangerfile\z} => :engineering_productivity, %r{Dangerfile\z} => :engineering_productivity,
%r{\A(ee/)?(danger/|lib/gitlab/danger/)} => :engineering_productivity, %r{\A(ee/)?(danger/|tooling/danger/)} => :engineering_productivity,
%r{\A(ee/)?scripts/} => :engineering_productivity, %r{\A(ee/)?scripts/} => :engineering_productivity,
%r{\Atooling/} => :engineering_productivity, %r{\Atooling/} => :engineering_productivity,
%r{(CODEOWNERS)} => :engineering_productivity, %r{(CODEOWNERS)} => :engineering_productivity,
...@@ -213,7 +213,7 @@ module Gitlab ...@@ -213,7 +213,7 @@ module Gitlab
}.freeze }.freeze
def new_teammates(usernames) def new_teammates(usernames)
usernames.map { |u| Gitlab::Danger::Teammate.new('username' => u) } usernames.map { |u| Tooling::Danger::Teammate.new('username' => u) }
end end
def draft_mr? def draft_mr?
......
# frozen_string_literal: true # frozen_string_literal: true
base_linter_path = File.expand_path('base_linter', __dir__) require_relative 'base_linter'
if defined?(Rails) module Tooling
require_dependency(base_linter_path)
else
require_relative(base_linter_path)
end
module Gitlab
module Danger module Danger
class MergeRequestLinter < BaseLinter class MergeRequestLinter < BaseLinter
alias_method :lint, :lint_subject alias_method :lint, :lint_subject
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require 'net/http' require 'net/http'
require 'json' require 'json'
module Gitlab module Tooling
module Danger module Danger
module RequestHelper module RequestHelper
HTTPError = Class.new(RuntimeError) HTTPError = Class.new(RuntimeError)
......
# frozen_string_literal: true # frozen_string_literal: true
require_relative 'teammate' require_relative 'teammate'
require_relative 'request_helper' unless defined?(Gitlab::Danger::RequestHelper) require_relative 'request_helper'
require_relative 'weightage/reviewers' require_relative 'weightage/reviewers'
require_relative 'weightage/maintainers' require_relative 'weightage/maintainers'
module Gitlab module Tooling
module Danger module Danger
module Roulette module Roulette
ROULETTE_DATA_URL = 'https://gitlab-org.gitlab.io/gitlab-roulette/roulette.json' ROULETTE_DATA_URL = 'https://gitlab-org.gitlab.io/gitlab-roulette/roulette.json'
...@@ -72,8 +72,8 @@ module Gitlab ...@@ -72,8 +72,8 @@ module Gitlab
def team def team
@team ||= @team ||=
begin begin
data = Gitlab::Danger::RequestHelper.http_get_json(ROULETTE_DATA_URL) data = Tooling::Danger::RequestHelper.http_get_json(ROULETTE_DATA_URL)
data.map { |hash| ::Gitlab::Danger::Teammate.new(hash) } data.map { |hash| ::Tooling::Danger::Teammate.new(hash) }
rescue JSON::ParserError rescue JSON::ParserError
raise "Failed to parse JSON response from #{ROULETTE_DATA_URL}" raise "Failed to parse JSON response from #{ROULETTE_DATA_URL}"
end end
......
# frozen_string_literal: true # frozen_string_literal: true
module Gitlab module Tooling
module Danger module Danger
module SidekiqQueues module SidekiqQueues
def changed_queue_files def changed_queue_files
......
# frozen_string_literal: true # frozen_string_literal: true
module Gitlab module Tooling
module Danger module Danger
class Teammate class Teammate
attr_reader :options, :username, :name, :role, :projects, :available, :hungry, :reduced_capacity, :tz_offset_hours attr_reader :options, :username, :name, :role, :projects, :available, :hungry, :reduced_capacity, :tz_offset_hours
......
# frozen_string_literal: true # frozen_string_literal: true
module Gitlab module Tooling
module Danger module Danger
module TitleLinting module TitleLinting
DRAFT_REGEX = /\A*#{Regexp.union(/(?i)(\[WIP\]\s*|WIP:\s*|WIP$)/, /(?i)(\[draft\]|\(draft\)|draft:|draft\s\-\s|draft$)/)}+\s*/i.freeze DRAFT_REGEX = /\A*#{Regexp.union(/(?i)(\[WIP\]\s*|WIP:\s*|WIP$)/, /(?i)(\[draft\]|\(draft\)|draft:|draft\s\-\s|draft$)/)}+\s*/i.freeze
......
# frozen_string_literal: true # frozen_string_literal: true
module Gitlab module Tooling
module Danger module Danger
module Weightage module Weightage
CAPACITY_MULTIPLIER = 2 # change this number to change what it means to be a reduced capacity reviewer 1/this number CAPACITY_MULTIPLIER = 2 # change this number to change what it means to be a reduced capacity reviewer 1/this number
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require_relative '../weightage' require_relative '../weightage'
module Gitlab module Tooling
module Danger module Danger
module Weightage module Weightage
class Maintainers class Maintainers
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require_relative '../weightage' require_relative '../weightage'
module Gitlab module Tooling
module Danger module Danger
module Weightage module Weightage
# Weights after (current multiplier of 2) # Weights after (current multiplier of 2)
......
# frozen_string_literal: true # frozen_string_literal: true
# rubocop:todo Gitlab/NamespacedClass
class GitlabDanger class GitlabDanger
LOCAL_RULES ||= %w[ LOCAL_RULES ||= %w[
changes_size changes_size
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment