diff options
author | Matija Čupić <matteeyah@gmail.com> | 2018-01-05 20:04:33 +0100 |
---|---|---|
committer | Matija Čupić <matteeyah@gmail.com> | 2018-01-05 20:04:33 +0100 |
commit | b058af1be6aad166fbab2809bb8430bc90b4896f (patch) | |
tree | 6266e653a231e19a966693a7c1da7e07f6019978 /app/services | |
parent | 12984a73029408ef4ca10446131613e9ac371eb9 (diff) | |
parent | 3d162d192ba2a57776de62b553a2a0a9a9245f8a (diff) | |
download | gitlab-ce-b058af1be6aad166fbab2809bb8430bc90b4896f.tar.gz |
Merge branch 'master' into 39957-redirect-to-gpc-page-if-users-try-to-create-a-cluster-but-the-account-is-not-enabled
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/merge_requests/rebase_service.rb | 30 | ||||
-rw-r--r-- | app/services/merge_requests/working_copy_base_service.rb | 24 |
2 files changed, 54 insertions, 0 deletions
diff --git a/app/services/merge_requests/rebase_service.rb b/app/services/merge_requests/rebase_service.rb new file mode 100644 index 00000000000..0d5a25fa28e --- /dev/null +++ b/app/services/merge_requests/rebase_service.rb @@ -0,0 +1,30 @@ +module MergeRequests + class RebaseService < MergeRequests::WorkingCopyBaseService + def execute(merge_request) + @merge_request = merge_request + + if rebase + success + else + error('Failed to rebase. Should be done manually') + end + end + + def rebase + if merge_request.rebase_in_progress? + log_error('Rebase task canceled: Another rebase is already in progress', save_message_on_model: true) + return false + end + + rebase_sha = repository.rebase(current_user, merge_request) + + merge_request.update_attributes(rebase_commit_sha: rebase_sha) + + true + rescue => e + log_error('Failed to rebase branch:') + log_error(e.message, save_message_on_model: true) + false + end + end +end diff --git a/app/services/merge_requests/working_copy_base_service.rb b/app/services/merge_requests/working_copy_base_service.rb new file mode 100644 index 00000000000..186e05bf966 --- /dev/null +++ b/app/services/merge_requests/working_copy_base_service.rb @@ -0,0 +1,24 @@ +module MergeRequests + class WorkingCopyBaseService < MergeRequests::BaseService + attr_reader :merge_request + + def source_project + @source_project ||= merge_request.source_project + end + + def target_project + @target_project ||= merge_request.target_project + end + + def log_error(message, save_message_on_model: false) + Gitlab::GitLogger.error("#{self.class.name} error (#{merge_request.to_reference(full: true)}): #{message}") + + merge_request.update(merge_error: message) if save_message_on_model + end + + # Don't try to print expensive instance variables. + def inspect + "#<#{self.class} #{merge_request.to_reference(full: true)}>" + end + end +end |