Prevent commits from upstream repositories to be re-processed by forks

This commit is contained in:
Felipe Artur 2017-05-18 17:17:58 -03:00
parent 258f578fc8
commit e44016b90a
3 changed files with 29 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,4 @@
---
title: Prevent commits from upstream repositories to be re-processed by forks
merge_request:
author:

View File

@ -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