diff options
author | Stan Hu <stanhu@gmail.com> | 2015-08-16 18:05:53 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2015-08-20 01:38:15 -0700 |
commit | 98eb89be5d2df31c31812e670f058afc0454c865 (patch) | |
tree | afc4fb0d97a3d356b65d997dcdd8590d32fdc435 | |
parent | 55fc58bda4a5592f2f8deaecec9526fbe4eecd6f (diff) | |
download | gitlab-ce-98eb89be5d2df31c31812e670f058afc0454c865.tar.gz |
Only show recent push event if the branch still exists or a recent merge request has not been created
Closes #2277
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/models/user.rb | 15 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 29 |
3 files changed, 43 insertions, 2 deletions
diff --git a/CHANGELOG b/CHANGELOG index 8214e57aaa7..927f547bdae 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 57145cc6b6e..f70761074c5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 876cfb1204a..a46e789eab4 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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 |