diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-08-11 11:28:42 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-08-11 11:28:42 +0300 |
commit | 9f10943c1a76576ac40d96189a28a4d6123a75d8 (patch) | |
tree | 88955d92ebc98a4165d66a36cb8a2cf92709981a /app | |
parent | 84727fba96c6794874e1f94d581408b70e1842a7 (diff) |
Revert "Merge branch 'drop-satellites'"
This reverts commit 957e849f41d96fa9778fcdd06792d2f0274b29ab, reversing
changes made to 6b9dbe9f5a175a8162abf296367f561bab3eea1a.
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app')
32 files changed, 242 insertions, 300 deletions
diff --git a/app/assets/javascripts/merge_request_widget.js.coffee b/app/assets/javascripts/merge_request_widget.js.coffee index c68a2a9d047..762eec63dee 100644 --- a/app/assets/javascripts/merge_request_widget.js.coffee +++ b/app/assets/javascripts/merge_request_widget.js.coffee @@ -19,7 +19,7 @@ class @MergeRequestWidget when 'merged' location.reload() else - setTimeout(merge_request_widget.mergeInProgress, 2000) + setTimeout(merge_request_widget.mergeInProgress, 3000) dataType: 'json' getMergeStatus: -> diff --git a/app/controllers/projects/compare_controller.rb b/app/controllers/projects/compare_controller.rb index d9b3adae95b..c5f085c236f 100644 --- a/app/controllers/projects/compare_controller.rb +++ b/app/controllers/projects/compare_controller.rb @@ -13,8 +13,13 @@ class Projects::CompareController < Projects::ApplicationController base_ref = Addressable::URI.unescape(params[:from]) @ref = head_ref = Addressable::URI.unescape(params[:to]) - compare_result = CompareService.new. - execute(@project, head_ref, @project, base_ref) + compare_result = CompareService.new.execute( + current_user, + @project, + head_ref, + @project, + base_ref + ) @commits = compare_result.commits @diffs = compare_result.diffs diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index f3054881daf..d1265198318 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -1,7 +1,9 @@ +require 'gitlab/satellite/satellite' + class Projects::MergeRequestsController < Projects::ApplicationController before_action :module_enabled before_action :merge_request, only: [ - :edit, :update, :show, :diffs, :commits, :merge, :merge_check, + :edit, :update, :show, :diffs, :commits, :automerge, :automerge_check, :ci_status, :toggle_subscription ] before_action :closes_issues, only: [:edit, :update, :show, :diffs, :commits] @@ -135,7 +137,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController end end - def merge_check + def automerge_check if @merge_request.unchecked? @merge_request.check_if_can_be_merged end @@ -145,11 +147,11 @@ class Projects::MergeRequestsController < Projects::ApplicationController render partial: "projects/merge_requests/widget/show.html.haml", layout: false end - def merge + def automerge return access_denied! unless @merge_request.can_be_merged_by?(current_user) - if @merge_request.mergeable? - MergeWorker.perform_async(@merge_request.id, current_user.id, params) + if @merge_request.automergeable? + AutoMergeWorker.perform_async(@merge_request.id, current_user.id, params) @status = true else @status = false diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 631a2d887cc..1ef76d16700 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -41,6 +41,8 @@ class MergeRequest < ActiveRecord::Base delegate :commits, :diffs, :last_commit, :last_commit_short_sha, to: :merge_request_diff, prefix: nil + attr_accessor :should_remove_source_branch + # When this attribute is true some MR validation is ignored # It allows us to close or modify broken merge requests attr_accessor :allow_broken @@ -55,7 +57,7 @@ class MergeRequest < ActiveRecord::Base transition [:reopened, :opened] => :closed end - event :mark_as_merged do + event :merge do transition [:reopened, :opened, :locked] => :merged end @@ -204,7 +206,11 @@ class MergeRequest < ActiveRecord::Base def check_if_can_be_merged can_be_merged = - project.repository.can_be_merged?(source_sha, target_branch) + if for_fork? + Gitlab::Satellite::MergeAction.new(self.author, self).can_be_merged? + else + project.repository.can_be_merged?(source_branch, target_branch) + end if can_be_merged mark_as_mergeable @@ -221,6 +227,18 @@ class MergeRequest < ActiveRecord::Base self.target_project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::CLOSED).last end + def automerge!(current_user, commit_message = nil) + return unless automergeable? + + MergeRequests::AutoMergeService. + new(target_project, current_user). + execute(self, commit_message) + end + + def remove_source_branch? + self.should_remove_source_branch && !self.source_project.root_ref?(self.source_branch) && !self.for_fork? + end + def open? opened? || reopened? end @@ -229,11 +247,11 @@ class MergeRequest < ActiveRecord::Base title =~ /\A\[?WIP\]?:? /i end - def mergeable? + def automergeable? open? && !work_in_progress? && can_be_merged? end - def gitlab_merge_status + def automerge_status if work_in_progress? "work_in_progress" else @@ -260,14 +278,14 @@ class MergeRequest < ActiveRecord::Base # # see "git diff" def to_diff(current_user) - target_project.repository.diff_text(target_branch, source_sha) + Gitlab::Satellite::MergeAction.new(current_user, self).diff_in_satellite end # Returns the commit as a series of email patches. # # see "git format-patch" def to_patch(current_user) - target_project.repository.format_patch(target_branch, source_sha) + Gitlab::Satellite::MergeAction.new(current_user, self).format_patch end def hook_attrs @@ -418,30 +436,4 @@ class MergeRequest < ActiveRecord::Base "Open" end end - - def target_sha - @target_sha ||= target_project. - repository.commit(target_branch).sha - end - - def source_sha - commits.first.sha - end - - def fetch_ref - target_project.repository.fetch_ref( - source_project.repository.path_to_repo, - "refs/heads/#{source_branch}", - "refs/merge-requests/#{id}/head" - ) - end - - def in_locked_state - begin - lock_mr - yield - ensure - unlock_mr if locked? - end - end end diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index 2177f972ca3..df1c2b78758 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -16,8 +16,9 @@ require Rails.root.join("app/models/commit") class MergeRequestDiff < ActiveRecord::Base include Sortable - # Prevent store of diff if commits amount more then 500 - COMMITS_SAFE_SIZE = 500 + # Prevent store of diff + # if commits amount more then 200 + COMMITS_SAFE_SIZE = 200 attr_reader :commits, :diffs @@ -123,12 +124,12 @@ class MergeRequestDiff < ActiveRecord::Base if new_diffs.any? if new_diffs.size > Commit::DIFF_HARD_LIMIT_FILES self.state = :overflow_diff_files_limit - new_diffs = new_diffs.first[Commit::DIFF_HARD_LIMIT_LINES] + new_diffs = [] end if new_diffs.sum { |diff| diff.diff.lines.count } > Commit::DIFF_HARD_LIMIT_LINES self.state = :overflow_diff_lines_limit - new_diffs = new_diffs.first[Commit::DIFF_HARD_LIMIT_LINES] + new_diffs = [] end end @@ -159,21 +160,12 @@ class MergeRequestDiff < ActiveRecord::Base private def compare_result - @compare_result ||= - begin - # Update ref if merge request is from fork - merge_request.fetch_ref if merge_request.for_fork? - - # Get latest sha of branch from source project - source_sha = merge_request.source_project.commit(source_branch).sha - - Gitlab::CompareResult.new( - Gitlab::Git::Compare.new( - merge_request.target_project.repository.raw_repository, - merge_request.target_branch, - source_sha, - ) - ) - end + @compare_result ||= CompareService.new.execute( + merge_request.author, + merge_request.source_project, + merge_request.source_branch, + merge_request.target_project, + merge_request.target_branch, + ) end end diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 161a16ca61c..30ffacadded 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -118,11 +118,12 @@ class Namespace < ActiveRecord::Base gitlab_shell.add_namespace(path_was) if gitlab_shell.mv_namespace(path_was, path) - # If repositories moved successfully we need to - # send update instructions to users. + # If repositories moved successfully we need to remove old satellites + # and send update instructions to users. # However we cannot allow rollback since we moved namespace dir # So we basically we mute exceptions in next actions begin + gitlab_shell.rm_satellites(path_was) send_update_instructions rescue # Returning false does not rollback after_* transaction but gives diff --git a/app/models/project.rb b/app/models/project.rb index 4628f478ca6..3dc1729e812 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -520,6 +520,14 @@ class Project < ActiveRecord::Base !repository.exists? || repository.empty? end + def ensure_satellite_exists + self.satellite.create unless self.satellite.exists? + end + + def satellite + @satellite ||= Gitlab::Satellite::Satellite.new(self) + end + def repo repository.raw end @@ -589,11 +597,14 @@ class Project < ActiveRecord::Base new_path_with_namespace = File.join(namespace_dir, path) if gitlab_shell.mv_repository(old_path_with_namespace, new_path_with_namespace) - # If repository moved successfully we need to send update instructions to users. + # If repository moved successfully we need to remove old satellite + # and send update instructions to users. # However we cannot allow rollback since we moved repository # So we basically we mute exceptions in next actions begin gitlab_shell.mv_repository("#{old_path_with_namespace}.wiki", "#{new_path_with_namespace}.wiki") + gitlab_shell.rm_satellites(old_path_with_namespace) + ensure_satellite_exists send_move_instructions reset_events_cache rescue @@ -691,6 +702,7 @@ class Project < ActiveRecord::Base def create_repository if forked? if gitlab_shell.fork_repository(forked_from_project.path_with_namespace, self.namespace.path) + ensure_satellite_exists true else errors.add(:base, 'Failed to fork repository via gitlab-shell') diff --git a/app/models/project_services/gitlab_ci_service.rb b/app/models/project_services/gitlab_ci_service.rb index ecdcd48ae60..5aaa4e85cbc 100644 --- a/app/models/project_services/gitlab_ci_service.rb +++ b/app/models/project_services/gitlab_ci_service.rb @@ -74,8 +74,6 @@ class GitlabCiService < CiService else :error end - rescue Errno::ECONNREFUSED - :error end def fork_registration(new_project, private_token) @@ -105,8 +103,6 @@ class GitlabCiService < CiService if response.code == 200 and response["coverage"] response["coverage"] end - rescue Errno::ECONNREFUSED - nil end def build_page(sha, ref) diff --git a/app/models/repository.rb b/app/models/repository.rb index 46efbede2a2..807b33b2a3e 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -411,36 +411,15 @@ class Repository } end - def can_be_merged?(source_sha, target_branch) + def can_be_merged?(source_branch, target_branch) our_commit = rugged.branches[target_branch].target - their_commit = rugged.lookup(source_sha) + their_commit = rugged.branches[source_branch].target if our_commit && their_commit !rugged.merge_commits(our_commit, their_commit).conflicts? - else - false end end - def merge(source_sha, target_branch, options = {}) - our_commit = rugged.branches[target_branch].target - their_commit = rugged.lookup(source_sha) - - raise "Invalid merge target" if our_commit.nil? - raise "Invalid merge source" if their_commit.nil? - - merge_index = rugged.merge_commits(our_commit, their_commit) - return false if merge_index.conflicts? - - actual_options = options.merge( - parents: [our_commit, their_commit], - tree: merge_index.write_tree(rugged), - update_ref: "refs/heads/#{target_branch}" - ) - - Rugged::Commit.create(rugged, actual_options) - end - def search_files(query, ref) offset = 2 args = %W(git grep -i -n --before-context #{offset} --after-context #{offset} #{query} #{ref || root_ref}) @@ -474,11 +453,6 @@ class Repository ) end - def fetch_ref(source_path, source_ref, target_ref) - args = %W(git fetch #{source_path} #{source_ref}:#{target_ref}) - Gitlab::Popen.popen(args, path_to_repo) - end - private def cache diff --git a/app/services/base_service.rb b/app/services/base_service.rb index f00ec7408b6..6d9ed345914 100644 --- a/app/services/base_service.rb +++ b/app/services/base_service.rb @@ -31,10 +31,6 @@ class BaseService SystemHooksService.new end - def repository - project.repository - end - # Add an error to the specified model for restricted visibility levels def deny_visibility_level(model, denied_visibility_level = nil) denied_visibility_level ||= model.visibility_level diff --git a/app/services/compare_service.rb b/app/services/compare_service.rb index 70f642baaaa..6aa9df4b194 100644 --- a/app/services/compare_service.rb +++ b/app/services/compare_service.rb @@ -1,28 +1,27 @@ -require 'securerandom' - # Compare 2 branches for one repo or between repositories # and return Gitlab::CompareResult object that responds to commits and diffs class CompareService - def execute(source_project, source_branch, target_project, target_branch) - source_sha = source_project.commit(source_branch).sha - - # If compare with other project we need to fetch ref first - unless target_project == source_project - random_string = SecureRandom.hex - - target_project.repository.fetch_ref( - source_project.repository.path_to_repo, - "refs/heads/#{source_branch}", - "refs/tmp/#{random_string}/head" + def execute(current_user, source_project, source_branch, target_project, target_branch) + # Try to compare branches to get commits list and diffs + # + # Note: Use satellite only when need to compare between two repos + # because satellites are slower than operations on bare repo + if target_project == source_project + Gitlab::CompareResult.new( + Gitlab::Git::Compare.new( + target_project.repository.raw_repository, + target_branch, + source_branch, + ) ) - end - - Gitlab::CompareResult.new( - Gitlab::Git::Compare.new( - target_project.repository.raw_repository, + else + Gitlab::Satellite::CompareAction.new( + current_user, + target_project, target_branch, - source_sha, - ) - ) + source_project, + source_branch + ).result + end end end diff --git a/app/services/files/base_service.rb b/app/services/files/base_service.rb index d7b40ee8906..646784f2d9d 100644 --- a/app/services/files/base_service.rb +++ b/app/services/files/base_service.rb @@ -33,8 +33,15 @@ module Files private + def repository + project.repository + end + def after_commit(sha, branch) - PostCommitService.new(project, current_user).execute(sha, branch) + commit = repository.commit(sha) + full_ref = "#{Gitlab::Git::BRANCH_REF_PREFIX}#{branch}" + old_sha = commit.parent_id || Gitlab::Git::BLANK_SHA + GitPushService.new.execute(project, current_user, old_sha, sha, full_ref) end def current_branch diff --git a/app/services/git_push_service.rb b/app/services/git_push_service.rb index 81535450ac1..3511392d1d8 100644 --- a/app/services/git_push_service.rb +++ b/app/services/git_push_service.rb @@ -10,14 +10,16 @@ class GitPushService # # Next, this method: # 1. Creates the push event - # 2. Updates merge requests - # 3. Recognizes cross-references from commit messages - # 4. Executes the project's web hooks - # 5. Executes the project's services + # 2. Ensures that the project satellite exists + # 3. Updates merge requests + # 4. Recognizes cross-references from commit messages + # 5. Executes the project's web hooks + # 6. Executes the project's services # def execute(project, user, oldrev, newrev, ref) @project, @user = project, user + project.ensure_satellite_exists project.repository.expire_cache if push_remove_branch?(ref, newrev) diff --git a/app/services/merge_requests/auto_merge_service.rb b/app/services/merge_requests/auto_merge_service.rb new file mode 100644 index 00000000000..db824d452d0 --- /dev/null +++ b/app/services/merge_requests/auto_merge_service.rb @@ -0,0 +1,75 @@ +module MergeRequests + # AutoMergeService class + # + # Do git merge in satellite and in case of success + # mark merge request as merged and execute all hooks and notifications + # Called when you do merge via GitLab UI + class AutoMergeService < BaseMergeService + attr_reader :merge_request, :commit_message + + def execute(merge_request, commit_message) + @commit_message = commit_message + @merge_request = merge_request + + merge_request.lock_mr + + if merge! + merge_request.merge + create_merge_event(merge_request, current_user) + create_note(merge_request) + notification_service.merge_mr(merge_request, current_user) + execute_hooks(merge_request, 'merge') + true + else + merge_request.unlock_mr + false + end + rescue + merge_request.unlock_mr if merge_request.locked? + merge_request.mark_as_unmergeable + false + end + + def merge! + if merge_request.for_fork? + Gitlab::Satellite::MergeAction.new(current_user, merge_request).merge!(commit_message) + else + # Merge local branches using rugged instead of satellites + if sha = commit + after_commit(sha, merge_request.target_branch) + + if merge_request.remove_source_branch? + DeleteBranchService.new(merge_request.source_project, current_user).execute(merge_request.source_branch) + end + + true + else + false + end + end + end + + def commit + committer = repository.user_to_comitter(current_user) + + options = { + message: commit_message, + author: committer, + committer: committer + } + + repository.merge(merge_request.source_branch, merge_request.target_branch, options) + end + + def after_commit(sha, branch) + commit = repository.commit(sha) + full_ref = "#{Gitlab::Git::BRANCH_REF_PREFIX}#{branch}" + old_sha = commit.parent_id || Gitlab::Git::BLANK_SHA + GitPushService.new.execute(project, current_user, old_sha, sha, full_ref) + end + + def repository + project.repository + end + end +end diff --git a/app/services/merge_requests/base_merge_service.rb b/app/services/merge_requests/base_merge_service.rb new file mode 100644 index 00000000000..9579573adf9 --- /dev/null +++ b/app/services/merge_requests/base_merge_service.rb @@ -0,0 +1,10 @@ +module MergeRequests + class BaseMergeService < MergeRequests::BaseService + + private + + def create_merge_event(merge_request, current_user) + EventCreateService.new.merge_mr(merge_request, current_user) + end + end +end diff --git a/app/services/merge_requests/build_service.rb b/app/services/merge_requests/build_service.rb index a9b29f9654d..956480938c3 100644 --- a/app/services/merge_requests/build_service.rb +++ b/app/services/merge_requests/build_service.rb @@ -12,16 +12,12 @@ module MergeRequests merge_request.target_project ||= (project.forked_from_project || project) merge_request.target_branch ||= merge_request.target_project.default_branch - if merge_request.target_branch.blank? || merge_request.source_branch.blank? - message = - if params[:source_branch] || params[:target_branch] - "You must select source and target branch" - end - - return build_failed(merge_request, message) + unless merge_request.target_branch && merge_request.source_branch + return build_failed(merge_request, nil) end compare_result = CompareService.new.execute( + current_user, merge_request.source_project, merge_request.source_branch, merge_request.target_project, @@ -44,6 +40,7 @@ module MergeRequests merge_request.compare_diffs = diffs elsif diffs == false + # satellite timeout return false merge_request.can_be_created = false merge_request.compare_failed = true end @@ -62,6 +59,9 @@ module MergeRequests end merge_request + + rescue Gitlab::Satellite::BranchesWithoutParent + return build_failed(merge_request, "Selected branches have no common commit so they cannot be merged.") end def build_failed(merge_request, message) diff --git a/app/services/merge_requests/merge_service.rb b/app/services/merge_requests/merge_service.rb index 2107529a21a..327ead4ff3f 100644 --- a/app/services/merge_requests/merge_service.rb +++ b/app/services/merge_requests/merge_service.rb @@ -1,57 +1,22 @@ module MergeRequests # MergeService class # - # Do git merge and in case of success - # mark merge request as merged and execute all hooks and notifications - # Executed when you do merge via GitLab UI - # - class MergeService < MergeRequests::BaseService - attr_reader :merge_request, :commit_message - + # Mark existing merge request as merged + # and execute all hooks and notifications + # Called when you do merge via command line and push code + # to target branch + class MergeService < BaseMergeService def execute(merge_request, commit_message) - @commit_message = commit_message - @merge_request = merge_request + merge_request.merge - unless @merge_request.mergeable? - return error('Merge request is not mergeable') - end - - merge_request.in_locked_state do - if merge_changes - after_merge - success - else - error('Can not merge changes') - end - end - end - - private - - def merge_changes - if sha = commit - after_commit(sha, merge_request.target_branch) - end - end - - def commit - committer = repository.user_to_comitter(current_user) - - options = { - message: commit_message, - author: committer, - committer: committer - } - - repository.merge(merge_request.source_sha, merge_request.target_branch, options) - end - - def after_commit(sha, branch) - PostCommitService.new(project, current_user).execute(sha, branch) - end + create_merge_event(merge_request, current_user) + create_note(merge_request) + notification_service.merge_mr(merge_request, current_user) + execute_hooks(merge_request, 'merge') - def after_merge - MergeRequests::PostMergeService.new(project, current_user).execute(merge_request) + true + rescue + false end end end diff --git a/app/services/merge_requests/post_merge_service.rb b/app/services/merge_requests/post_merge_service.rb deleted file mode 100644 index aceb8cb9021..00000000000 --- a/app/services/merge_requests/post_merge_service.rb +++ /dev/null @@ -1,22 +0,0 @@ -module MergeRequests - # PostMergeService class - # - # Mark existing merge request as merged - # and execute all hooks and notifications - # - class PostMergeService < MergeRequests::BaseService - def execute(merge_request) - merge_request.mark_as_merged - create_merge_event(merge_request, current_user) - create_note(merge_request) - notification_service.merge_mr(merge_request, current_user) - execute_hooks(merge_request, 'merge') - end - - private - - def create_merge_event(merge_request, current_user) - EventCreateService.new.merge_mr(merge_request, current_user) - end - end -end diff --git a/app/services/merge_requests/refresh_service.rb b/app/services/merge_requests/refresh_service.rb index e903e48e3cd..d0648da049b 100644 --- a/app/services/merge_requests/refresh_service.rb +++ b/app/services/merge_requests/refresh_service.rb @@ -33,9 +33,9 @@ module MergeRequests merge_requests.uniq.select(&:source_project).each do |merge_request| - MergeRequests::PostMergeService. + MergeRequests::MergeService. new(merge_request.target_project, @current_user). - execute(merge_request) + execute(merge_request, nil) end end diff --git a/app/services/post_commit_service.rb b/app/services/post_commit_service.rb deleted file mode 100644 index 8592c8d238b..00000000000 --- a/app/services/post_commit_service.rb +++ /dev/null @@ -1,71 +0,0 @@ -class PostCommitService < BaseService - include Gitlab::Popen - - attr_reader :changes, :repo_path - - def execute(sha, branch) - commit = repository.commit(sha) - full_ref = Gitlab::Git::BRANCH_REF_PREFIX + branch - old_sha = commit.parent_id || Gitlab::Git::BLANK_SHA - @changes = "#{old_sha} #{sha} #{full_ref}" - @repo_path = repository.path_to_repo - - post_receive - end - - private - - def post_receive - hook = hook_file('post-receive', repo_path) - return true if hook.nil? - call_receive_hook(hook) - end - - def call_receive_hook(hook) - # function will return true if succesful - exit_status = false - - vars = { - 'GL_ID' => Gitlab::ShellEnv.gl_id(current_user), - 'PWD' => repo_path - } - - options = { - chdir: repo_path - } - - # we combine both stdout and stderr as we don't know what stream - # will be used by the custom hook - Open3.popen2e(vars, hook, options) do |stdin, stdout_stderr, wait_thr| - exit_status = true - stdin.sync = true - - # in git, pre- and post- receive hooks may just exit without - # reading stdin. We catch the exception to avoid a broken pipe - # warning - begin - # inject all the changes as stdin to the hook - changes.lines do |line| - stdin.puts line - end - rescue Errno::EPIPE - end - - # need to close stdin before reading stdout - stdin.close - - # only output stdut_stderr if scripts doesn't return 0 - unless wait_thr.value == 0 - exit_status = false - end - end - - exit_status - end - - def hook_file(hook_type, repo_path) - hook_path = File.join(repo_path.strip, 'hooks') - hook_file = "#{hook_path}/#{hook_type}" - hook_file if File.exist?(hook_file) - end -end diff --git a/app/services/projects/destroy_service.rb b/app/services/projects/destroy_service.rb index 28872c89259..403f419ec50 100644 --- a/app/services/projects/destroy_service.rb +++ b/app/services/projects/destroy_service.rb @@ -27,6 +27,7 @@ module Projects end end + project.satellite.destroy log_info("Project \"#{project.name}\" was removed") system_hook_service.execute_hooks_for(project, :destroy) true diff --git a/app/services/projects/transfer_service.rb b/app/services/projects/transfer_service.rb index 550ed6897dd..f43c0ef70e9 100644 --- a/app/services/projects/transfer_service.rb +++ b/app/services/projects/transfer_service.rb @@ -33,6 +33,9 @@ module Projects raise TransferError.new("Project with same path in target namespace already exists") end + # Remove old satellite + project.satellite.destroy + # Apply new namespace id project.namespace = new_namespace project.save! @@ -48,6 +51,9 @@ module Projects # Move wiki repo also if present gitlab_shell.mv_repository("#{old_path}.wiki", "#{new_path}.wiki") + # Create a new satellite (reload project from DB) + Project.find(project.id).ensure_satellite_exists + # clear project cached events project.reset_events_cache diff --git a/app/views/projects/merge_requests/_new_compare.html.haml b/app/views/projects/merge_requests/_new_compare.html.haml index 7709330611a..ff9c0cdb283 100644 --- a/app/views/projects/merge_requests/_new_compare.html.haml +++ b/app/views/projects/merge_requests/_new_compare.html.haml @@ -35,7 +35,7 @@ - if @merge_request.compare_failed .alert.alert-danger %h4 Compare failed - %p We can't compare selected branches. It may be because of huge diff. Please try again or select different branches. + %p We can't compare selected branches. It may be because of huge diff or satellite timeout. Please try again or select different branches. - else .light-well .center diff --git a/app/views/projects/merge_requests/_new_submit.html.haml b/app/views/projects/merge_requests/_new_submit.html.haml index 76f44211dac..633a54f3620 100644 --- a/app/views/projects/merge_requests/_new_submit.html.haml +++ b/app/views/projects/merge_requests/_new_submit.html.haml @@ -24,7 +24,7 @@ = icon('history') Commits %span.badge= @commits.size - %li.diffs-tab.active + %li.diffs-tab = link_to url_for(params), data: {target: '#diffs', action: 'diffs', toggle: 'tab'} do = icon('list-alt') Changes @@ -33,7 +33,7 @@ .tab-content #commits.commits.tab-pane = render "projects/commits/commits", project: @project - #diffs.diffs.tab-pane.active + #diffs.diffs.tab-pane - if @diffs.present? = render "projects/diffs/diffs", diffs: @diffs, project: @project - elsif @commits.size > MergeRequestDiff::COMMITS_SAFE_SIZE diff --git a/app/views/projects/merge_requests/merge.js.haml b/app/views/projects/merge_requests/automerge.js.haml index 33321651e32..33321651e32 100644 --- a/app/views/projects/merge_requests/merge.js.haml +++ b/app/views/projects/merge_requests/automerge.js.haml diff --git a/app/views/projects/merge_requests/widget/_open.html.haml b/app/views/projects/merge_requests/widget/_open.html.haml index f420cdcab49..bb794912f8f 100644 --- a/app/views/projects/merge_requests/widget/_open.html.haml +++ b/app/views/projects/merge_requests/widget/_open.html.haml @@ -3,6 +3,8 @@ .mr-widget-body - if @project.archived? = render 'projects/merge_requests/widget/open/archived' + - elsif !@project.satellite.exists? + = render 'projects/merge_requests/widget/open/no_satellite' - elsif @merge_request.commits.blank? = render 'projects/merge_requests/widget/open/nothing' - elsif @merge_request.branch_missing? diff --git a/app/views/projects/merge_requests/widget/_show.html.haml b/app/views/projects/merge_requests/widget/_show.html.haml index a489d4f9b24..263cab7a9e8 100644 --- a/app/views/projects/merge_requests/widget/_show.html.haml +++ b/app/views/projects/merge_requests/widget/_show.html.haml @@ -11,10 +11,10 @@ var merge_request_widget; merge_request_widget = new MergeRequestWidget({ - url_to_automerge_check: "#{merge_check_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}", + url_to_automerge_check: "#{automerge_check_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}", check_enable: #{@merge_request.unchecked? ? "true" : "false"}, url_to_ci_check: "#{ci_status_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}", ci_enable: #{@project.ci_service ? "true" : "false"}, - current_status: "#{@merge_request.gitlab_merge_status}", + current_status: "#{@merge_request.automerge_status}", }); diff --git a/app/views/projects/merge_requests/widget/open/_accept.html.haml b/app/views/projects/merge_requests/widget/open/_accept.html.haml index 3c0cd25ba07..f5bacaf280a 100644 --- a/app/views/projects/merge_requests/widget/open/_accept.html.haml +++ b/app/views/projects/merge_requests/widget/open/_accept.html.haml @@ -1,4 +1,4 @@ -= form_for [:merge, @project.namespace.becomes(Namespace), @project, @merge_request], remote: true, method: :post, html: { class: 'accept-mr-form js-requires-input' } do |f| += form_for [:automerge, @project.namespace.becomes(Namespace), @project, @merge_request], remote: true, method: :post, html: { class: 'accept-mr-form js-requires-input' } do |f| = hidden_field_tag :authenticity_token, form_authenticity_token .accept-merge-holder.clearfix.js-toggle-container .accept-action diff --git a/app/views/projects/merge_requests/widget/open/_no_satellite.html.haml b/app/views/projects/merge_requests/widget/open/_no_satellite.html.haml new file mode 100644 index 00000000000..3718cfd8333 --- /dev/null +++ b/app/views/projects/merge_requests/widget/open/_no_satellite.html.haml @@ -0,0 +1,3 @@ +%p + %span + %strong This repository does not have a satellite. Please ask an administrator to fix this issue! diff --git a/app/workers/auto_merge_worker.rb b/app/workers/auto_merge_worker.rb new file mode 100644 index 00000000000..a6dd73eee5f --- /dev/null +++ b/app/workers/auto_merge_worker.rb @@ -0,0 +1,13 @@ +class AutoMergeWorker + include Sidekiq::Worker + + sidekiq_options queue: :default + + def perform(merge_request_id, current_user_id, params) + params = params.with_indifferent_access + current_user = User.find(current_user_id) + merge_request = MergeRequest.find(merge_request_id) + merge_request.should_remove_source_branch = params[:should_remove_source_branch] + merge_request.automerge!(current_user, params[:commit_message]) + end +end diff --git a/app/workers/merge_worker.rb b/app/workers/merge_worker.rb deleted file mode 100644 index 6a8665c179a..00000000000 --- a/app/workers/merge_worker.rb +++ /dev/null @@ -1,19 +0,0 @@ -class MergeWorker - include Sidekiq::Worker - - sidekiq_options queue: :default - - def perform(merge_request_id, current_user_id, params) - params = params.with_indifferent_access - current_user = User.find(current_user_id) - merge_request = MergeRequest.find(merge_request_id) - - result = MergeRequests::MergeService.new(merge_request.target_project, current_user). - execute(merge_request, params[:commit_message]) - - if result[:status] == :success && params[:should_remove_source_branch].present? - DeleteBranchService.new(merge_request.source_project, current_user). - execute(merge_request.source_branch) - end - end -end diff --git a/app/workers/repository_import_worker.rb b/app/workers/repository_import_worker.rb index b546f8777e1..94832872d13 100644 --- a/app/workers/repository_import_worker.rb +++ b/app/workers/repository_import_worker.rb @@ -27,6 +27,7 @@ class RepositoryImportWorker project.import_finish project.save + project.satellite.create unless project.satellite.exists? ProjectCacheWorker.perform_async(project.id) Gitlab::BitbucketImport::KeyDeleter.new(project).execute if project.import_type == 'bitbucket' end |