Class: ExternalPullRequest
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ExternalPullRequest
- Includes:
- Gitlab::Utils::StrongMemoize, ShaAttribute
- Defined in:
- app/models/external_pull_request.rb
Overview
This model stores pull requests coming from external providers, such as GitHub, when GitLab project is set as CI/CD only and remote mirror.
When setting up a remote mirror with GitHub we subscribe to push and pull_request webhook events. When a pull request is opened on GitHub, a webhook is sent out, we create or update the status of the pull request locally.
When the mirror is updated and changes are pushed to branches we check if there are open pull requests for the source and target branch. If so, we create pipelines for external pull requests.
Class Method Summary collapse
Instance Method Summary collapse
- #actual_branch_head? ⇒ Boolean
- #from_fork? ⇒ Boolean
- #predefined_variables ⇒ Object
- #source_ref ⇒ Object
Methods included from Gitlab::Utils::StrongMemoize
#clear_memoization, #strong_memoize, #strong_memoized?
Methods inherited from ApplicationRecord
at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, where_exists, with_fast_statement_timeout, without_order
Class Method Details
.create_or_update_from_params(params) ⇒ Object
43 44 45 46 47 48 49 |
# File 'app/models/external_pull_request.rb', line 43 def self.create_or_update_from_params(params) find_params = params.slice(:project_id, :source_branch, :target_branch) safe_find_or_initialize_and_update(find: find_params, update: params) do |pull_request| yield(pull_request) if block_given? end end |
Instance Method Details
#actual_branch_head? ⇒ Boolean
51 52 53 |
# File 'app/models/external_pull_request.rb', line 51 def actual_branch_head? actual_source_branch_sha == source_sha end |
#from_fork? ⇒ Boolean
55 56 57 |
# File 'app/models/external_pull_request.rb', line 55 def from_fork? source_repository != target_repository end |
#predefined_variables ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/models/external_pull_request.rb', line 63 def predefined_variables Gitlab::Ci::Variables::Collection.new.tap do |variables| variables.append(key: 'CI_EXTERNAL_PULL_REQUEST_IID', value: pull_request_iid.to_s) variables.append(key: 'CI_EXTERNAL_PULL_REQUEST_SOURCE_REPOSITORY', value: source_repository) variables.append(key: 'CI_EXTERNAL_PULL_REQUEST_TARGET_REPOSITORY', value: target_repository) variables.append(key: 'CI_EXTERNAL_PULL_REQUEST_SOURCE_BRANCH_SHA', value: source_sha) variables.append(key: 'CI_EXTERNAL_PULL_REQUEST_TARGET_BRANCH_SHA', value: target_sha) variables.append(key: 'CI_EXTERNAL_PULL_REQUEST_SOURCE_BRANCH_NAME', value: source_branch) variables.append(key: 'CI_EXTERNAL_PULL_REQUEST_TARGET_BRANCH_NAME', value: target_branch) end end |
#source_ref ⇒ Object
59 60 61 |
# File 'app/models/external_pull_request.rb', line 59 def source_ref Gitlab::Git::BRANCH_REF_PREFIX + source_branch end |