diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/environments/components/environments_table.vue | 3 | ||||
-rw-r--r-- | app/assets/javascripts/snippet/snippet_embed.js | 27 | ||||
-rw-r--r-- | app/controllers/projects/merge_requests/diffs_controller.rb | 28 | ||||
-rw-r--r-- | app/helpers/snippets_helper.rb | 11 | ||||
-rw-r--r-- | app/models/commit.rb | 1 | ||||
-rw-r--r-- | app/models/compare.rb | 1 | ||||
-rw-r--r-- | app/models/concerns/acts_as_paginated_diff.rb | 11 | ||||
-rw-r--r-- | app/models/merge_request_diff.rb | 47 | ||||
-rw-r--r-- | app/views/projects/environments/empty_logs.html.haml | 14 | ||||
-rw-r--r-- | app/views/shared/snippets/_header.html.haml | 2 |
10 files changed, 98 insertions, 47 deletions
diff --git a/app/assets/javascripts/environments/components/environments_table.vue b/app/assets/javascripts/environments/components/environments_table.vue index b3022bdba36..453e7610e21 100644 --- a/app/assets/javascripts/environments/components/environments_table.vue +++ b/app/assets/javascripts/environments/components/environments_table.vue @@ -145,7 +145,8 @@ export default { :is-loading="model.isLoadingDeployBoard" :is-empty="model.isEmptyDeployBoard" :has-legacy-app-label="model.hasLegacyAppLabel" - :logs-path="model.logs_path" + :project-path="model.project_path" + :environment-name="model.name" /> </div> </div> diff --git a/app/assets/javascripts/snippet/snippet_embed.js b/app/assets/javascripts/snippet/snippet_embed.js index 6606271c4fa..65dd62f6af9 100644 --- a/app/assets/javascripts/snippet/snippet_embed.js +++ b/app/assets/javascripts/snippet/snippet_embed.js @@ -1,28 +1,35 @@ import { __ } from '~/locale'; +import { parseUrlPathname, parseUrl } from '../lib/utils/common_utils'; + +function swapActiveState(activateBtn, deactivateBtn) { + activateBtn.classList.add('is-active'); + deactivateBtn.classList.remove('is-active'); +} export default () => { const shareBtn = document.querySelector('.js-share-btn'); if (shareBtn) { - const { protocol, host, pathname } = window.location; - const embedBtn = document.querySelector('.js-embed-btn'); - const snippetUrlArea = document.querySelector('.js-snippet-url-area'); const embedAction = document.querySelector('.js-embed-action'); - const url = `${protocol}//${host + pathname}`; + const dataUrl = snippetUrlArea.getAttribute('data-url'); + + snippetUrlArea.addEventListener('click', () => snippetUrlArea.select()); shareBtn.addEventListener('click', () => { - shareBtn.classList.add('is-active'); - embedBtn.classList.remove('is-active'); - snippetUrlArea.value = url; + swapActiveState(shareBtn, embedBtn); + snippetUrlArea.value = dataUrl; embedAction.innerText = __('Share'); }); embedBtn.addEventListener('click', () => { - embedBtn.classList.add('is-active'); - shareBtn.classList.remove('is-active'); - const scriptTag = `<script src="${url}.js"></script>`; + const parser = parseUrl(dataUrl); + const url = `${parser.origin + parseUrlPathname(dataUrl)}`; + const params = parser.search; + const scriptTag = `<script src="${url}.js${params}"></script>`; + + swapActiveState(embedBtn, shareBtn); snippetUrlArea.value = scriptTag; embedAction.innerText = __('Embed'); }); diff --git a/app/controllers/projects/merge_requests/diffs_controller.rb b/app/controllers/projects/merge_requests/diffs_controller.rb index 5d458a229f2..37d90ecdc00 100644 --- a/app/controllers/projects/merge_requests/diffs_controller.rb +++ b/app/controllers/projects/merge_requests/diffs_controller.rb @@ -5,8 +5,8 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic include RendersNotes before_action :apply_diff_view_cookie! - before_action :commit, except: :diffs_batch - before_action :define_diff_vars, except: :diffs_batch + before_action :commit + before_action :define_diff_vars before_action :define_diff_comment_vars, except: [:diffs_batch, :diffs_metadata] def show @@ -20,11 +20,7 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic def diffs_batch return render_404 unless Feature.enabled?(:diffs_batch_load, @merge_request.project) - diffable = @merge_request.merge_request_diff - - return render_404 unless diffable - - diffs = diffable.diffs_in_batch(params[:page], params[:per_page], diff_options: diff_options) + diffs = @compare.diffs_in_batch(params[:page], params[:per_page], diff_options: diff_options) positions = @merge_request.note_positions_for_paths(diffs.diff_file_paths, current_user) diffs.unfold_diff_files(positions.unfoldable) @@ -40,8 +36,10 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic end def diffs_metadata + diffs = @compare.diffs(diff_options) + render json: DiffsMetadataSerializer.new(project: @merge_request.project) - .represent(@diffs, additional_attributes) + .represent(diffs, additional_attributes) end private @@ -50,11 +48,13 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic [{ source_project: :namespace }, { target_project: :namespace }] end + # Deprecated: https://gitlab.com/gitlab-org/gitlab/issues/37735 def render_diffs + diffs = @compare.diffs(diff_options) @environment = @merge_request.environments_for(current_user).last - @diffs.unfold_diff_files(note_positions.unfoldable) - @diffs.write_cache + diffs.unfold_diff_files(note_positions.unfoldable) + diffs.write_cache request = { current_user: current_user, @@ -64,15 +64,14 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic options = additional_attributes.merge(diff_view: diff_view) - render json: DiffsSerializer.new(request).represent(@diffs, options) + render json: DiffsSerializer.new(request).represent(diffs, options) end + # Deprecated: https://gitlab.com/gitlab-org/gitlab/issues/37735 def define_diff_vars @merge_request_diffs = @merge_request.merge_request_diffs.viewable.order_id_desc @compare = commit || find_merge_request_diff_compare return render_404 unless @compare - - @diffs = @compare.diffs(diff_options) end # rubocop: disable CodeReuse/ActiveRecord @@ -85,6 +84,8 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic # rubocop: enable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord + # + # Deprecated: https://gitlab.com/gitlab-org/gitlab/issues/37735 def find_merge_request_diff_compare @merge_request_diff = if diff_id = params[:diff_id].presence @@ -127,6 +128,7 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic } end + # Deprecated: https://gitlab.com/gitlab-org/gitlab/issues/37735 def define_diff_comment_vars @new_diff_note_attrs = { noteable_type: 'MergeRequest', diff --git a/app/helpers/snippets_helper.rb b/app/helpers/snippets_helper.rb index 7b93d44190e..1c7690f30d2 100644 --- a/app/helpers/snippets_helper.rb +++ b/app/helpers/snippets_helper.rb @@ -112,6 +112,17 @@ module SnippetsHelper content_tag(:script, nil, src: gitlab_snippet_url(snippet, format: :js)) end + def snippet_embed_input(snippet) + content_tag(:input, + nil, + type: :text, + readonly: true, + class: 'js-snippet-url-area snippet-embed-input form-control', + data: { url: gitlab_snippet_url(snippet) }, + value: snippet_embed_tag(snippet), + autocomplete: 'off') + end + def snippet_badge(snippet) return unless attrs = snippet_badge_attributes(snippet) diff --git a/app/models/commit.rb b/app/models/commit.rb index 01c7991ba2f..460725b2016 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -12,6 +12,7 @@ class Commit include StaticModel include Presentable include ::Gitlab::Utils::StrongMemoize + include ActsAsPaginatedDiff include CacheMarkdownField attr_mentionable :safe_message, pipeline: :single_line diff --git a/app/models/compare.rb b/app/models/compare.rb index f1ed84ab5a5..9b214171f07 100644 --- a/app/models/compare.rb +++ b/app/models/compare.rb @@ -4,6 +4,7 @@ require 'set' class Compare include Gitlab::Utils::StrongMemoize + include ActsAsPaginatedDiff delegate :same, :head, :base, to: :@compare diff --git a/app/models/concerns/acts_as_paginated_diff.rb b/app/models/concerns/acts_as_paginated_diff.rb new file mode 100644 index 00000000000..4ce2f99e63f --- /dev/null +++ b/app/models/concerns/acts_as_paginated_diff.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module ActsAsPaginatedDiff + # Comparisons going back to the repository will need proper batch + # loading (https://gitlab.com/gitlab-org/gitlab/issues/32859). + # For now, we're returning all the diffs available with + # no pagination data. + def diffs_in_batch(_batch_page, _batch_size, diff_options:) + diffs(diff_options) + end +end diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index b8a1575c180..71a344e69e3 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -309,20 +309,25 @@ class MergeRequestDiff < ApplicationRecord end def diffs_in_batch(batch_page, batch_size, diff_options:) - Gitlab::Diff::FileCollection::MergeRequestDiffBatch.new(self, - batch_page, - batch_size, - diff_options: diff_options) + fetching_repository_diffs(diff_options) do |comparison| + if comparison + comparison.diffs_in_batch(batch_page, batch_size, diff_options: diff_options) + else + diffs_in_batch_collection(batch_page, batch_size, diff_options: diff_options) + end + end end def diffs(diff_options = nil) - if without_files? && comparison = diff_refs&.compare_in(project) + fetching_repository_diffs(diff_options) do |comparison| # It should fetch the repository when diffs are cleaned by the system. # We don't keep these for storage overload purposes. # See https://gitlab.com/gitlab-org/gitlab-foss/issues/37639 - comparison.diffs(diff_options) - else - diffs_collection(diff_options) + if comparison + comparison.diffs(diff_options) + else + diffs_collection(diff_options) + end end end @@ -430,6 +435,13 @@ class MergeRequestDiff < ApplicationRecord private + def diffs_in_batch_collection(batch_page, batch_size, diff_options:) + Gitlab::Diff::FileCollection::MergeRequestDiffBatch.new(self, + batch_page, + batch_size, + diff_options: diff_options) + end + def encode_in_base64?(diff_text) (diff_text.encoding == Encoding::BINARY && !diff_text.ascii_only?) || diff_text.include?("\0") @@ -487,6 +499,25 @@ class MergeRequestDiff < ApplicationRecord end end + # Yields the block with the repository Compare object if it should + # fetch diffs from the repository instead DB. + def fetching_repository_diffs(diff_options) + return unless block_given? + + diff_options ||= {} + + # Can be read as: fetch the persisted diffs if yielded without the + # Compare object. + return yield unless without_files? || diff_options[:ignore_whitespace_change] + return yield unless diff_refs&.complete? + + comparison = diff_refs.compare_in(repository.project) + + return yield unless comparison + + yield(comparison) + end + def use_external_diff? return false unless has_attribute?(:external_diff) return false unless Gitlab.config.external_diffs.enabled diff --git a/app/views/projects/environments/empty_logs.html.haml b/app/views/projects/environments/empty_logs.html.haml deleted file mode 100644 index 602dc908b75..00000000000 --- a/app/views/projects/environments/empty_logs.html.haml +++ /dev/null @@ -1,14 +0,0 @@ -- page_title _('Pod logs') - -.row.empty-state - .col-sm-12 - .svg-content - = image_tag 'illustrations/operations_log_pods_empty.svg' - .col-12 - .text-content - %h4.text-center - = s_('Environments|No deployed environments') - %p.state-description.text-center - = s_('Logs|To see the pod logs, deploy your code to an environment.') - .text-center - = link_to s_('Environments|Learn about environments'), help_page_path('ci/environments'), class: 'btn btn-success' diff --git a/app/views/shared/snippets/_header.html.haml b/app/views/shared/snippets/_header.html.haml index 71ec62930d0..1243bdab6dd 100644 --- a/app/views/shared/snippets/_header.html.haml +++ b/app/views/shared/snippets/_header.html.haml @@ -44,7 +44,7 @@ %li %button.js-share-btn.btn.btn-transparent{ type: 'button' } %strong.embed-toggle-list-item= _("Share") - %input.js-snippet-url-area.snippet-embed-input.form-control{ type: "text", autocomplete: 'off', value: snippet_embed_tag(@snippet) } + = snippet_embed_input(@snippet) .input-group-append = clipboard_button(title: _('Copy'), class: 'js-clipboard-btn snippet-clipboard-btn btn btn-default', target: '.js-snippet-url-area') .clearfix |