Skip to content
代码片段 群组 项目
未验证 提交 9acaa09b 编辑于 作者: Thomas Hutterer's avatar Thomas Hutterer 提交者: GitLab
浏览文件

Add Danger warning about changed SettingBlock instances

Settings sections can be searched through the command palette.
But this only works if they are kept in sync with the files that drive
that search.
上级 43128550
No related branches found
No related tags found
无相关合并请求
# frozen_string_literal: true
require_relative '../../tooling/danger/settings_sections'
module Danger
class SettingsSections < ::Danger::Plugin
include Tooling::Danger::SettingsSections
end
end
# frozen_string_literal: true
settings_sections.check!
# frozen_string_literal: true # frozen_string_literal: true
module Search module Search
# Generates a list of all available setting sections of a group.
# This list is used by the command palette's search functionality.
class GroupSettings class GroupSettings
include Rails.application.routes.url_helpers include Rails.application.routes.url_helpers
......
# frozen_string_literal: true # frozen_string_literal: true
module Search module Search
# Generates a list of all available setting sections of a project.
# This list is used by the command palette's search functionality.
class ProjectSettings class ProjectSettings
include Rails.application.routes.url_helpers include Rails.application.routes.url_helpers
......
# frozen_string_literal: true
require 'gitlab/dangerfiles/spec_helper'
require 'fast_spec_helper'
require_relative '../../../tooling/danger/settings_sections'
RSpec.describe Tooling::Danger::SettingsSections, feature_category: :tooling do
include_context 'with dangerfile'
subject(:settings_section_check) { fake_danger.new(helper: fake_helper) }
let(:fake_danger) { DangerSpecHelper.fake_danger.include(described_class) }
let(:matching_changed_files) { ['app/views/foo/bar.html.haml', 'app/assets/js/foo/bar.vue'] }
let(:changed_lines) { ['-render SettingsBlockComponent.new(id: "foo") do', '<settings-block id="foo">'] }
let(:stable_branch?) { false }
before do
allow(fake_helper).to receive(:changed_files).and_return(matching_changed_files)
allow(fake_helper).to receive(:changed_lines).and_return(changed_lines)
allow(fake_helper).to receive(:stable_branch?).and_return(stable_branch?)
end
context 'when on stable branch' do
let(:stable_branch?) { true }
it 'does not write any markdown' do
expect(settings_section_check).not_to receive(:markdown)
settings_section_check.check!
end
end
context 'when none of the changed files are Haml or Vue files' do
let(:matching_changed_files) { [] }
it 'does not write any markdown' do
expect(settings_section_check).not_to receive(:markdown)
settings_section_check.check!
end
end
context 'when none of the changed lines match the pattern' do
let(:changed_lines) { ['-foo', '+bar'] }
it 'does not write any markdown' do
expect(settings_section_check).not_to receive(:markdown)
settings_section_check.check!
end
end
it 'adds a new markdown section listing every matching line' do
expect(settings_section_check).to receive(:markdown).with(/Searchable setting sections/)
expect(settings_section_check).to receive(:markdown).with(/SettingsBlock/)
expect(settings_section_check).to receive(:markdown).with(/settings-block/)
settings_section_check.check!
end
end
# frozen_string_literal: true
module Tooling
module Danger
module SettingsSections
def check!
return if helper.stable_branch?
changed_code_files = helper.changed_files(/\.(haml|vue)$/)
return if changed_code_files.empty?
vc_regexp = /(SettingsBlockComponent|settings-block)/
lines_with_matches = filter_changed_lines(changed_code_files, vc_regexp)
return if lines_with_matches.empty?
markdown(<<~MARKDOWN)
## Searchable setting sections
Looks like you have edited the template of some settings section. Please check that all changed sections are still searchable:
- If you created a new section, make sure to add it to either `lib/search/project_settings.rb` or `lib/search/group_settings.rb`, or in their counterparts in `ee/` if this section is only available behind a licensed feature.
- If you removed a section, make sure to also remove it from the files above.
- If you changed a section's id, please update it also in the files above.
- If you just moved code around within the same page, there is nothing to do.
MARKDOWN
lines_with_matches.each do |file, lines|
markdown(<<~MARKDOWN)
#### `#{file}`
```shell
#{lines.join("\n")}
```
MARKDOWN
end
end
def filter_changed_lines(files, pattern)
files_with_lines = {}
files.each do |file|
next if file.start_with?('spec/', 'ee/spec/', 'qa/')
matching_changed_lines = helper.changed_lines(file).select { |line| line =~ pattern }
next unless matching_changed_lines.any?
files_with_lines[file] = matching_changed_lines
end
files_with_lines
end
end
end
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册