Class: PostReceiveService
- Inherits:
-
Object
- Object
- PostReceiveService
- Defined in:
- app/services/post_receive_service.rb
Overview
PostReceiveService class
Used for scheduling related jobs after a push action has been performed
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(user, repository, project, params) ⇒ PostReceiveService
constructor
A new instance of PostReceiveService.
- #merge_request_urls ⇒ Object
- #process_mr_push_options(push_options, changes) ⇒ Object
- #push_options_warning(warning) ⇒ Object
Constructor Details
#initialize(user, repository, project, params) ⇒ PostReceiveService
Returns a new instance of PostReceiveService.
9 10 11 12 13 14 |
# File 'app/services/post_receive_service.rb', line 9 def initialize(user, repository, project, params) @user = user @repository = repository @project = project @params = params end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
7 8 9 |
# File 'app/services/post_receive_service.rb', line 7 def params @params end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
7 8 9 |
# File 'app/services/post_receive_service.rb', line 7 def project @project end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
7 8 9 |
# File 'app/services/post_receive_service.rb', line 7 def repository @repository end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
7 8 9 |
# File 'app/services/post_receive_service.rb', line 7 def user @user end |
Instance Method Details
#execute ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/services/post_receive_service.rb', line 16 def execute response = Gitlab::InternalPostReceive::Response.new = Gitlab::PushOptions.new(params[:push_options]) = .get(:merge_request) response.reference_counter_decreased = Gitlab::ReferenceCounter.new(params[:gl_repository]).decrease # The PostReceive worker will normally invalidate the cache. However, it # runs asynchronously. If push options require us to create a new merge # request synchronously, we can't rely on that, so invalidate the cache here repository&.expire_branches_cache if &.fetch(:create, false) PostReceive.perform_async(params[:gl_repository], params[:identifier], params[:changes], .as_json) if .present? = (, params[:changes]) response.() end response.() response.add_merge_request_urls(merge_request_urls) # Neither User nor Repository are guaranteed to be returned; an orphaned write deploy # key could be used if user && repository = Gitlab::Checks::ContainerMoved.(user, repository) = Gitlab::Checks::ProjectCreated.(user, repository) response.() response.() record_onboarding_progress end response end |
#merge_request_urls ⇒ Object
77 78 79 80 81 |
# File 'app/services/post_receive_service.rb', line 77 def merge_request_urls return [] unless repository&.repo_type&.project? ::MergeRequests::GetUrlsService.new(project: project).execute(params[:changes]) end |
#process_mr_push_options(push_options, changes) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/services/post_receive_service.rb', line 55 def (, changes) Gitlab::QueryLimiting.disable!('https://gitlab.com/gitlab-org/gitlab/-/issues/28494') return unless repository unless repository.repo_type.project? return ('Push options are only supported for projects') end service = ::MergeRequests::PushOptionsHandlerService.new( project: project, current_user: user, changes: changes, push_options: ).execute if service.errors.present? (service.errors.join("\n\n")) end end |
#push_options_warning(warning) ⇒ Object
72 73 74 75 |
# File 'app/services/post_receive_service.rb', line 72 def (warning) = Array.wrap(params[:push_options]).map { |p| "'#{p}'" }.join(' ') "WARNINGS:\nError encountered with push options #{}: #{warning}" end |