Merge branch 'hide-recent-push' into 'master'
Only show recent push event if the branch still exists or a recent merge request has not been created Closes #2277 See merge request !1167
This commit is contained in:
commit
d43d7ffd6f
|
@ -1,6 +1,7 @@
|
|||
Please view this file on the master branch, on stable branches it's out of date.
|
||||
|
||||
v 8.0.0 (unreleased)
|
||||
- Only show recent push event if the branch still exists or a recent merge request has not been created (Stan Hu)
|
||||
- Remove satellites
|
||||
- Better performance for web editor (switched from satellites to rugged)
|
||||
- Faster merge
|
||||
|
|
|
@ -471,8 +471,19 @@ class User < ActiveRecord::Base
|
|||
events = recent_events.code_push.where("created_at > ?", Time.now - 2.hours)
|
||||
events = events.where(project_id: project_id) if project_id
|
||||
|
||||
# Take only latest one
|
||||
events = events.recent.limit(1).first
|
||||
# Use the latest event that has not been pushed or merged recently
|
||||
events.recent.find do |event|
|
||||
project = Project.find_by_id(event.project_id)
|
||||
next unless project
|
||||
repo = project.repository
|
||||
|
||||
if repo.branch_names.include?(event.branch_name)
|
||||
merge_requests = MergeRequest.where("created_at >= ?", event.created_at).
|
||||
where(source_project_id: project.id,
|
||||
source_branch: event.branch_name)
|
||||
merge_requests.empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def projects_sorted_by_activity
|
||||
|
|
|
@ -710,4 +710,33 @@ describe User do
|
|||
it { expect(subject.can_be_removed?).to be_falsey }
|
||||
end
|
||||
end
|
||||
|
||||
describe "#recent_push" do
|
||||
subject { create(:user) }
|
||||
let!(:project1) { create(:project) }
|
||||
let!(:project2) { create(:project, forked_from_project: project1) }
|
||||
let!(:push_data) { Gitlab::PushDataBuilder.build_sample(project2, subject) }
|
||||
let!(:push_event) { create(:event, action: Event::PUSHED, project: project2, target: project1, author: subject, data: push_data) }
|
||||
|
||||
before do
|
||||
project1.team << [subject, :master]
|
||||
project2.team << [subject, :master]
|
||||
end
|
||||
|
||||
it "includes push event" do
|
||||
expect(subject.recent_push).to eq(push_event)
|
||||
end
|
||||
|
||||
it "excludes push event if branch has been deleted" do
|
||||
allow_any_instance_of(Repository).to receive(:branch_names).and_return(['foo'])
|
||||
|
||||
expect(subject.recent_push).to eq(nil)
|
||||
end
|
||||
|
||||
it "excludes push event if MR is opened for it" do
|
||||
create(:merge_request, source_project: project2, target_project: project1, source_branch: project2.default_branch, target_branch: 'fix', author: subject)
|
||||
|
||||
expect(subject.recent_push).to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue