Skip to content
代码片段 群组 项目
提交 65d5bc64 编辑于 作者: Dylan Griffith's avatar Dylan Griffith
浏览文件

Merge branch...

Merge branch '397074-add-the-correct-tags-to-the-issue-created-by-the-schema-validation-framework' into 'master'

Add the correct tags to the schema validation issue

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/115881



Merged-by: default avatarDylan Griffith <dyl.griffith@gmail.com>
Approved-by: default avatarGregory Havenga <11164960-ghavenga@users.noreply.gitlab.com>
Approved-by: default avatarLeonardo da Rosa <ldarosa@gitlab.com>
Approved-by: default avatarDylan Griffith <dyl.griffith@gmail.com>
Reviewed-by: default avatarAlex Ives <aives@gitlab.com>
Reviewed-by: default avatarLeonardo da Rosa <ldarosa@gitlab.com>
Co-authored-by: default avatardfrazao-gitlab <dfrazao@gitlab.com>
No related branches found
No related tags found
无相关合并请求
# frozen_string_literal: true
module Gitlab
module Database
class ConvertFeatureCategoryToGroupLabel
STAGES_URL = 'https://gitlab.com/gitlab-com/www-gitlab-com/-/raw/master/data/stages.yml'
def initialize(feature_category)
@feature_category = feature_category
end
def execute
feature_categories_map[feature_category]
end
private
attr_reader :feature_category
def stages
response = Gitlab::HTTP.get(STAGES_URL)
YAML.safe_load(response) if response.success?
end
def feature_categories_map
stages['stages'].each_with_object({}) do |(_, stage), result|
stage['groups'].each do |group_name, group|
group['categories'].each do |category|
result[category] = "group::#{group_name.sub('_', ' ')}"
end
end
end
end
end
end
end
......@@ -41,7 +41,7 @@ def params
title: issue_title,
description: description,
issue_type: 'issue',
labels: %w[database database-inconsistency-report]
labels: default_labels + group_labels
}
end
......@@ -84,6 +84,24 @@ def description
MSG
end
def group_labels
dictionary = YAML.safe_load(File.read(table_file_path))
dictionary['feature_categories'].to_a.filter_map do |feature_category|
Gitlab::Database::ConvertFeatureCategoryToGroupLabel.new(feature_category).execute
end
rescue Errno::ENOENT
[]
end
def default_labels
%w[database database-inconsistency-report type::maintenance severity::4]
end
def table_file_path
Rails.root.join(Gitlab::Database::GitlabSchema.dictionary_paths.first, "#{inconsistency.table_name}.yml")
end
def schema_inconsistency_model
Gitlab::Database::SchemaValidation::SchemaInconsistency
end
......
---
table_name: achievements
classes:
- Achievements::Achievement
feature_categories:
- feature_category_example
description: Achievements which can be created by namespaces to award them to users
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/105871
milestone: '15.7'
gitlab_schema: gitlab_main
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Database::ConvertFeatureCategoryToGroupLabel, feature_category: :database do
describe '#execute' do
subject(:group_label) { described_class.new(feature_category).execute }
let_it_be(:stages_fixture) do
{ stages: { manage: { groups: { database: { categories: ['database'] } } } } }
end
before do
stub_request(:get, 'https://gitlab.com/gitlab-com/www-gitlab-com/-/raw/master/data/stages.yml')
.to_return(status: 200, body: stages_fixture.to_json, headers: {})
end
context 'when the group label exists' do
let(:feature_category) { 'database' }
it 'returns a group label' do
expect(group_label).to eql 'group::database'
end
end
context 'when the group label does not exist' do
let(:feature_category) { 'non_existing_feature_category_test' }
it 'returns nil' do
expect(group_label).to be nil
end
end
end
end
......@@ -39,7 +39,12 @@
context 'when the issue creation fails' do
let(:issue_creation) { instance_double(Mutations::Issues::Create, resolve: { errors: 'error' }) }
let(:convert_object) do
instance_double('Gitlab::Database::ConvertFeatureCategoryToGroupLabel', execute: 'group_label')
end
before do
allow(Gitlab::Database::ConvertFeatureCategoryToGroupLabel).to receive(:new).and_return(convert_object)
allow(Mutations::Issues::Create).to receive(:new).and_return(issue_creation)
end
......@@ -51,7 +56,12 @@
end
context 'when a new inconsistency is found' do
let(:convert_object) do
instance_double('Gitlab::Database::ConvertFeatureCategoryToGroupLabel', execute: 'group_label')
end
before do
allow(Gitlab::Database::ConvertFeatureCategoryToGroupLabel).to receive(:new).and_return(convert_object)
project.add_developer(user)
end
......@@ -116,6 +126,15 @@
end
context 'when the GitLab is not open' do
let(:convert_object) do
instance_double('Gitlab::Database::ConvertFeatureCategoryToGroupLabel', execute: 'group_label')
end
before do
allow(Gitlab::Database::ConvertFeatureCategoryToGroupLabel).to receive(:new).and_return(convert_object)
project.add_developer(user)
end
it 'creates a new schema inconsistency record' do
allow(Gitlab).to receive(:com?).and_return(true)
schema_inconsistency.issue.update!(state_id: Issue.available_states[:closed])
......@@ -124,5 +143,47 @@
end
end
end
context 'when the dictionary file is not present' do
before do
allow(Gitlab::Database::GitlabSchema).to receive(:dictionary_paths).and_return(['dictionary_not_found_path/'])
project.add_developer(user)
end
it 'add the default labels' do
allow(Gitlab).to receive(:com?).and_return(true)
inconsistency = execute
labels = inconsistency.issue.labels.map(&:name)
expect(labels).to eq %w[database database-inconsistency-report type::maintenance severity::4]
end
end
context 'when dictionary feature_categories are available' do
let(:convert_object) do
instance_double('Gitlab::Database::ConvertFeatureCategoryToGroupLabel', execute: 'group_label')
end
before do
allow(Gitlab::Database::ConvertFeatureCategoryToGroupLabel).to receive(:new).and_return(convert_object)
allow(Gitlab::Database::GitlabSchema).to receive(:dictionary_paths).and_return(['spec/fixtures/'])
project.add_developer(user)
end
it 'add the default labels + group labels' do
allow(Gitlab).to receive(:com?).and_return(true)
inconsistency = execute
labels = inconsistency.issue.labels.map(&:name)
expect(labels).to eq %w[database database-inconsistency-report type::maintenance severity::4 group_label]
end
end
end
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册