Commit e44016b9 authored by Felipe Artur's avatar Felipe Artur

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

parent 258f578f
......@@ -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
---
title: Prevent commits from upstream repositories to be re-processed by forks
merge_request:
author:
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment