Support "Preview" tab also for commit commands

This commit is contained in:
Peter Leitzen 2018-07-28 23:43:21 +02:00
parent 9b95fe78ae
commit 9c6fc59c6c
2 changed files with 29 additions and 8 deletions

View File

@ -16,7 +16,7 @@ class PreviewMarkdownService < BaseService
private
def explain_quick_actions(text)
return text, [] unless %w(Issue MergeRequest).include?(commands_target_type)
return text, [] unless %w(Issue MergeRequest Commit).include?(commands_target_type)
quick_actions_service = QuickActions::InterpretService.new(project, current_user)
quick_actions_service.explain(text, find_commands_target)
@ -29,13 +29,9 @@ class PreviewMarkdownService < BaseService
end
def find_commands_target
if commands_target_id.present?
finder = commands_target_type == 'Issue' ? IssuesFinder : MergeRequestsFinder
finder.new(current_user, project_id: project.id).find(commands_target_id)
else
collection = commands_target_type == 'Issue' ? project.issues : project.merge_requests
collection.build
end
Projects::AutocompleteService
.new(project, current_user)
.target(commands_target_type, commands_target_id)
end
def commands_target_type

View File

@ -65,6 +65,31 @@ describe PreviewMarkdownService do
end
end
context 'commit description' do
let(:project) { create(:project, :repository) }
let(:commit) { project.commit }
let(:params) do
{
text: "My work\n/tag v1.2.3 Stable release",
quick_actions_target_type: 'Commit',
quick_actions_target_id: commit.id
}
end
let(:service) { described_class.new(project, user, params) }
it 'removes quick actions from text' do
result = service.execute
expect(result[:text]).to eq 'My work'
end
it 'explains quick actions effect' do
result = service.execute
expect(result[:commands]).to eq 'Tags this commit to v1.2.3 with "Stable release".'
end
end
it 'sets correct markdown engine' do
service = described_class.new(project, user, { markdown_version: CacheMarkdownField::CACHE_REDCARPET_VERSION })
result = service.execute