| ... | @@ -4,6 +4,7 @@ require 'spec_helper' |
... | @@ -4,6 +4,7 @@ require 'spec_helper' |
|
|
|
|
|
|
|
describe Git::BranchHooksService do
|
|
describe Git::BranchHooksService do
|
|
|
include RepoHelpers
|
|
include RepoHelpers
|
|
|
|
include ProjectForksHelper
|
|
|
|
|
|
|
|
let(:project) { create(:project, :repository) }
|
|
let(:project) { create(:project, :repository) }
|
|
|
let(:user) { project.creator }
|
|
let(:user) { project.creator }
|
| ... | @@ -272,10 +273,10 @@ describe Git::BranchHooksService do |
... | @@ -272,10 +273,10 @@ describe Git::BranchHooksService do |
|
|
end
|
|
end
|
|
|
|
|
|
|
|
describe 'Processing commit messages' do
|
|
describe 'Processing commit messages' do
|
|
|
# Create 4 commits, 2 of which have references. Limiting to 2 commits, we
|
|
# Create 6 commits, 3 of which have references. Limiting to 4 commits, we
|
|
|
# expect to see one commit message processor enqueued.
|
|
# expect to see two commit message processors enqueued.
|
|
|
let(:commit_ids) do
|
|
let!(:commit_ids) do
|
|
|
Array.new(4) do |i|
|
|
Array.new(6) do |i|
|
|
|
message = "Issue #{'#' if i.even?}#{i}"
|
|
message = "Issue #{'#' if i.even?}#{i}"
|
|
|
project.repository.update_file(
|
|
project.repository.update_file(
|
|
|
user, 'README.md', '', message: message, branch_name: branch
|
|
user, 'README.md', '', message: message, branch_name: branch
|
| ... | @@ -283,18 +284,18 @@ describe Git::BranchHooksService do |
... | @@ -283,18 +284,18 @@ describe Git::BranchHooksService do |
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
let(:oldrev) { commit_ids.first }
|
|
let(:oldrev) { project.commit(commit_ids.first).parent_id }
|
|
|
let(:newrev) { commit_ids.last }
|
|
let(:newrev) { commit_ids.last }
|
|
|
|
|
|
|
|
before do
|
|
before do
|
|
|
stub_const("::Git::BaseHooksService::PROCESS_COMMIT_LIMIT", 2)
|
|
stub_const("::Git::BaseHooksService::PROCESS_COMMIT_LIMIT", 4)
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
context 'creating the default branch' do
|
|
context 'creating the default branch' do
|
|
|
let(:oldrev) { Gitlab::Git::BLANK_SHA }
|
|
let(:oldrev) { Gitlab::Git::BLANK_SHA }
|
|
|
|
|
|
|
|
it 'processes a limited number of commit messages' do
|
|
it 'processes a limited number of commit messages' do
|
|
|
expect(ProcessCommitWorker).to receive(:perform_async).once
|
|
expect(ProcessCommitWorker).to receive(:perform_async).twice
|
|
|
|
|
|
|
|
service.execute
|
|
service.execute
|
|
|
end
|
|
end
|
| ... | @@ -302,7 +303,7 @@ describe Git::BranchHooksService do |
... | @@ -302,7 +303,7 @@ describe Git::BranchHooksService do |
|
|
|
|
|
|
|
context 'updating the default branch' do
|
|
context 'updating the default branch' do
|
|
|
it 'processes a limited number of commit messages' do
|
|
it 'processes a limited number of commit messages' do
|
|
|
expect(ProcessCommitWorker).to receive(:perform_async).once
|
|
expect(ProcessCommitWorker).to receive(:perform_async).twice
|
|
|
|
|
|
|
|
service.execute
|
|
service.execute
|
|
|
end
|
|
end
|
| ... | @@ -323,7 +324,7 @@ describe Git::BranchHooksService do |
... | @@ -323,7 +324,7 @@ describe Git::BranchHooksService do |
|
|
let(:oldrev) { Gitlab::Git::BLANK_SHA }
|
|
let(:oldrev) { Gitlab::Git::BLANK_SHA }
|
|
|
|
|
|
|
|
it 'processes a limited number of commit messages' do
|
|
it 'processes a limited number of commit messages' do
|
|
|
expect(ProcessCommitWorker).to receive(:perform_async).once
|
|
expect(ProcessCommitWorker).to receive(:perform_async).twice
|
|
|
|
|
|
|
|
service.execute
|
|
service.execute
|
|
|
end
|
|
end
|
| ... | @@ -333,7 +334,7 @@ describe Git::BranchHooksService do |
... | @@ -333,7 +334,7 @@ describe Git::BranchHooksService do |
|
|
let(:branch) { 'fix' }
|
|
let(:branch) { 'fix' }
|
|
|
|
|
|
|
|
it 'processes a limited number of commit messages' do
|
|
it 'processes a limited number of commit messages' do
|
|
|
expect(ProcessCommitWorker).to receive(:perform_async).once
|
|
expect(ProcessCommitWorker).to receive(:perform_async).twice
|
|
|
|
|
|
|
|
service.execute
|
|
service.execute
|
|
|
end
|
|
end
|
| ... | @@ -349,6 +350,55 @@ describe Git::BranchHooksService do |
... | @@ -349,6 +350,55 @@ describe Git::BranchHooksService do |
|
|
service.execute
|
|
service.execute
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
context 'when the project is forked' do
|
|
|
|
let(:upstream_project) { project }
|
|
|
|
let(:forked_project) { fork_project(upstream_project, user, repository: true) }
|
|
|
|
|
|
|
|
let!(:forked_service) do
|
|
|
|
described_class.new(forked_project, user, oldrev: oldrev, newrev: newrev, ref: ref)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when commits already exists in the upstream project' do
|
|
|
|
it 'does not process commit messages' do
|
|
|
|
expect(ProcessCommitWorker).not_to receive(:perform_async)
|
|
|
|
|
|
|
|
forked_service.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a commit does not exist in the upstream repo' do
|
|
|
|
# On top of the existing 6 commits, 3 of which have references,
|
|
|
|
# create 2 more, 1 of which has a reference. Limiting to 4 commits, we
|
|
|
|
# expect to see one commit message processor enqueued.
|
|
|
|
let!(:forked_commit_ids) do
|
|
|
|
Array.new(2) do |i|
|
|
|
|
message = "Issue #{'#' if i.even?}#{i}"
|
|
|
|
forked_project.repository.update_file(
|
|
|
|
user, 'README.md', '', message: message, branch_name: branch
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:newrev) { forked_commit_ids.last }
|
|
|
|
|
|
|
|
it 'processes the commit message' do
|
|
|
|
expect(ProcessCommitWorker).to receive(:perform_async).once
|
|
|
|
|
|
|
|
forked_service.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the upstream project no longer exists' do
|
|
|
|
it 'processes the commit messages' do
|
|
|
|
upstream_project.destroy!
|
|
|
|
|
|
|
|
expect(ProcessCommitWorker).to receive(:perform_async).twice
|
|
|
|
|
|
|
|
forked_service.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
describe 'New branch detection' do
|
|
describe 'New branch detection' do
|
| ... | |
... | |
| ... | | ... | |