Skip to content
Snippets Groups Projects
Commit e5e3dc2e authored by Felipe Artur's avatar Felipe Artur
Browse files

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

parent 258f578f
No related branches found
No related tags found
No related merge requests found
Pipeline #
Loading
Loading
@@ -16,7 +16,7 @@ class ProcessCommitWorker
def perform(project_id, user_id, commit_hash, default = false)
project = Project.find_by(id: project_id)
 
return unless project
return if project.nil? || commit_exists_in_upstream?(project, commit_hash)
 
user = User.find_by(id: user_id)
 
Loading
Loading
@@ -76,4 +76,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:
Loading
Loading
@@ -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
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment