diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-03 18:07:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-03 18:07:07 +0300 |
commit | 9a1c5456747a7b5b218b8b44e4b43396bf7fd705 (patch) | |
tree | dc5873f33437c897389e923a59365fb192d87fb8 /app | |
parent | 927cfbfe63dd3dc64df9d341d7c4328a2fe3597f (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/services/concerns/git/change_params.rb | 17 | ||||
-rw-r--r-- | app/services/git/base_hooks_service.rb | 15 | ||||
-rw-r--r-- | app/services/git/branch_hooks_service.rb | 16 | ||||
-rw-r--r-- | app/services/git/branch_push_service.rb | 13 | ||||
-rw-r--r-- | app/services/git/tag_hooks_service.rb | 6 | ||||
-rw-r--r-- | app/services/git/tag_push_service.rb | 4 | ||||
-rw-r--r-- | app/services/issues/close_service.rb | 2 | ||||
-rw-r--r-- | app/services/merge_requests/post_merge_service.rb | 4 | ||||
-rw-r--r-- | app/views/projects/cycle_analytics/_overview.html.haml | 2 | ||||
-rw-r--r-- | app/views/projects/cycle_analytics/show.html.haml | 2 | ||||
-rw-r--r-- | app/workers/post_receive.rb | 57 |
11 files changed, 76 insertions, 62 deletions
diff --git a/app/services/concerns/git/change_params.rb b/app/services/concerns/git/change_params.rb new file mode 100644 index 00000000000..32faf805b5e --- /dev/null +++ b/app/services/concerns/git/change_params.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Git + module ChangeParams + private + + %i[oldrev newrev ref].each do |method| + define_method method do + change[method] + end + end + + def change + @change ||= params.fetch(:change, {}) + end + end +end diff --git a/app/services/git/base_hooks_service.rb b/app/services/git/base_hooks_service.rb index 0d320e96b2e..97047d96de1 100644 --- a/app/services/git/base_hooks_service.rb +++ b/app/services/git/base_hooks_service.rb @@ -3,6 +3,7 @@ module Git class BaseHooksService < ::BaseService include Gitlab::Utils::StrongMemoize + include ChangeParams # The N most recent commits to process in a single push payload. PROCESS_COMMIT_LIMIT = 100 @@ -77,20 +78,20 @@ module Git def pipeline_params { - before: params[:oldrev], - after: params[:newrev], - ref: params[:ref], + before: oldrev, + after: newrev, + ref: ref, push_options: params[:push_options] || {}, checkout_sha: Gitlab::DataBuilder::Push.checkout_sha( - project.repository, params[:newrev], params[:ref]) + project.repository, newrev, ref) } end def push_data_params(commits:, with_changed_files: true) { - oldrev: params[:oldrev], - newrev: params[:newrev], - ref: params[:ref], + oldrev: oldrev, + newrev: newrev, + ref: ref, project: project, user: current_user, commits: commits, diff --git a/app/services/git/branch_hooks_service.rb b/app/services/git/branch_hooks_service.rb index c633cff2822..69f1f9eb31f 100644 --- a/app/services/git/branch_hooks_service.rb +++ b/app/services/git/branch_hooks_service.rb @@ -20,15 +20,15 @@ module Git strong_memoize(:commits) do if creating_default_branch? # The most recent PROCESS_COMMIT_LIMIT commits in the default branch - project.repository.commits(params[:newrev], limit: PROCESS_COMMIT_LIMIT) + project.repository.commits(newrev, limit: PROCESS_COMMIT_LIMIT) elsif creating_branch? # Use the pushed commits that aren't reachable by the default branch # as a heuristic. This may include more commits than are actually # pushed, but that shouldn't matter because we check for existing # cross-references later. - project.repository.commits_between(project.default_branch, params[:newrev]) + project.repository.commits_between(project.default_branch, newrev) elsif updating_branch? - project.repository.commits_between(params[:oldrev], params[:newrev]) + project.repository.commits_between(oldrev, newrev) else # removing branch [] end @@ -70,7 +70,7 @@ module Git def branch_update_hooks # Update the bare repositories info/attributes file using the contents of # the default branch's .gitattributes file - project.repository.copy_gitattributes(params[:ref]) if default_branch? + project.repository.copy_gitattributes(ref) if default_branch? end def branch_change_hooks @@ -118,7 +118,7 @@ module Git # https://gitlab.com/gitlab-org/gitlab-foss/issues/59257 def creating_branch? strong_memoize(:creating_branch) do - Gitlab::Git.blank_ref?(params[:oldrev]) || + Gitlab::Git.blank_ref?(oldrev) || !project.repository.branch_exists?(branch_name) end end @@ -128,7 +128,7 @@ module Git end def removing_branch? - Gitlab::Git.blank_ref?(params[:newrev]) + Gitlab::Git.blank_ref?(newrev) end def creating_default_branch? @@ -137,7 +137,7 @@ module Git def count_commits_in_branch strong_memoize(:count_commits_in_branch) do - project.repository.commit_count_for_ref(params[:ref]) + project.repository.commit_count_for_ref(ref) end end @@ -148,7 +148,7 @@ module Git end def branch_name - strong_memoize(:branch_name) { Gitlab::Git.ref_name(params[:ref]) } + strong_memoize(:branch_name) { Gitlab::Git.ref_name(ref) } end def upstream_commit_ids(commits) diff --git a/app/services/git/branch_push_service.rb b/app/services/git/branch_push_service.rb index 7adc3320e06..da45bcc7eaa 100644 --- a/app/services/git/branch_push_service.rb +++ b/app/services/git/branch_push_service.rb @@ -4,6 +4,7 @@ module Git class BranchPushService < ::BaseService include Gitlab::Access include Gitlab::Utils::StrongMemoize + include ChangeParams # This method will be called after each git update # and only if the provided user and project are present in GitLab. @@ -19,7 +20,7 @@ module Git # 6. Checks if the project's main language has changed # def execute - return unless Gitlab::Git.branch_ref?(params[:ref]) + return unless Gitlab::Git.branch_ref?(ref) enqueue_update_mrs enqueue_detect_repository_languages @@ -38,9 +39,9 @@ module Git UpdateMergeRequestsWorker.perform_async( project.id, current_user.id, - params[:oldrev], - params[:newrev], - params[:ref] + oldrev, + newrev, + ref ) end @@ -69,11 +70,11 @@ module Git end def removing_branch? - Gitlab::Git.blank_ref?(params[:newrev]) + Gitlab::Git.blank_ref?(newrev) end def branch_name - strong_memoize(:branch_name) { Gitlab::Git.ref_name(params[:ref]) } + strong_memoize(:branch_name) { Gitlab::Git.ref_name(ref) } end def default_branch? diff --git a/app/services/git/tag_hooks_service.rb b/app/services/git/tag_hooks_service.rb index e5b109c79d6..0e5e1bbc992 100644 --- a/app/services/git/tag_hooks_service.rb +++ b/app/services/git/tag_hooks_service.rb @@ -18,12 +18,12 @@ module Git def tag strong_memoize(:tag) do - next if Gitlab::Git.blank_ref?(params[:newrev]) + next if Gitlab::Git.blank_ref?(newrev) - tag_name = Gitlab::Git.ref_name(params[:ref]) + tag_name = Gitlab::Git.ref_name(ref) tag = project.repository.find_tag(tag_name) - tag if tag && tag.target == params[:newrev] + tag if tag && tag.target == newrev end end diff --git a/app/services/git/tag_push_service.rb b/app/services/git/tag_push_service.rb index ee4166dccd0..9a266f7d74c 100644 --- a/app/services/git/tag_push_service.rb +++ b/app/services/git/tag_push_service.rb @@ -2,8 +2,10 @@ module Git class TagPushService < ::BaseService + include ChangeParams + def execute - return unless Gitlab::Git.tag_ref?(params[:ref]) + return unless Gitlab::Git.tag_ref?(ref) project.repository.before_push_tag TagHooksService.new(project, current_user, params).execute diff --git a/app/services/issues/close_service.rb b/app/services/issues/close_service.rb index 965351b5b6c..14585c2850b 100644 --- a/app/services/issues/close_service.rb +++ b/app/services/issues/close_service.rb @@ -4,7 +4,7 @@ module Issues class CloseService < Issues::BaseService # Closes the supplied issue if the current user is able to do so. def execute(issue, commit: nil, notifications: true, system_note: true) - return issue unless can?(current_user, :update_issue, issue) + return issue unless can?(current_user, :update_issue, issue) || issue.is_a?(ExternalIssue) close_issue(issue, closed_via: commit, diff --git a/app/services/merge_requests/post_merge_service.rb b/app/services/merge_requests/post_merge_service.rb index fbe6c48ac28..0364c0dd479 100644 --- a/app/services/merge_requests/post_merge_service.rb +++ b/app/services/merge_requests/post_merge_service.rb @@ -29,9 +29,7 @@ module MergeRequests closed_issues = merge_request.visible_closing_issues_for(current_user) closed_issues.each do |issue| - if can?(current_user, :update_issue, issue) - Issues::CloseService.new(project, current_user, {}).execute(issue, commit: merge_request) - end + Issues::CloseService.new(project, current_user).execute(issue, commit: merge_request) end end diff --git a/app/views/projects/cycle_analytics/_overview.html.haml b/app/views/projects/cycle_analytics/_overview.html.haml index 5b0d73b8c68..ea94b637f89 100644 --- a/app/views/projects/cycle_analytics/_overview.html.haml +++ b/app/views/projects/cycle_analytics/_overview.html.haml @@ -9,7 +9,7 @@ Cycle Analytics gives an overview of how much time it takes to go from idea to production in your project. To set up CA, you must first define a production environment by setting up your CI and then deploy to production. %p - %a.btn{ href: help_page_path('user/project/cycle_analytics'), target: '_blank' } Read more + %a.btn{ href: help_page_path('user/analytics/cycle_analytics.md'), target: '_blank' } Read more .col-md-6.overview-image %span.overview-icon = custom_icon ('icon_cycle_analytics_overview') diff --git a/app/views/projects/cycle_analytics/show.html.haml b/app/views/projects/cycle_analytics/show.html.haml index 6b56a4ee7ab..7fedd1ab785 100644 --- a/app/views/projects/cycle_analytics/show.html.haml +++ b/app/views/projects/cycle_analytics/show.html.haml @@ -3,7 +3,7 @@ #cycle-analytics{ "v-cloak" => "true", data: { request_path: project_cycle_analytics_path(@project) } } - if @cycle_analytics_no_data %banner{ "v-if" => "!isOverviewDialogDismissed", - "documentation-link": help_page_path('user/project/cycle_analytics'), + "documentation-link": help_page_path('user/analytics/cycle_analytics.md'), "v-on:dismiss-overview-dialog" => "dismissOverviewDialog()" } = icon("spinner spin", "v-show" => "isLoading") .wrapper{ "v-show" => "!isLoading && !hasError" } diff --git a/app/workers/post_receive.rb b/app/workers/post_receive.rb index cae3cb45c45..a4b9ef18a3b 100644 --- a/app/workers/post_receive.rb +++ b/app/workers/post_receive.rb @@ -37,41 +37,22 @@ class PostReceive end def process_project_changes(post_received) - changes = [] - refs = Set.new user = identify_user(post_received) + return false unless user + project = post_received.project + push_options = post_received.push_options + changes = post_received.changes + # We only need to expire certain caches once per push expire_caches(post_received, post_received.project.repository) enqueue_repository_cache_update(post_received) - post_received.enum_for(:changes_refs).with_index do |(oldrev, newrev, ref), index| - service_klass = - if Gitlab::Git.tag_ref?(ref) - Git::TagPushService - elsif Gitlab::Git.branch_ref?(ref) - Git::BranchPushService - end - - if service_klass - service_klass.new( - post_received.project, - user, - oldrev: oldrev, - newrev: newrev, - ref: ref, - push_options: post_received.push_options, - create_pipelines: index < PIPELINE_PROCESS_LIMIT || Feature.enabled?(:git_push_create_all_pipelines, post_received.project) - ).execute - end - - changes << Gitlab::DataBuilder::Repository.single_change(oldrev, newrev, ref) - refs << ref - end - + process_changes(Git::BranchPushService, project, user, push_options, changes.branch_changes) + process_changes(Git::TagPushService, project, user, push_options, changes.tag_changes) update_remote_mirrors(post_received) - after_project_changes_hooks(post_received, user, refs.to_a, changes) + after_project_changes_hooks(project, user, changes.refs, changes.repository_data) end # Expire the repository status, branch, and tag cache once per push. @@ -94,6 +75,20 @@ class PostReceive ) end + def process_changes(service_class, project, user, push_options, changes) + return if changes.empty? + + changes.each do |change| + service_class.new( + project, + user, + change: change, + push_options: push_options, + create_pipelines: change[:index] < PIPELINE_PROCESS_LIMIT || Feature.enabled?(:git_push_create_all_pipelines, project) + ).execute + end + end + def update_remote_mirrors(post_received) return unless post_received.includes_branches? || post_received.includes_tags? @@ -104,9 +99,9 @@ class PostReceive project.update_remote_mirrors end - def after_project_changes_hooks(post_received, user, refs, changes) - hook_data = Gitlab::DataBuilder::Repository.update(post_received.project, user, changes, refs) - SystemHooksService.new.execute_hooks(hook_data, :repository_update_hooks) + def after_project_changes_hooks(project, user, refs, changes) + repository_update_hook_data = Gitlab::DataBuilder::Repository.update(project, user, changes, refs) + SystemHooksService.new.execute_hooks(repository_update_hook_data, :repository_update_hooks) Gitlab::UsageDataCounters::SourceCodeCounter.count(:pushes) end @@ -121,7 +116,7 @@ class PostReceive # We only need to expire certain caches once per push expire_caches(post_received, post_received.project.wiki.repository) - ::Git::WikiPushService.new(post_received.project, user, changes: post_received.enum_for(:changes_refs)).execute + ::Git::WikiPushService.new(post_received.project, user, changes: post_received.changes).execute end def log(message) |