diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-05 00:08:55 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-05 00:08:55 +0300 |
commit | 51612d3ef5be853289008694c40973b479e8547c (patch) | |
tree | 0a74213e94c9b6d81f6f0cb01e0b5dbff26f5444 /app | |
parent | ca05512007cea51e05d3431b2c8bd7228c754370 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/models/project.rb | 4 | ||||
-rw-r--r-- | app/serializers/merge_request_widget_entity.rb | 20 |
2 files changed, 24 insertions, 0 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 31aeb0146df..8a751b0d706 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -2299,6 +2299,10 @@ class Project < ApplicationRecord false end + def uses_default_ci_config? + ci_config_path.blank? || ci_config_path == Gitlab::FileDetector::PATTERNS[:gitlab_ci] + end + private def closest_namespace_setting(name) diff --git a/app/serializers/merge_request_widget_entity.rb b/app/serializers/merge_request_widget_entity.rb index adc4d08a6f6..7d67a35c94c 100644 --- a/app/serializers/merge_request_widget_entity.rb +++ b/app/serializers/merge_request_widget_entity.rb @@ -50,6 +50,19 @@ class MergeRequestWidgetEntity < Grape::Entity ci_environments_status_project_merge_request_path(merge_request.project, merge_request) end + expose :merge_request_add_ci_config_path, if: ->(mr, _) { can_add_ci_config_path?(mr) } do |merge_request| + project_new_blob_path( + merge_request.source_project, + merge_request.source_branch, + file_name: '.gitlab-ci.yml', + commit_message: s_("CommitMessage|Add %{file_name}") % { file_name: Gitlab::FileDetector::PATTERNS[:gitlab_ci] } + ) + end + + expose :human_access do |merge_request| + merge_request.project.team.human_max_access(current_user&.id) + end + # Rendering and redacting Markdown can be expensive. These links are # just nice to have in the merge request widget, so only # include them if they are explicitly requested on first load. @@ -75,6 +88,13 @@ class MergeRequestWidgetEntity < Grape::Entity @presenters ||= {} @presenters[merge_request] ||= MergeRequestPresenter.new(merge_request, current_user: current_user) # rubocop: disable CodeReuse/Presenter end + + def can_add_ci_config_path?(merge_request) + merge_request.source_project&.uses_default_ci_config? && + merge_request.all_pipelines.none? && + merge_request.commits_count.positive? && + can?(current_user, :push_code, merge_request.source_project) + end end MergeRequestWidgetEntity.prepend_if_ee('EE::MergeRequestWidgetEntity') |