Class: Ci::ExternalPullRequest
Constant Summary
ApplicationRecord::MAX_PLUCK
HasCheckConstraints::NOT_NULL_CHECK_PATTERN
ResetOnColumnErrors::MAX_RESET_PERIOD
Class Method Summary
collapse
Instance Method Summary
collapse
model_name, table_name_prefix
===, cached_column_list, #create_or_load_association, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
#sharding_organization
#reset_on_union_error, #reset_on_unknown_attribute_error
#serializable_hash
Class Method Details
.create_or_update_from_params(params) ⇒ Object
48
49
50
51
52
53
54
|
# File 'app/models/ci/external_pull_request.rb', line 48
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
|
.safe_find_or_initialize_and_update(find:, update:) ⇒ Object
56
57
58
59
60
61
62
63
64
|
# File 'app/models/ci/external_pull_request.rb', line 56
def self.safe_find_or_initialize_and_update(find:, update:)
safe_ensure_unique(retries: 1) do
model = find_or_initialize_by(find)
yield(model) if model.update(update) && block_given?
model
end
end
|
Instance Method Details
#actual_branch_head? ⇒ Boolean
66
67
68
|
# File 'app/models/ci/external_pull_request.rb', line 66
def actual_branch_head?
actual_source_branch_sha == source_sha
end
|
#changed_paths ⇒ Object
94
95
96
97
|
# File 'app/models/ci/external_pull_request.rb', line 94
def changed_paths
project.repository.find_changed_paths([Gitlab::Git::DiffTree.new(target_sha, source_sha)],
merge_commit_diff_mode: :all_parents)
end
|
#from_fork? ⇒ Boolean
70
71
72
|
# File 'app/models/ci/external_pull_request.rb', line 70
def from_fork?
source_repository != target_repository
end
|
#modified_paths ⇒ Object
90
91
92
|
# File 'app/models/ci/external_pull_request.rb', line 90
def modified_paths
project.repository.diff_stats(target_sha, source_sha).paths
end
|
#predefined_variables ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
|
# File 'app/models/ci/external_pull_request.rb', line 78
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
74
75
76
|
# File 'app/models/ci/external_pull_request.rb', line 74
def source_ref
Gitlab::Git::BRANCH_REF_PREFIX + source_branch
end
|