diff options
author | Paul Slaughter <pslaughter@gitlab.com> | 2018-09-26 08:28:50 +0000 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2018-09-26 08:28:50 +0000 |
commit | f3901842493c58faba71ad0812bf3102790a1b9f (patch) | |
tree | f30d0f4c67e80ec8fd591fa43b0b9b59998423c7 /app | |
parent | c7fcb01b8adf988e2e10e63979507d99bedba163 (diff) | |
download | gitlab-ce-f3901842493c58faba71ad0812bf3102790a1b9f.tar.gz |
Resolve "Commit details are not displayed when reviewing an MR commit by commit"
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/diffs/components/app.vue | 7 | ||||
-rw-r--r-- | app/assets/javascripts/diffs/components/commit_item.vue | 119 | ||||
-rw-r--r-- | app/assets/javascripts/diffs/components/commit_widget.vue | 40 | ||||
-rw-r--r-- | app/controllers/projects/merge_requests/diffs_controller.rb | 2 | ||||
-rw-r--r-- | app/serializers/commit_entity.rb | 17 | ||||
-rw-r--r-- | app/serializers/diffs_entity.rb | 7 | ||||
-rw-r--r-- | app/views/projects/commits/_commit.html.haml | 4 | ||||
-rw-r--r-- | app/views/projects/merge_requests/diffs/_commit_widget.html.haml | 4 |
8 files changed, 193 insertions, 7 deletions
diff --git a/app/assets/javascripts/diffs/components/app.vue b/app/assets/javascripts/diffs/components/app.vue index bfb992340bc..fc41ee4b777 100644 --- a/app/assets/javascripts/diffs/components/app.vue +++ b/app/assets/javascripts/diffs/components/app.vue @@ -9,6 +9,7 @@ import ChangedFiles from './changed_files.vue'; import DiffFile from './diff_file.vue'; import NoChanges from './no_changes.vue'; import HiddenFilesWarning from './hidden_files_warning.vue'; +import CommitWidget from './commit_widget.vue'; export default { name: 'DiffsApp', @@ -19,6 +20,7 @@ export default { DiffFile, NoChanges, HiddenFilesWarning, + CommitWidget, }, props: { endpoint: { @@ -208,6 +210,11 @@ export default { </div> </div> + <commit-widget + v-if="commit" + :commit="commit" + /> + <changed-files :diff-files="diffFiles" /> diff --git a/app/assets/javascripts/diffs/components/commit_item.vue b/app/assets/javascripts/diffs/components/commit_item.vue new file mode 100644 index 00000000000..5758588e82e --- /dev/null +++ b/app/assets/javascripts/diffs/components/commit_item.vue @@ -0,0 +1,119 @@ +<script> +import tooltip from '~/vue_shared/directives/tooltip'; +import UserAvatarLink from '~/vue_shared/components/user_avatar/user_avatar_link.vue'; +import Icon from '~/vue_shared/components/icon.vue'; +import ClipboardButton from '~/vue_shared/components/clipboard_button.vue'; +import CIIcon from '~/vue_shared/components/ci_icon.vue'; +import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue'; + +/** + * CommitItem + * + * ----------------------------------------------------------------- + * WARNING: Please keep changes up-to-date with the following files: + * - `views/projects/commits/_commit.html.haml` + * ----------------------------------------------------------------- + * + * This Component was cloned from a HAML view. For the time being they + * coexist, but there is an issue to remove the duplication. + * https://gitlab.com/gitlab-org/gitlab-ce/issues/51613 + * + */ +export default { + directives: { + tooltip, + }, + components: { + UserAvatarLink, + Icon, + ClipboardButton, + CIIcon, + TimeAgoTooltip, + }, + props: { + commit: { + type: Object, + required: true, + }, + }, + computed: { + authorName() { + return (this.commit.author && this.commit.author.name) || this.commit.authorName; + }, + authorUrl() { + return (this.commit.author && this.commit.author.webUrl) || `mailto:${this.commit.authorEmail}`; + }, + authorAvatar() { + return (this.commit.author && this.commit.author.avatarUrl) || this.commit.authorGravatarUrl; + }, + }, +}; +</script> + +<template> + <li class="commit flex-row js-toggle-container"> + <user-avatar-link + :link-href="authorUrl" + :img-src="authorAvatar" + :img-alt="authorName" + :img-size="36" + class="avatar-cell d-none d-sm-block" + /> + <div class="commit-detail flex-list"> + <div class="commit-content qa-commit-content"> + <a + :href="commit.commitUrl" + class="commit-row-message item-title" + v-html="commit.titleHtml" + ></a> + + <span class="commit-row-message d-block d-sm-none"> + · + {{ commit.shortId }} + </span> + + <button + v-if="commit.descriptionHtml" + class="text-expander js-toggle-button" + type="button" + :aria-label="__('Toggle commit description')" + > + <icon + :size="12" + name="ellipsis_h" + /> + </button> + + <div class="commiter"> + <a + :href="authorUrl" + v-text="authorName" + ></a> + {{ s__('CommitWidget|authored') }} + <time-ago-tooltip + :time="commit.authoredDate" + /> + </div> + + <pre + v-if="commit.descriptionHtml" + class="commit-row-description js-toggle-content append-bottom-8" + v-html="commit.descriptionHtml" + ></pre> + </div> + <div class="commit-actions flex-row d-none d-sm-flex"> + <div class="commit-sha-group"> + <div + class="label label-monospace" + v-text="commit.shortId" + ></div> + <clipboard-button + :text="commit.id" + :title="__('Copy commit SHA to clipboard')" + class="btn btn-default" + /> + </div> + </div> + </div> + </li> +</template> diff --git a/app/assets/javascripts/diffs/components/commit_widget.vue b/app/assets/javascripts/diffs/components/commit_widget.vue new file mode 100644 index 00000000000..cc8e72eb1c8 --- /dev/null +++ b/app/assets/javascripts/diffs/components/commit_widget.vue @@ -0,0 +1,40 @@ +<script> +import CommitItem from './commit_item.vue'; + +/** + * CommitWidget + * + * ----------------------------------------------------------------- + * WARNING: Please keep changes up-to-date with the following files: + * - `views/projects/merge_requests/diffs/_commit_widget.html.haml` + * ----------------------------------------------------------------- + * + * This Component was cloned from a HAML view. For the time being, + * they coexist, but there is an issue to remove the duplication. + * https://gitlab.com/gitlab-org/gitlab-ce/issues/51613 + * + */ +export default { + components: { + CommitItem, + }, + props: { + commit: { + type: Object, + required: true, + }, + }, +}; +</script> + +<template> + <div class="info-well prepend-top-default"> + <div class="well-segment"> + <ul class="blob-commit-info"> + <commit-item + :commit="commit" + /> + </ul> + </div> + </div> +</template> diff --git a/app/controllers/projects/merge_requests/diffs_controller.rb b/app/controllers/projects/merge_requests/diffs_controller.rb index 666e65b6c5e..3d9ade77467 100644 --- a/app/controllers/projects/merge_requests/diffs_controller.rb +++ b/app/controllers/projects/merge_requests/diffs_controller.rb @@ -23,7 +23,7 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic @diffs.write_cache - render json: DiffsSerializer.new(current_user: current_user).represent(@diffs, additional_attributes) + render json: DiffsSerializer.new(current_user: current_user, project: @merge_request.project).represent(@diffs, additional_attributes) end def define_diff_vars diff --git a/app/serializers/commit_entity.rb b/app/serializers/commit_entity.rb index ce76659fa46..396e95a03c8 100644 --- a/app/serializers/commit_entity.rb +++ b/app/serializers/commit_entity.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true class CommitEntity < API::Entities::Commit + include MarkupHelper include RequestAwareEntity expose :author, using: UserEntity @@ -9,11 +10,19 @@ class CommitEntity < API::Entities::Commit GravatarService.new.execute(commit.author_email) # rubocop: disable CodeReuse/ServiceClass end - expose :commit_url do |commit| - project_commit_url(request.project, commit) + expose :commit_url do |commit, options| + project_commit_url(request.project, commit, params: options.fetch(:commit_url_params, {})) end - expose :commit_path do |commit| - project_commit_path(request.project, commit) + expose :commit_path do |commit, options| + project_commit_path(request.project, commit, params: options.fetch(:commit_url_params, {})) + end + + expose :description_html, if: { type: :full } do |commit| + markdown_field(commit, :description) + end + + expose :title_html, if: { type: :full } do |commit| + markdown_field(commit, :title) end end diff --git a/app/serializers/diffs_entity.rb b/app/serializers/diffs_entity.rb index 878cc5290bd..00dc55fc004 100644 --- a/app/serializers/diffs_entity.rb +++ b/app/serializers/diffs_entity.rb @@ -15,8 +15,11 @@ class DiffsEntity < Grape::Entity merge_request&.target_branch end - expose :commit do |diffs| - options[:commit] + expose :commit do |diffs, options| + CommitEntity.represent options[:commit], options.merge( + type: :full, + commit_url_params: { merge_request_iid: merge_request&.iid } + ) end expose :merge_request_diff, using: MergeRequestDiffEntity do |diffs| diff --git a/app/views/projects/commits/_commit.html.haml b/app/views/projects/commits/_commit.html.haml index 45b4f03fa0c..c6789e32dbe 100644 --- a/app/views/projects/commits/_commit.html.haml +++ b/app/views/projects/commits/_commit.html.haml @@ -1,3 +1,7 @@ +-#----------------------------------------------------------------- + WARNING: Please keep changes up-to-date with the following files: + - `assets/javascripts/diffs/components/commit_item.vue` +-#----------------------------------------------------------------- - view_details = local_assigns.fetch(:view_details, false) - merge_request = local_assigns.fetch(:merge_request, nil) - project = local_assigns.fetch(:project) { merge_request&.project } diff --git a/app/views/projects/merge_requests/diffs/_commit_widget.html.haml b/app/views/projects/merge_requests/diffs/_commit_widget.html.haml index dab95b97346..066c8d5dba6 100644 --- a/app/views/projects/merge_requests/diffs/_commit_widget.html.haml +++ b/app/views/projects/merge_requests/diffs/_commit_widget.html.haml @@ -1,3 +1,7 @@ +-#----------------------------------------------------------------- + WARNING: Please keep changes up-to-date with the following files: + - `assets/javascripts/diffs/components/commit_widget.vue` +-#----------------------------------------------------------------- - if @commit .info-well.d-none.d-sm-block.prepend-top-default .well-segment |