diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-22 11:31:16 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-22 11:31:16 +0000 |
commit | 905c1110b08f93a19661cf42a276c7ea90d0a0ff (patch) | |
tree | 756d138db422392c00471ab06acdff92c5a9b69c /app/presenters | |
parent | 50d93f8d1686950fc58dda4823c4835fd0d8c14b (diff) | |
download | gitlab-ce-905c1110b08f93a19661cf42a276c7ea90d0a0ff.tar.gz |
Add latest changes from gitlab-org/gitlab@12-4-stable-ee
Diffstat (limited to 'app/presenters')
-rw-r--r-- | app/presenters/ci/build_runner_presenter.rb | 17 | ||||
-rw-r--r-- | app/presenters/ci/pipeline_presenter.rb | 58 | ||||
-rw-r--r-- | app/presenters/commit_presenter.rb | 19 | ||||
-rw-r--r-- | app/presenters/issue_presenter.rb | 4 | ||||
-rw-r--r-- | app/presenters/project_presenter.rb | 3 | ||||
-rw-r--r-- | app/presenters/projects/settings/deploy_keys_presenter.rb | 2 | ||||
-rw-r--r-- | app/presenters/todo_presenter.rb | 7 |
7 files changed, 95 insertions, 15 deletions
diff --git a/app/presenters/ci/build_runner_presenter.rb b/app/presenters/ci/build_runner_presenter.rb index 5231a8efa55..8e469795581 100644 --- a/app/presenters/ci/build_runner_presenter.rb +++ b/app/presenters/ci/build_runner_presenter.rb @@ -34,7 +34,8 @@ module Ci def refspecs specs = [] - specs << refspec_for_merge_request_ref if merge_request_ref? + specs << refspec_for_pipeline_ref if merge_request_ref? + specs << refspec_for_persistent_ref if persistent_ref_exist? if git_depth > 0 specs << refspec_for_branch(ref) if branch? || legacy_detached_merge_request_pipeline? @@ -86,10 +87,22 @@ module Ci "+#{Gitlab::Git::TAG_REF_PREFIX}#{ref}:#{RUNNER_REMOTE_TAG_PREFIX}#{ref}" end - def refspec_for_merge_request_ref + def refspec_for_pipeline_ref "+#{ref}:#{ref}" end + def refspec_for_persistent_ref + "+#{persistent_ref_path}:#{persistent_ref_path}" + end + + def persistent_ref_exist? + pipeline.persistent_ref.exist? + end + + def persistent_ref_path + pipeline.persistent_ref.path + end + def git_depth_variable strong_memoize(:git_depth_variable) do variables&.find { |variable| variable[:key] == 'GIT_DEPTH' } diff --git a/app/presenters/ci/pipeline_presenter.rb b/app/presenters/ci/pipeline_presenter.rb index 73a048dfa56..d81b1e6c522 100644 --- a/app/presenters/ci/pipeline_presenter.rb +++ b/app/presenters/ci/pipeline_presenter.rb @@ -48,15 +48,35 @@ module Ci def ref_text if pipeline.detached_merge_request_pipeline? - _("for %{link_to_merge_request} with %{link_to_merge_request_source_branch}").html_safe % { link_to_merge_request: link_to_merge_request, link_to_merge_request_source_branch: link_to_merge_request_source_branch } + _("for %{link_to_merge_request} with %{link_to_merge_request_source_branch}") + .html_safe % { + link_to_merge_request: link_to_merge_request, + link_to_merge_request_source_branch: link_to_merge_request_source_branch + } elsif pipeline.merge_request_pipeline? - _("for %{link_to_merge_request} with %{link_to_merge_request_source_branch} into %{link_to_merge_request_target_branch}").html_safe % { link_to_merge_request: link_to_merge_request, link_to_merge_request_source_branch: link_to_merge_request_source_branch, link_to_merge_request_target_branch: link_to_merge_request_target_branch } + _("for %{link_to_merge_request} with %{link_to_merge_request_source_branch} into %{link_to_merge_request_target_branch}") + .html_safe % { + link_to_merge_request: link_to_merge_request, + link_to_merge_request_source_branch: link_to_merge_request_source_branch, + link_to_merge_request_target_branch: link_to_merge_request_target_branch + } + elsif pipeline.ref && pipeline.ref_exists? + _("for %{link_to_pipeline_ref}") + .html_safe % { link_to_pipeline_ref: link_to_pipeline_ref } elsif pipeline.ref - if pipeline.ref_exists? - _("for %{link_to_pipeline_ref}").html_safe % { link_to_pipeline_ref: link_to_pipeline_ref } - else - _("for %{ref}").html_safe % { ref: content_tag(:span, pipeline.ref, class: 'ref-name') } - end + _("for %{ref}").html_safe % { ref: plain_ref_name } + end + end + + def all_related_merge_request_text + if all_related_merge_requests.none? + 'No related merge requests found.' + else + _("%{count} related %{pluralized_subject}: %{links}" % { + count: all_related_merge_requests.count, + pluralized_subject: 'merge request'.pluralize(all_related_merge_requests.count), + links: all_related_merge_request_links.join(', ') + }).html_safe end end @@ -84,10 +104,30 @@ module Ci private + def plain_ref_name + content_tag(:span, pipeline.ref, class: 'ref-name') + end + def merge_request_presenter - return unless pipeline.triggered_by_merge_request? + strong_memoize(:merge_request_presenter) do + if pipeline.triggered_by_merge_request? + pipeline.merge_request.present(current_user: current_user) + end + end + end - @merge_request_presenter ||= pipeline.merge_request.present(current_user: current_user) + def all_related_merge_request_links + all_related_merge_requests.map do |merge_request| + mr_path = project_merge_request_path(merge_request.project, merge_request) + + link_to "#{merge_request.to_reference} #{merge_request.title}", mr_path, class: 'mr-iid' + end + end + + def all_related_merge_requests + strong_memoize(:all_related_merge_requests) do + pipeline.ref ? pipeline.all_merge_requests_by_recency.to_a : [] + end end end end diff --git a/app/presenters/commit_presenter.rb b/app/presenters/commit_presenter.rb index fc9853733c1..94fc8ac8e39 100644 --- a/app/presenters/commit_presenter.rb +++ b/app/presenters/commit_presenter.rb @@ -6,14 +6,29 @@ class CommitPresenter < Gitlab::View::Presenter::Delegated presents :commit def status_for(ref) - can?(current_user, :read_commit_status, commit.project) && commit.status(ref) + return unless can?(current_user, :read_commit_status, commit.project) + + commit.latest_pipeline(ref)&.detailed_status(current_user) end def any_pipelines? - can?(current_user, :read_pipeline, commit.project) && commit.pipelines.any? + return false unless can?(current_user, :read_pipeline, commit.project) + + commit.pipelines.any? end def web_url Gitlab::UrlBuilder.new(commit).url end + + def signature_html + return unless commit.has_signature? + + ApplicationController.renderer.render( + 'projects/commit/_signature', + locals: { signature: commit.signature }, + layout: false, + formats: [:html] + ) + end end diff --git a/app/presenters/issue_presenter.rb b/app/presenters/issue_presenter.rb index c9dc0dbf443..3d55b00ac3b 100644 --- a/app/presenters/issue_presenter.rb +++ b/app/presenters/issue_presenter.rb @@ -11,6 +11,10 @@ class IssuePresenter < Gitlab::View::Presenter::Delegated url_builder.issue_path(issue) end + def subscribed? + issue.subscribed?(current_user, issue.project) + end + private def url_builder diff --git a/app/presenters/project_presenter.rb b/app/presenters/project_presenter.rb index 6c300cd8be1..6d370f6241c 100644 --- a/app/presenters/project_presenter.rb +++ b/app/presenters/project_presenter.rb @@ -51,7 +51,8 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated new_file_anchor_data, readme_anchor_data, changelog_anchor_data, - contribution_guide_anchor_data + contribution_guide_anchor_data, + gitlab_ci_anchor_data ].compact.reject { |item| item.is_link } end diff --git a/app/presenters/projects/settings/deploy_keys_presenter.rb b/app/presenters/projects/settings/deploy_keys_presenter.rb index 6f8c4e1f902..9bb7fe13593 100644 --- a/app/presenters/projects/settings/deploy_keys_presenter.rb +++ b/app/presenters/projects/settings/deploy_keys_presenter.rb @@ -40,7 +40,7 @@ module Projects def as_json serializer = DeployKeySerializer.new # rubocop: disable CodeReuse/Serializer - opts = { user: current_user } + opts = { user: current_user, project: project } { enabled_keys: serializer.represent(enabled_keys.with_projects, opts), diff --git a/app/presenters/todo_presenter.rb b/app/presenters/todo_presenter.rb new file mode 100644 index 00000000000..b57fc712c5a --- /dev/null +++ b/app/presenters/todo_presenter.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class TodoPresenter < Gitlab::View::Presenter::Delegated + include GlobalID::Identification + + presents :todo +end |