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 /app/workers | |
parent | 258f578fc8d58b3e343664ca59ab0df0d14057f0 (diff) | |
download | gitlab-ce-e44016b90ad900836b2cbc83ebb9f58c39b3576a.tar.gz |
Prevent commits from upstream repositories to be re-processed by forks
Diffstat (limited to 'app/workers')
-rw-r--r-- | app/workers/process_commit_worker.rb | 13 |
1 files changed, 13 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 |