2019-02-05 12:16:18 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'fast_spec_helper'
|
|
|
|
require 'rspec-parameterized'
|
2019-12-12 10:08:41 -05:00
|
|
|
require_relative 'danger_spec_helper'
|
2019-02-05 12:16:18 -05:00
|
|
|
|
|
|
|
require 'gitlab/danger/helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::Danger::Helper do
|
2019-02-05 12:16:18 -05:00
|
|
|
using RSpec::Parameterized::TableSyntax
|
2019-12-12 10:08:41 -05:00
|
|
|
include DangerSpecHelper
|
2019-02-05 12:16:18 -05:00
|
|
|
|
|
|
|
let(:fake_git) { double('fake-git') }
|
|
|
|
|
2019-09-06 07:21:53 -04:00
|
|
|
let(:mr_author) { nil }
|
|
|
|
let(:fake_gitlab) { double('fake-gitlab', mr_author: mr_author) }
|
|
|
|
|
2019-12-12 10:08:41 -05:00
|
|
|
let(:fake_danger) { new_fake_danger.include(described_class) }
|
|
|
|
|
|
|
|
subject(:helper) { fake_danger.new(git: fake_git, gitlab: fake_gitlab) }
|
2019-09-06 07:21:53 -04:00
|
|
|
|
|
|
|
describe '#gitlab_helper' do
|
|
|
|
context 'when gitlab helper is not available' do
|
|
|
|
let(:fake_gitlab) { nil }
|
|
|
|
|
|
|
|
it 'returns nil' do
|
|
|
|
expect(helper.gitlab_helper).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when gitlab helper is available' do
|
|
|
|
it 'returns the gitlab helper' do
|
|
|
|
expect(helper.gitlab_helper).to eq(fake_gitlab)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#release_automation?' do
|
|
|
|
context 'when gitlab helper is not available' do
|
|
|
|
it 'returns false' do
|
|
|
|
expect(helper.release_automation?).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when gitlab helper is available' do
|
|
|
|
context "but the MR author isn't the RELEASE_TOOLS_BOT" do
|
|
|
|
let(:mr_author) { 'johnmarston' }
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(helper.release_automation?).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and the MR author is the RELEASE_TOOLS_BOT' do
|
|
|
|
let(:mr_author) { described_class::RELEASE_TOOLS_BOT }
|
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
expect(helper.release_automation?).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-02-05 12:16:18 -05:00
|
|
|
|
|
|
|
describe '#all_changed_files' do
|
|
|
|
subject { helper.all_changed_files }
|
|
|
|
|
|
|
|
it 'interprets a list of changes from the danger git plugin' do
|
|
|
|
expect(fake_git).to receive(:added_files) { %w[a b c.old] }
|
|
|
|
expect(fake_git).to receive(:modified_files) { %w[d e] }
|
|
|
|
expect(fake_git)
|
|
|
|
.to receive(:renamed_files)
|
|
|
|
.at_least(:once)
|
|
|
|
.and_return([{ before: 'c.old', after: 'c.new' }])
|
|
|
|
|
|
|
|
is_expected.to contain_exactly('a', 'b', 'c.new', 'd', 'e')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-23 11:09:36 -04:00
|
|
|
describe '#all_ee_changes' do
|
|
|
|
subject { helper.all_ee_changes }
|
|
|
|
|
|
|
|
it 'returns all changed files starting with ee/' do
|
|
|
|
expect(helper).to receive(:all_changed_files).and_return(%w[fr/ee/beer.rb ee/wine.rb ee/lib/ido.rb ee.k])
|
|
|
|
|
|
|
|
is_expected.to match_array(%w[ee/wine.rb ee/lib/ido.rb])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-05 12:16:18 -05:00
|
|
|
describe '#ee?' do
|
|
|
|
subject { helper.ee? }
|
|
|
|
|
2019-09-20 23:06:07 -04:00
|
|
|
it 'returns true if CI_PROJECT_NAME if set to gitlab' do
|
|
|
|
stub_env('CI_PROJECT_NAME', 'gitlab')
|
2019-09-24 11:06:34 -04:00
|
|
|
expect(Dir).not_to receive(:exist?)
|
2019-02-05 12:16:18 -05:00
|
|
|
|
|
|
|
is_expected.to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'delegates to CHANGELOG-EE.md existence if CI_PROJECT_NAME is set to something else' do
|
|
|
|
stub_env('CI_PROJECT_NAME', 'something else')
|
2019-09-24 11:06:34 -04:00
|
|
|
expect(Dir).to receive(:exist?).with('../../ee') { true }
|
2019-02-05 12:16:18 -05:00
|
|
|
|
|
|
|
is_expected.to be_truthy
|
|
|
|
end
|
|
|
|
|
2019-09-24 11:06:34 -04:00
|
|
|
it 'returns true if ee exists' do
|
2019-02-05 12:16:18 -05:00
|
|
|
stub_env('CI_PROJECT_NAME', nil)
|
2019-09-24 11:06:34 -04:00
|
|
|
expect(Dir).to receive(:exist?).with('../../ee') { true }
|
2019-02-05 12:16:18 -05:00
|
|
|
|
|
|
|
is_expected.to be_truthy
|
|
|
|
end
|
|
|
|
|
2019-09-24 11:06:34 -04:00
|
|
|
it "returns false if ee doesn't exist" do
|
2019-02-05 12:16:18 -05:00
|
|
|
stub_env('CI_PROJECT_NAME', nil)
|
2019-09-24 11:06:34 -04:00
|
|
|
expect(Dir).to receive(:exist?).with('../../ee') { false }
|
2019-02-05 12:16:18 -05:00
|
|
|
|
|
|
|
is_expected.to be_falsy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#project_name' do
|
|
|
|
subject { helper.project_name }
|
|
|
|
|
2019-09-20 23:06:07 -04:00
|
|
|
it 'returns gitlab if ee? returns true' do
|
2019-02-05 12:16:18 -05:00
|
|
|
expect(helper).to receive(:ee?) { true }
|
|
|
|
|
2019-09-20 23:06:07 -04:00
|
|
|
is_expected.to eq('gitlab')
|
2019-02-05 12:16:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns gitlab-ce if ee? returns false' do
|
|
|
|
expect(helper).to receive(:ee?) { false }
|
|
|
|
|
2019-09-20 23:06:07 -04:00
|
|
|
is_expected.to eq('gitlab-foss')
|
2019-02-05 12:16:18 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-19 13:33:48 -04:00
|
|
|
describe '#markdown_list' do
|
|
|
|
it 'creates a markdown list of items' do
|
|
|
|
items = %w[a b]
|
|
|
|
|
|
|
|
expect(helper.markdown_list(items)).to eq("* `a`\n* `b`")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'wraps items in <details> when there are more than 10 items' do
|
|
|
|
items = ('a'..'k').to_a
|
|
|
|
|
|
|
|
expect(helper.markdown_list(items)).to match(%r{<details>[^<]+</details>})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-05 12:16:18 -05:00
|
|
|
describe '#changes_by_category' do
|
|
|
|
it 'categorizes changed files' do
|
2019-08-15 13:42:13 -04:00
|
|
|
expect(fake_git).to receive(:added_files) { %w[foo foo.md foo.rb foo.js db/migrate/foo lib/gitlab/database/foo.rb qa/foo ee/changelogs/foo.yml] }
|
2019-02-05 12:16:18 -05:00
|
|
|
allow(fake_git).to receive(:modified_files) { [] }
|
|
|
|
allow(fake_git).to receive(:renamed_files) { [] }
|
|
|
|
|
|
|
|
expect(helper.changes_by_category).to eq(
|
|
|
|
backend: %w[foo.rb],
|
2019-08-15 13:42:13 -04:00
|
|
|
database: %w[db/migrate/foo lib/gitlab/database/foo.rb],
|
2019-02-05 12:16:18 -05:00
|
|
|
frontend: %w[foo.js],
|
2019-04-30 06:38:46 -04:00
|
|
|
none: %w[ee/changelogs/foo.yml foo.md],
|
2019-02-05 12:16:18 -05:00
|
|
|
qa: %w[qa/foo],
|
|
|
|
unknown: %w[foo]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-02 11:09:08 -04:00
|
|
|
describe '#categories_for_file' do
|
2020-07-16 08:09:22 -04:00
|
|
|
before do
|
|
|
|
allow(fake_git).to receive(:diff_for_file).with('usage_data.rb') { double(:diff, patch: "+ count(User.active)") }
|
|
|
|
end
|
|
|
|
|
2020-07-02 11:09:08 -04:00
|
|
|
where(:path, :expected_categories) do
|
2020-07-16 08:09:22 -04:00
|
|
|
'usage_data.rb' | [:database, :backend]
|
2020-07-13 08:09:18 -04:00
|
|
|
'doc/foo.md' | [:docs]
|
2020-07-07 05:08:57 -04:00
|
|
|
'CONTRIBUTING.md' | [:docs]
|
|
|
|
'LICENSE' | [:docs]
|
|
|
|
'MAINTENANCE.md' | [:docs]
|
|
|
|
'PHILOSOPHY.md' | [:docs]
|
|
|
|
'PROCESS.md' | [:docs]
|
|
|
|
'README.md' | [:docs]
|
2020-07-02 11:09:08 -04:00
|
|
|
|
|
|
|
'ee/doc/foo' | [:unknown]
|
|
|
|
'ee/README' | [:unknown]
|
|
|
|
|
|
|
|
'app/assets/foo' | [:frontend]
|
|
|
|
'app/views/foo' | [:frontend]
|
|
|
|
'public/foo' | [:frontend]
|
|
|
|
'scripts/frontend/foo' | [:frontend]
|
|
|
|
'spec/javascripts/foo' | [:frontend]
|
|
|
|
'spec/frontend/bar' | [:frontend]
|
|
|
|
'vendor/assets/foo' | [:frontend]
|
|
|
|
'babel.config.js' | [:frontend]
|
|
|
|
'jest.config.js' | [:frontend]
|
|
|
|
'package.json' | [:frontend]
|
|
|
|
'yarn.lock' | [:frontend]
|
|
|
|
'config/foo.js' | [:frontend]
|
|
|
|
'config/deep/foo.js' | [:frontend]
|
|
|
|
|
|
|
|
'ee/app/assets/foo' | [:frontend]
|
|
|
|
'ee/app/views/foo' | [:frontend]
|
|
|
|
'ee/spec/javascripts/foo' | [:frontend]
|
|
|
|
'ee/spec/frontend/bar' | [:frontend]
|
|
|
|
|
|
|
|
'.gitlab/ci/frontend.gitlab-ci.yml' | %i[frontend engineering_productivity]
|
|
|
|
|
|
|
|
'app/models/foo' | [:backend]
|
|
|
|
'bin/foo' | [:backend]
|
|
|
|
'config/foo' | [:backend]
|
|
|
|
'lib/foo' | [:backend]
|
|
|
|
'rubocop/foo' | [:backend]
|
|
|
|
'spec/foo' | [:backend]
|
|
|
|
'spec/foo/bar' | [:backend]
|
|
|
|
|
|
|
|
'ee/app/foo' | [:backend]
|
|
|
|
'ee/bin/foo' | [:backend]
|
|
|
|
'ee/spec/foo' | [:backend]
|
|
|
|
'ee/spec/foo/bar' | [:backend]
|
|
|
|
|
|
|
|
'generator_templates/foo' | [:backend]
|
|
|
|
'vendor/languages.yml' | [:backend]
|
|
|
|
'vendor/licenses.csv' | [:backend]
|
|
|
|
'file_hooks/examples/' | [:backend]
|
|
|
|
|
|
|
|
'Gemfile' | [:backend]
|
|
|
|
'Gemfile.lock' | [:backend]
|
|
|
|
'Rakefile' | [:backend]
|
|
|
|
'FOO_VERSION' | [:backend]
|
|
|
|
|
|
|
|
'Dangerfile' | [:engineering_productivity]
|
|
|
|
'danger/commit_messages/Dangerfile' | [:engineering_productivity]
|
|
|
|
'ee/danger/commit_messages/Dangerfile' | [:engineering_productivity]
|
|
|
|
'danger/commit_messages/' | [:engineering_productivity]
|
|
|
|
'ee/danger/commit_messages/' | [:engineering_productivity]
|
|
|
|
'.gitlab-ci.yml' | [:engineering_productivity]
|
|
|
|
'.gitlab/ci/cng.gitlab-ci.yml' | [:engineering_productivity]
|
|
|
|
'.gitlab/ci/ee-specific-checks.gitlab-ci.yml' | [:engineering_productivity]
|
|
|
|
'scripts/foo' | [:engineering_productivity]
|
|
|
|
'lib/gitlab/danger/foo' | [:engineering_productivity]
|
|
|
|
'ee/lib/gitlab/danger/foo' | [:engineering_productivity]
|
|
|
|
'.overcommit.yml.example' | [:engineering_productivity]
|
|
|
|
'.editorconfig' | [:engineering_productivity]
|
|
|
|
'tooling/overcommit/foo' | [:engineering_productivity]
|
|
|
|
'.codeclimate.yml' | [:engineering_productivity]
|
2020-07-22 11:09:28 -04:00
|
|
|
'.gitlab/CODEOWNERS' | [:engineering_productivity]
|
2020-07-02 11:09:08 -04:00
|
|
|
|
|
|
|
'lib/gitlab/ci/templates/Security/SAST.gitlab-ci.yml' | [:backend]
|
|
|
|
|
|
|
|
'ee/FOO_VERSION' | [:unknown]
|
|
|
|
|
|
|
|
'db/schema.rb' | [:database]
|
|
|
|
'db/structure.sql' | [:database]
|
|
|
|
'db/migrate/foo' | [:database]
|
|
|
|
'db/post_migrate/foo' | [:database]
|
|
|
|
'ee/db/migrate/foo' | [:database]
|
|
|
|
'ee/db/post_migrate/foo' | [:database]
|
|
|
|
'ee/db/geo/migrate/foo' | [:database]
|
|
|
|
'ee/db/geo/post_migrate/foo' | [:database]
|
|
|
|
'app/models/project_authorization.rb' | [:database]
|
|
|
|
'app/services/users/refresh_authorized_projects_service.rb' | [:database]
|
|
|
|
'lib/gitlab/background_migration.rb' | [:database]
|
|
|
|
'lib/gitlab/background_migration/foo' | [:database]
|
|
|
|
'ee/lib/gitlab/background_migration/foo' | [:database]
|
|
|
|
'lib/gitlab/database.rb' | [:database]
|
|
|
|
'lib/gitlab/database/foo' | [:database]
|
|
|
|
'ee/lib/gitlab/database/foo' | [:database]
|
|
|
|
'lib/gitlab/github_import.rb' | [:database]
|
|
|
|
'lib/gitlab/github_import/foo' | [:database]
|
|
|
|
'lib/gitlab/sql/foo' | [:database]
|
|
|
|
'rubocop/cop/migration/foo' | [:database]
|
|
|
|
|
|
|
|
'db/fixtures/foo.rb' | [:backend]
|
|
|
|
'ee/db/fixtures/foo.rb' | [:backend]
|
|
|
|
|
|
|
|
'qa/foo' | [:qa]
|
|
|
|
'ee/qa/foo' | [:qa]
|
|
|
|
|
|
|
|
'changelogs/foo' | [:none]
|
|
|
|
'ee/changelogs/foo' | [:none]
|
|
|
|
'locale/gitlab.pot' | [:none]
|
|
|
|
|
|
|
|
'FOO' | [:unknown]
|
|
|
|
'foo' | [:unknown]
|
|
|
|
|
|
|
|
'foo/bar.rb' | [:backend]
|
|
|
|
'foo/bar.js' | [:frontend]
|
|
|
|
'foo/bar.txt' | [:none]
|
|
|
|
'foo/bar.md' | [:none]
|
2019-02-05 12:16:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
2020-07-02 11:09:08 -04:00
|
|
|
subject { helper.categories_for_file(path) }
|
2019-02-05 12:16:18 -05:00
|
|
|
|
2020-07-02 11:09:08 -04:00
|
|
|
it { is_expected.to eq(expected_categories) }
|
2019-02-05 12:16:18 -05:00
|
|
|
end
|
2020-07-16 08:09:22 -04:00
|
|
|
|
|
|
|
context 'having specific changes' do
|
|
|
|
it 'has database and backend categories' do
|
2020-07-20 11:09:10 -04:00
|
|
|
changed_files = ['usage_data.rb', 'lib/gitlab/usage_data.rb', 'ee/lib/ee/gitlab/usage_data.rb']
|
2020-07-16 08:09:22 -04:00
|
|
|
|
2020-07-20 11:09:10 -04:00
|
|
|
changed_files.each do |file|
|
|
|
|
allow(fake_git).to receive(:diff_for_file).with(file) { double(:diff, patch: "+ count(User.active)") }
|
|
|
|
|
|
|
|
expect(helper.categories_for_file(file)).to eq([:database, :backend])
|
|
|
|
end
|
2020-07-16 08:09:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has backend category' do
|
|
|
|
allow(fake_git).to receive(:diff_for_file).with('usage_data.rb') { double(:diff, patch: "+ alt_usage_data(User.active)") }
|
|
|
|
|
|
|
|
expect(helper.categories_for_file('usage_data.rb')).to eq([:backend])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has backend category for changes outside usage_data files' do
|
|
|
|
allow(fake_git).to receive(:diff_for_file).with('user.rb') { double(:diff, patch: "+ count(User.active)") }
|
|
|
|
|
|
|
|
expect(helper.categories_for_file('user.rb')).to eq([:backend])
|
|
|
|
end
|
2020-07-20 11:09:10 -04:00
|
|
|
|
|
|
|
it 'has backend category for files that are not usage_data.rb' do
|
|
|
|
changed_file = 'usage_data/topology.rb'
|
|
|
|
allow(fake_git).to receive(:diff_for_file).with(changed_file) { double(:diff, patch: "+ count(User.active)") }
|
|
|
|
|
|
|
|
expect(helper.categories_for_file(changed_file)).to eq([:backend])
|
|
|
|
end
|
2020-07-16 08:09:22 -04:00
|
|
|
end
|
2019-02-05 12:16:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#label_for_category' do
|
|
|
|
where(:category, :expected_label) do
|
|
|
|
:backend | '~backend'
|
|
|
|
:database | '~database'
|
2019-09-23 02:06:19 -04:00
|
|
|
:docs | '~documentation'
|
2019-02-05 12:16:18 -05:00
|
|
|
:foo | '~foo'
|
|
|
|
:frontend | '~frontend'
|
2019-02-14 11:45:53 -05:00
|
|
|
:none | ''
|
2019-02-05 12:16:18 -05:00
|
|
|
:qa | '~QA'
|
2020-07-02 11:09:08 -04:00
|
|
|
:engineering_productivity | '~"Engineering Productivity" for CI, Danger'
|
2019-02-05 12:16:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
subject { helper.label_for_category(category) }
|
|
|
|
|
|
|
|
it { is_expected.to eq(expected_label) }
|
|
|
|
end
|
|
|
|
end
|
2019-05-30 06:50:40 -04:00
|
|
|
|
|
|
|
describe '#new_teammates' do
|
|
|
|
it 'returns an array of Teammate' do
|
|
|
|
usernames = %w[filipa iamphil]
|
|
|
|
|
|
|
|
teammates = helper.new_teammates(usernames)
|
|
|
|
|
|
|
|
expect(teammates.map(&:username)).to eq(usernames)
|
|
|
|
end
|
|
|
|
end
|
2019-07-19 13:33:48 -04:00
|
|
|
|
|
|
|
describe '#missing_database_labels' do
|
|
|
|
subject { helper.missing_database_labels(current_mr_labels) }
|
|
|
|
|
|
|
|
context 'when current merge request has ~database::review pending' do
|
|
|
|
let(:current_mr_labels) { ['database::review pending', 'feature'] }
|
|
|
|
|
|
|
|
it { is_expected.to match_array(['database']) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when current merge request does not have ~database::review pending' do
|
|
|
|
let(:current_mr_labels) { ['feature'] }
|
|
|
|
|
|
|
|
it { is_expected.to match_array(['database', 'database::review pending']) }
|
|
|
|
end
|
|
|
|
end
|
2020-01-03 19:07:49 -05:00
|
|
|
|
2020-01-16 13:08:46 -05:00
|
|
|
describe '#sanitize_mr_title' do
|
|
|
|
where(:mr_title, :expected_mr_title) do
|
|
|
|
'My MR title' | 'My MR title'
|
|
|
|
'WIP: My MR title' | 'My MR title'
|
2020-07-16 11:09:38 -04:00
|
|
|
'Draft: My MR title' | 'My MR title'
|
|
|
|
'(Draft) My MR title' | 'My MR title'
|
|
|
|
'[Draft] My MR title' | 'My MR title'
|
|
|
|
'[DRAFT] My MR title' | 'My MR title'
|
|
|
|
'DRAFT: My MR title' | 'My MR title'
|
2020-01-16 13:08:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
subject { helper.sanitize_mr_title(mr_title) }
|
|
|
|
|
|
|
|
it { is_expected.to eq(expected_mr_title) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-03 19:07:49 -05:00
|
|
|
describe '#security_mr?' do
|
|
|
|
it 'returns false when `gitlab_helper` is unavailable' do
|
|
|
|
expect(helper).to receive(:gitlab_helper).and_return(nil)
|
|
|
|
|
|
|
|
expect(helper).not_to be_security_mr
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when on a normal merge request' do
|
|
|
|
expect(fake_gitlab).to receive(:mr_json)
|
2020-01-20 19:08:46 -05:00
|
|
|
.and_return('web_url' => 'https://gitlab.com/gitlab-org/gitlab/-/merge_requests/1')
|
2020-01-03 19:07:49 -05:00
|
|
|
|
|
|
|
expect(helper).not_to be_security_mr
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true when on a security merge request' do
|
|
|
|
expect(fake_gitlab).to receive(:mr_json)
|
2020-01-20 19:08:46 -05:00
|
|
|
.and_return('web_url' => 'https://gitlab.com/gitlab-org/security/gitlab/-/merge_requests/1')
|
2020-01-03 19:07:49 -05:00
|
|
|
|
|
|
|
expect(helper).to be_security_mr
|
|
|
|
end
|
|
|
|
end
|
2020-04-23 14:09:46 -04:00
|
|
|
|
2020-07-02 20:09:23 -04:00
|
|
|
describe '#cherry_pick_mr?' do
|
|
|
|
it 'returns false when `gitlab_helper` is unavailable' do
|
|
|
|
expect(helper).to receive(:gitlab_helper).and_return(nil)
|
|
|
|
|
|
|
|
expect(helper).not_to be_cherry_pick_mr
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when MR title does not mention a cherry-pick' do
|
|
|
|
it 'returns false' do
|
|
|
|
expect(fake_gitlab).to receive(:mr_json)
|
|
|
|
.and_return('title' => 'Add feature xyz')
|
|
|
|
|
|
|
|
expect(helper).not_to be_cherry_pick_mr
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when MR title mentions a cherry-pick' do
|
|
|
|
[
|
|
|
|
'Cherry Pick !1234',
|
|
|
|
'cherry-pick !1234',
|
|
|
|
'CherryPick !1234'
|
|
|
|
].each do |mr_title|
|
|
|
|
it 'returns true' do
|
|
|
|
expect(fake_gitlab).to receive(:mr_json)
|
|
|
|
.and_return('title' => mr_title)
|
|
|
|
|
|
|
|
expect(helper).to be_cherry_pick_mr
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#stable_branch?' do
|
|
|
|
it 'returns false when `gitlab_helper` is unavailable' do
|
|
|
|
expect(helper).to receive(:gitlab_helper).and_return(nil)
|
|
|
|
|
|
|
|
expect(helper).not_to be_stable_branch
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when MR target branch is not a stable branch' do
|
|
|
|
it 'returns false' do
|
|
|
|
expect(fake_gitlab).to receive(:mr_json)
|
|
|
|
.and_return('target_branch' => 'my-feature-branch')
|
|
|
|
|
|
|
|
expect(helper).not_to be_stable_branch
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when MR target branch is a stable branch' do
|
|
|
|
%w[
|
|
|
|
13-1-stable-ee
|
|
|
|
13-1-stable-ee-patch-1
|
|
|
|
].each do |target_branch|
|
|
|
|
it 'returns true' do
|
|
|
|
expect(fake_gitlab).to receive(:mr_json)
|
|
|
|
.and_return('target_branch' => target_branch)
|
|
|
|
|
|
|
|
expect(helper).to be_stable_branch
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-23 14:09:46 -04:00
|
|
|
describe '#mr_has_label?' do
|
|
|
|
it 'returns false when `gitlab_helper` is unavailable' do
|
|
|
|
expect(helper).to receive(:gitlab_helper).and_return(nil)
|
|
|
|
|
|
|
|
expect(helper.mr_has_labels?('telemetry')).to be_falsey
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when mr has labels' do
|
|
|
|
before do
|
|
|
|
mr_labels = ['telemetry', 'telemetry::reviewed']
|
|
|
|
expect(fake_gitlab).to receive(:mr_labels).and_return(mr_labels)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true with a matched label' do
|
|
|
|
expect(helper.mr_has_labels?('telemetry')).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false with unmatched label' do
|
|
|
|
expect(helper.mr_has_labels?('database')).to be_falsey
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true with an array of labels' do
|
|
|
|
expect(helper.mr_has_labels?(['telemetry', 'telemetry::reviewed'])).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true with multi arguments with matched labels' do
|
|
|
|
expect(helper.mr_has_labels?('telemetry', 'telemetry::reviewed')).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false with multi arguments with unmatched labels' do
|
|
|
|
expect(helper.mr_has_labels?('telemetry', 'telemetry::non existing')).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-28 14:09:35 -04:00
|
|
|
describe '#labels_list' do
|
|
|
|
let(:labels) { ['telemetry', 'telemetry::reviewed'] }
|
|
|
|
|
|
|
|
it 'composes the labels string' do
|
|
|
|
expect(helper.labels_list(labels)).to eq('~"telemetry", ~"telemetry::reviewed"')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when passing a separator' do
|
|
|
|
it 'composes the labels string with the given separator' do
|
|
|
|
expect(helper.labels_list(labels, sep: ' ')).to eq('~"telemetry" ~"telemetry::reviewed"')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns empty string for empty array' do
|
|
|
|
expect(helper.labels_list([])).to eq('')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-23 14:09:46 -04:00
|
|
|
describe '#prepare_labels_for_mr' do
|
|
|
|
it 'composes the labels string' do
|
|
|
|
mr_labels = ['telemetry', 'telemetry::reviewed']
|
2020-04-28 14:09:35 -04:00
|
|
|
|
2020-04-23 14:09:46 -04:00
|
|
|
expect(helper.prepare_labels_for_mr(mr_labels)).to eq('/label ~"telemetry" ~"telemetry::reviewed"')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns empty string for empty array' do
|
|
|
|
expect(helper.prepare_labels_for_mr([])).to eq('')
|
|
|
|
end
|
|
|
|
end
|
2019-02-05 12:16:18 -05:00
|
|
|
end
|