Commit aa98caf9 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'ph/212669/commitTypeMarkdownHTML' into 'master'

Fixes emojis not rendering in the Vue file list

Closes #212669

See merge request gitlab-org/gitlab!31070
parents baa1521d 6bbe6848
......@@ -121,9 +121,8 @@ export default {
:href="commit.webUrl"
:class="{ 'font-italic': !commit.message }"
class="commit-row-message item-title"
>
{{ commit.title }}
</gl-link>
v-html="commit.titleHtml"
/>
<gl-deprecated-button
v-if="commit.description"
:class="{ open: showDescription }"
......
......@@ -167,9 +167,8 @@ export default {
:href="commit.commitPath"
:title="commit.message"
class="str-truncated-100 tree-commit-link"
>
{{ commit.message }}
</gl-link>
v-html="commit.titleHtml"
/>
<gl-skeleton-loading v-else :lines="1" class="h-auto" />
</td>
<td class="tree-time-ago text-right cursor-default">
......
fragment TreeEntryCommit on LogTreeCommit {
sha
message
titleHtml
committedDate
commitPath
fileName
......
......@@ -5,6 +5,7 @@ query pathLastCommit($projectPath: ID!, $path: String, $ref: String!) {
lastCommit {
sha
title
titleHtml
description
message
webUrl
......
......@@ -3,6 +3,7 @@ export function normalizeData(data, path, extra = () => {}) {
return data.map(d => ({
sha: d.commit.id,
message: d.commit.message,
titleHtml: d.commit_title_html,
committedDate: d.commit.committed_date,
commitPath: d.commit_path,
fileName: d.file_name,
......
......@@ -45,7 +45,8 @@ class Projects::RefsController < Projects::ApplicationController
def logs_tree
tree_summary = ::Gitlab::TreeSummary.new(
@commit, @project, path: @path, offset: params[:offset], limit: 25)
@commit, @project, current_user,
path: @path, offset: params[:offset], limit: 25)
respond_to do |format|
format.html { render_404 }
......@@ -60,10 +61,8 @@ class Projects::RefsController < Projects::ApplicationController
# Deprecated due to https://gitlab.com/gitlab-org/gitlab/-/issues/36863
# Will be removed soon https://gitlab.com/gitlab-org/gitlab/-/merge_requests/29895
format.js do
@logs, commits = tree_summary.summarize
@logs, _ = tree_summary.summarize
@more_log_url = more_url(tree_summary.next_offset) if tree_summary.more?
prerender_commit_full_titles!(commits)
end
end
end
......@@ -74,14 +73,6 @@ class Projects::RefsController < Projects::ApplicationController
logs_file_project_ref_path(@project, @ref, @path, offset: offset)
end
def prerender_commit_full_titles!(commits)
# Preload commit authors as they are used in rendering
commits.each(&:lazy_author)
renderer = Banzai::ObjectRenderer.new(user: current_user, default_project: @project)
renderer.render(commits, :full_title)
end
def validate_ref_id
return not_found! if params[:id].present? && params[:id] !~ Gitlab::PathRegex.git_reference_regex
end
......
......@@ -14,6 +14,7 @@ module Types
description: 'SHA1 ID of the commit'
field :title, type: GraphQL::STRING_TYPE, null: true, calls_gitaly: true,
description: 'Title of the commit message'
markdown_field :title_html, null: true
field :description, type: GraphQL::STRING_TYPE, null: true,
description: 'Description of the commit message'
field :message, type: GraphQL::STRING_TYPE, null: true,
......
---
title: Fixes commit message emojis not rendering in Vue file list
merge_request:
author:
type: fixed
......@@ -889,6 +889,11 @@ type Commit {
"""
title: String
"""
The GitLab Flavored Markdown rendering of `title`
"""
titleHtml: String
"""
Web URL of the commit
"""
......
......@@ -2378,6 +2378,20 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "titleHtml",
"description": "The GitLab Flavored Markdown rendering of `title`",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "webUrl",
"description": "Web URL of the commit",
......
......@@ -161,6 +161,7 @@ Autogenerated return type of BoardListUpdateLimitMetrics
| `sha` | String! | SHA1 ID of the commit |
| `signatureHtml` | String | Rendered HTML of the commit signature |
| `title` | String | Title of the commit message |
| `titleHtml` | String | The GitLab Flavored Markdown rendering of `title` |
| `webUrl` | String! | Web URL of the commit |
## CreateBranchPayload
......
fragment TreeEntryCommit on LogTreeCommit {
sha
message
titleHtml
committedDate
commitPath
fileName
......
......@@ -8,6 +8,7 @@ const mockData = [
committed_date: '2019-01-01',
},
commit_path: `https://test.com`,
commit_title_html: 'testing message',
file_name: 'index.js',
type: 'blob',
lock_label: 'Locked',
......@@ -26,6 +27,7 @@ describe('normalizeData', () => {
filePath: '/index.js',
type: 'blob',
lockLabel: 'Locked',
titleHtml: 'testing message',
__typename: 'LogTreeCommit',
},
]);
......@@ -45,6 +47,7 @@ describe('normalizeData', () => {
filePath: '/index.js',
type: 'blob',
lockLabel: false,
titleHtml: 'testing message',
__typename: 'LogTreeCommit',
},
]);
......
......@@ -5,10 +5,11 @@ require 'spec_helper'
describe Gitlab::TreeSummary do
let_it_be(:project) { create(:project, :custom_repo, files: { 'a.txt' => '' }) }
let_it_be(:path_lock) { create(:path_lock, project: project, path: 'a.txt') }
let_it_be(:user) { create(:user) }
let(:commit) { project.repository.head_commit }
subject { described_class.new(commit, project).summarize.first }
subject { described_class.new(commit, project, user).summarize.first }
describe '#summarize (entries)' do
it 'includes path locks in entries' do
......
......@@ -3,18 +3,20 @@
module Gitlab
class TreeSummary
include ::Gitlab::Utils::StrongMemoize
include ::MarkupHelper
CACHE_EXPIRE_IN = 1.hour
MAX_OFFSET = 2**31
attr_reader :commit, :project, :path, :offset, :limit
attr_reader :commit, :project, :path, :offset, :limit, :user
attr_reader :resolved_commits
private :resolved_commits
def initialize(commit, project, params = {})
def initialize(commit, project, user, params = {})
@commit = commit
@project = project
@user = user
@path = params.fetch(:path, nil).presence
@offset = [params.fetch(:offset, 0).to_i, MAX_OFFSET].min
......@@ -96,6 +98,7 @@ module Gitlab
end
commits_hsh = repository.list_last_commits_for_tree(commit.id, ensured_path, offset: offset, limit: limit)
prerender_commit_full_titles!(commits_hsh.values)
entries.each do |entry|
path_key = entry_path(entry)
......@@ -104,6 +107,7 @@ module Gitlab
if commit
entry[:commit] = commit
entry[:commit_path] = commit_path(commit)
entry[:commit_title_html] = markdown_field(commit, :full_title)
end
end
end
......@@ -131,6 +135,14 @@ module Gitlab
def tree
strong_memoize(:tree) { repository.tree(commit.id, path) }
end
def prerender_commit_full_titles!(commits)
# Preload commit authors as they are used in rendering
commits.each(&:lazy_author)
renderer = Banzai::ObjectRenderer.new(user: user, default_project: project)
renderer.render(commits, :full_title)
end
end
end
......
......@@ -171,6 +171,18 @@ describe "User browses files" do
end
end
context 'when commit message has markdown', :js do
before do
project.repository.create_file(user, 'index', 'test', message: ':star: testing', branch_name: 'master')
visit(project_tree_path(project, "master"))
end
it 'renders emojis' do
expect(page).to have_selector('gl-emoji', count: 2)
end
end
context "when browsing a `improve/awesome` branch", :js do
before do
visit(project_tree_path(project, "improve/awesome"))
......
......@@ -26,9 +26,7 @@ exports[`Repository last commit component renders commit widget 1`] = `
class="commit-row-message item-title"
href="https://test.com/commit/123"
>
Commit title
Commit title
</gl-link-stub>
<!---->
......@@ -128,9 +126,7 @@ exports[`Repository last commit component renders the signature HTML as returned
class="commit-row-message item-title"
href="https://test.com/commit/123"
>
Commit title
Commit title
</gl-link-stub>
<!---->
......
......@@ -9,6 +9,7 @@ function createCommitData(data = {}) {
const defaultData = {
sha: '123456789',
title: 'Commit title',
titleHtml: 'Commit title',
message: 'Commit message',
webUrl: 'https://test.com/commit/123',
authoredDate: '2019-01-01',
......
......@@ -8,6 +8,7 @@ const mockData = [
committed_date: '2019-01-01',
},
commit_path: `https://test.com`,
commit_title_html: 'testing message',
file_name: 'index.js',
type: 'blob',
},
......@@ -24,6 +25,7 @@ describe('normalizeData', () => {
fileName: 'index.js',
filePath: '/index.js',
type: 'blob',
titleHtml: 'testing message',
__typename: 'LogTreeCommit',
},
]);
......
......@@ -9,7 +9,7 @@ describe GitlabSchema.types['Commit'] do
it 'contains attributes related to commit' do
expect(described_class).to have_graphql_fields(
:id, :sha, :title, :description, :message, :authored_date,
:id, :sha, :title, :description, :message, :title_html, :authored_date,
:author_name, :author_gravatar, :author, :web_url, :latest_pipeline,
:pipelines, :signature_html
)
......
......@@ -8,12 +8,13 @@ describe Gitlab::TreeSummary do
let(:project) { create(:project, :empty_repo) }
let(:repo) { project.repository }
let(:commit) { repo.head_commit }
let_it_be(:user) { create(:user) }
let(:path) { nil }
let(:offset) { nil }
let(:limit) { nil }
subject(:summary) { described_class.new(commit, project, path: path, offset: offset, limit: limit) }
subject(:summary) { described_class.new(commit, project, user, path: path, offset: offset, limit: limit) }
describe '#initialize' do
it 'defaults offset to 0' do
......@@ -72,7 +73,8 @@ describe Gitlab::TreeSummary do
expected_commit_path = Gitlab::Routing.url_helpers.project_commit_path(project, commit)
expect(entry[:commit]).to be_a(::Commit)
expect(entry[:commit_path]).to eq expected_commit_path
expect(entry[:commit_path]).to eq(expected_commit_path)
expect(entry[:commit_title_html]).to eq(commit.message)
end
context 'in a good subdirectory' do
......@@ -140,6 +142,16 @@ describe Gitlab::TreeSummary do
expect(entry).to include(:commit)
end
end
context 'rendering commits' do
it 'does not perform N + 1 request' do
summary
queries = ActiveRecord::QueryRecorder.new { summary.summarize }
expect(queries.count).to be <= 3
end
end
end
describe '#more?' do
......
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