diff options
author | Sean McGivern <sean@gitlab.com> | 2018-07-10 19:11:31 +0300 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2018-07-10 19:11:31 +0300 |
commit | 5b0210a0c8db13b6e538dfea7bc07d090224bbca (patch) | |
tree | 08b56fdda44762bab34bdc6ea5e4879e23e6b77a | |
parent | 49d7f92fd7476b4fb10e44ff92f36be99de0df49 (diff) |
Fix ProcessCommitWorker when upstream project is deleted
3 files changed, 42 insertions, 8 deletions
diff --git a/app/workers/process_commit_worker.rb b/app/workers/process_commit_worker.rb index ed39b4a1ea8..c9f6df9b56d 100644 --- a/app/workers/process_commit_worker.rb +++ b/app/workers/process_commit_worker.rb @@ -79,9 +79,10 @@ class ProcessCommitWorker # Avoid reprocessing commits that already exist 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.fork_source + + return false unless upstream_project - upstream_project = project.forked_from_project commit_id = commit_hash.with_indifferent_access[:id] upstream_project.commit(commit_id).present? end diff --git a/changelogs/unreleased/45592-nomethoderror-undefined-method-commit-for-nil-nilclass-in-sidekiq-caused-by-a-merge-commit-in-a-forked-project-with-upstream-project-deleted.yml b/changelogs/unreleased/45592-nomethoderror-undefined-method-commit-for-nil-nilclass-in-sidekiq-caused-by-a-merge-commit-in-a-forked-project-with-upstream-project-deleted.yml new file mode 100644 index 00000000000..6994a238074 --- /dev/null +++ b/changelogs/unreleased/45592-nomethoderror-undefined-method-commit-for-nil-nilclass-in-sidekiq-caused-by-a-merge-commit-in-a-forked-project-with-upstream-project-deleted.yml @@ -0,0 +1,5 @@ +--- +title: Process commits as normal in forks when the upstream project is deleted +merge_request: 20534 +author: +type: fixed diff --git a/spec/workers/process_commit_worker_spec.rb b/spec/workers/process_commit_worker_spec.rb index ac79d9c0ac1..2d071c181c2 100644 --- a/spec/workers/process_commit_worker_spec.rb +++ b/spec/workers/process_commit_worker_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' describe ProcessCommitWorker do + include ProjectForksHelper + let(:worker) { described_class.new } let(:user) { create(:user) } let(:project) { create(:project, :public, :repository) } @@ -32,15 +34,41 @@ 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, :repository) } + context 'when the project is forked' do + context 'when commit already exists in the upstream project' do + it 'does not process the commit message' do + forked = fork_project(project, user, repository: true) + + expect(worker).not_to receive(:process_commit_message) + + worker.perform(forked.id, user.id, forked.commit.to_hash) + end + end + + context 'when the commit does not exist in the upstream project' do + it 'processes the commit message' do + empty_project = create(:project, :public) + forked = fork_project(empty_project, user, repository: true) + + TestEnv.copy_repo(forked, + bare_repo: TestEnv.factory_repo_path_bare, + refs: TestEnv::BRANCH_SHA) + + expect(worker).to receive(:process_commit_message) + + worker.perform(forked.id, user.id, forked.commit.to_hash) + end + end - it 'does not process commit message' do - create(:forked_project_link, forked_to_project: forked, forked_from_project: project) + context 'when the upstream project no longer exists' do + it 'processes the commit message' do + forked = fork_project(project, user, repository: true) + project.destroy! - expect(worker).not_to receive(:process_commit_message) + expect(worker).to receive(:process_commit_message) - worker.perform(forked.id, user.id, forked.commit.to_hash) + worker.perform(forked.id, user.id, forked.commit.to_hash) + end end end end |