Commit 9c6fc59c authored by Peter Leitzen's avatar Peter Leitzen

Support "Preview" tab also for commit commands

parent 9b95fe78
......@@ -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
......
......@@ -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
......
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