diff options
author | Felipe Artur <felipefac@gmail.com> | 2017-05-18 17:17:58 -0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2017-05-22 17:43:27 -0300 |
commit | e44016b90ad900836b2cbc83ebb9f58c39b3576a (patch) | |
tree | c6d2b8f007846d557fd8dc2a408f984e69c0d416 | |
parent | 258f578fc8d58b3e343664ca59ab0df0d14057f0 (diff) | |
download | gitlab-ce-e44016b90ad900836b2cbc83ebb9f58c39b3576a.tar.gz |
Prevent commits from upstream repositories to be re-processed by forks
-rw-r--r-- | app/workers/process_commit_worker.rb | 13 | ||||
-rw-r--r-- | changelogs/unreleased/issue_19262.yml | 4 | ||||
-rw-r--r-- | spec/workers/process_commit_worker_spec.rb | 12 |
3 files changed, 29 insertions, 0 deletions
diff --git a/app/workers/process_commit_worker.rb b/app/workers/process_commit_worker.rb index d6ed0e253ad..8b192aa74c6 100644 --- a/app/workers/process_commit_worker.rb +++ b/app/workers/process_commit_worker.rb @@ -17,6 +17,7 @@ class ProcessCommitWorker project = Project.find_by(id: project_id) return unless project + return if commit_exists_in_upstream?(project, commit_hash) user = User.find_by(id: user_id) @@ -76,4 +77,16 @@ class ProcessCommitWorker Commit.from_hash(hash, project) end + + private + + # Avoid to re-process commits messages that already exists in the upstream + # when project is forked. This will also prevent duplicated system notes. + def commit_exists_in_upstream?(project, commit_hash) + return false unless project.forked? + + upstream_project = project.forked_from_project + commit_id = commit_hash.with_indifferent_access[:id] + upstream_project.commit(commit_id).present? + end end diff --git a/changelogs/unreleased/issue_19262.yml b/changelogs/unreleased/issue_19262.yml new file mode 100644 index 00000000000..7bcbc647fcb --- /dev/null +++ b/changelogs/unreleased/issue_19262.yml @@ -0,0 +1,4 @@ +--- +title: Prevent commits from upstream repositories to be re-processed by forks +merge_request: +author: diff --git a/spec/workers/process_commit_worker_spec.rb b/spec/workers/process_commit_worker_spec.rb index 6295856b461..12b6d567b8e 100644 --- a/spec/workers/process_commit_worker_spec.rb +++ b/spec/workers/process_commit_worker_spec.rb @@ -39,6 +39,18 @@ describe ProcessCommitWorker do worker.perform(project.id, user.id, commit.to_hash) end + + context 'when commit already exists in upstream project' do + let(:forked) { create(:project, :public) } + + it 'does not process commit message' do + create(:forked_project_link, forked_to_project: forked, forked_from_project: project) + + expect(worker).not_to receive(:process_commit_message) + + worker.perform(forked.id, user.id, forked.commit.to_hash) + end + end end describe '#process_commit_message' do |