Commit 837b450c authored by Stan Hu's avatar Stan Hu

Merge branch 'ce-to-ee-2018-08-22' into 'master'

CE upstream - 2018-08-22 21:21 UTC

Closes gitlab-ce#49971

See merge request gitlab-org/gitlab-ee!6973
parents e02f4141 6be56fc8
...@@ -164,7 +164,7 @@ class GitPushService < BaseService ...@@ -164,7 +164,7 @@ class GitPushService < BaseService
end end
def process_default_branch def process_default_branch
offset = [push_commits_count - PROCESS_COMMIT_LIMIT, 0].max offset = [push_commits_count_for_ref - PROCESS_COMMIT_LIMIT, 0].max
@push_commits = project.repository.commits(params[:newrev], offset: offset, limit: PROCESS_COMMIT_LIMIT) @push_commits = project.repository.commits(params[:newrev], offset: offset, limit: PROCESS_COMMIT_LIMIT)
project.after_create_default_branch project.after_create_default_branch
...@@ -178,7 +178,7 @@ class GitPushService < BaseService ...@@ -178,7 +178,7 @@ class GitPushService < BaseService
params[:newrev], params[:newrev],
params[:ref], params[:ref],
@push_commits, @push_commits,
commits_count: push_commits_count) commits_count: commits_count)
end end
def push_to_existing_branch? def push_to_existing_branch?
...@@ -219,8 +219,14 @@ class GitPushService < BaseService ...@@ -219,8 +219,14 @@ class GitPushService < BaseService
end end
end end
def push_commits_count def commits_count
strong_memoize(:push_commits_count) do return push_commits_count_for_ref if default_branch? && push_to_new_branch?
Array(@push_commits).size
end
def push_commits_count_for_ref
strong_memoize(:push_commits_count_for_ref) do
project.repository.commit_count_for_ref(params[:ref]) project.repository.commit_count_for_ref(params[:ref])
end end
end end
......
---
title: Fix broken Git over HTTP clones with LDAP users
merge_request: 21352
author:
type: fixed
---
title: Fix wrong commit count in push event payload
merge_request: 21338
author:
type: fixed
...@@ -29,6 +29,7 @@ module Gitlab ...@@ -29,6 +29,7 @@ module Gitlab
def self.enabled?(name) def self.enabled?(name)
return true if name == 'database' return true if name == 'database'
return true if self.ldap_provider?(name) && providers.include?(name.to_sym)
Gitlab::Auth.omniauth_enabled? && providers.include?(name.to_sym) Gitlab::Auth.omniauth_enabled? && providers.include?(name.to_sym)
end end
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Auth::OAuth::Provider do describe Gitlab::Auth::OAuth::Provider do
describe '.enabled?' do
before do
allow(described_class).to receive(:providers).and_return([:ldapmain, :google_oauth2])
end
context 'when OmniAuth is disabled' do
before do
allow(Gitlab::Auth).to receive(:omniauth_enabled?).and_return(false)
end
it 'allows database auth' do
expect(described_class.enabled?('database')).to be_truthy
end
it 'allows LDAP auth' do
expect(described_class.enabled?('ldapmain')).to be_truthy
end
it 'does not allow other OmniAuth providers' do
expect(described_class.enabled?('google_oauth2')).to be_falsey
end
end
context 'when OmniAuth is enabled' do
before do
allow(Gitlab::Auth).to receive(:omniauth_enabled?).and_return(true)
end
it 'allows database auth' do
expect(described_class.enabled?('database')).to be_truthy
end
it 'allows LDAP auth' do
expect(described_class.enabled?('ldapmain')).to be_truthy
end
it 'allows other OmniAuth providers' do
expect(described_class.enabled?('google_oauth2')).to be_truthy
end
end
end
describe '#config_for' do describe '#config_for' do
context 'for an LDAP provider' do context 'for an LDAP provider' do
context 'when the provider exists' do context 'when the provider exists' do
......
...@@ -226,16 +226,37 @@ describe GitPushService do ...@@ -226,16 +226,37 @@ describe GitPushService do
end end
describe "Push Event" do describe "Push Event" do
let!(:push_data) { push_data_from_service(project, user, oldrev, newrev, ref) } context "with an existing branch" do
let(:event) { Event.find_by_action(Event::PUSHED) } let!(:push_data) { push_data_from_service(project, user, oldrev, newrev, ref) }
let(:event) { Event.find_by_action(Event::PUSHED) }
it { expect(event).to be_an_instance_of(PushEvent) } it 'generates a push event with one commit' do
it { expect(event.project).to eq(project) } expect(event).to be_an_instance_of(PushEvent)
it { expect(event.action).to eq(Event::PUSHED) } expect(event.project).to eq(project)
it { expect(event.push_event_payload).to be_an_instance_of(PushEventPayload) } expect(event.action).to eq(Event::PUSHED)
it { expect(event.push_event_payload.commit_from).to eq(oldrev) } expect(event.push_event_payload).to be_an_instance_of(PushEventPayload)
it { expect(event.push_event_payload.commit_to).to eq(newrev) } expect(event.push_event_payload.commit_from).to eq(oldrev)
it { expect(event.push_event_payload.ref).to eq('master') } expect(event.push_event_payload.commit_to).to eq(newrev)
expect(event.push_event_payload.ref).to eq('master')
expect(event.push_event_payload.commit_count).to eq(1)
end
end
context "with a new branch" do
let!(:new_branch_data) { push_data_from_service(project, user, Gitlab::Git::BLANK_SHA, newrev, ref) }
let(:event) { Event.find_by_action(Event::PUSHED) }
it 'generates a push event with more than one commit' do
expect(event).to be_an_instance_of(PushEvent)
expect(event.project).to eq(project)
expect(event.action).to eq(Event::PUSHED)
expect(event.push_event_payload).to be_an_instance_of(PushEventPayload)
expect(event.push_event_payload.commit_from).to be_nil
expect(event.push_event_payload.commit_to).to eq(newrev)
expect(event.push_event_payload.ref).to eq('master')
expect(event.push_event_payload.commit_count).to be > 1
end
end
context "Updates merge requests" do context "Updates merge requests" do
it "when pushing a new branch for the first time" do it "when pushing a new branch for the first time" do
...@@ -246,6 +267,7 @@ describe GitPushService do ...@@ -246,6 +267,7 @@ describe GitPushService do
end end
describe 'system hooks' do describe 'system hooks' do
let!(:push_data) { push_data_from_service(project, user, oldrev, newrev, ref) }
let(:system_hooks_service) { SystemHooksService.new } let(:system_hooks_service) { SystemHooksService.new }
it "sends a system hook after pushing a branch" do it "sends a system hook after pushing a branch" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment