Merge branch '45592-nomethoderror-undefined-method-commit-for-nil-nilclass-in-sidekiq-caused-by-a-merge-commit-in-a-forked-project-with-upstream-project-deleted' into 'master'
Resolve "NoMethodError: undefined method `commit' for nil:NilClass in sidekiq caused by a merge commit in a forked project with upstream project deleted." Closes #45592 See merge request gitlab-org/gitlab-ce!20534
This commit is contained in:
commit
6d8c262593
3 changed files with 42 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Process commits as normal in forks when the upstream project is deleted
|
||||
merge_request: 20534
|
||||
author:
|
||||
type: fixed
|
|
@ -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,17 +34,43 @@ 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) }
|
||||
|
||||
it 'does not process commit message' do
|
||||
create(:forked_project_link, forked_to_project: forked, forked_from_project: project)
|
||||
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
|
||||
|
||||
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).to receive(:process_commit_message)
|
||||
|
||||
worker.perform(forked.id, user.id, forked.commit.to_hash)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#process_commit_message' do
|
||||
|
|
Loading…
Reference in a new issue