From 9d938fd77da033f09530571a6194609aee8bbc7b Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 17 Mar 2015 15:51:14 +0100 Subject: [PATCH] List new commits for newly pushed branch in activity view. --- CHANGELOG | 1 + app/helpers/events_helper.rb | 2 +- app/models/event.rb | 2 +- app/views/events/event/_push.html.haml | 10 ++++++++-- lib/gitlab/push_data_builder.rb | 15 +++++++-------- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 09b60e8e54a..23a48375b45 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ Please view this file on the master branch, on stable branches it's out of date. v 7.10.0 (unreleased) - Add a service to support external wikis (Hannes Rosenögger) + - List new commits for newly pushed branch in activity view. v 7.9.0 (unreleased) - Add HipChat integration documentation (Stan Hu) diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb index 779cebc0136..c9fd0f0362b 100644 --- a/app/helpers/events_helper.rb +++ b/app/helpers/events_helper.rb @@ -96,7 +96,7 @@ module EventsHelper end end elsif event.push? - if event.push_with_commits? + if event.push_with_commits? && event.md_ref? if event.commits_count > 1 namespace_project_compare_url(event.project.namespace, event.project, from: event.commit_from, to: diff --git a/app/models/event.rb b/app/models/event.rb index 8d20d7ef252..2103a48a71b 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -247,7 +247,7 @@ class Event < ActiveRecord::Base end def push_with_commits? - md_ref? && commits.any? && commit_from && commit_to + !commits.empty? && commit_from && commit_to end def last_push_to_non_root? diff --git a/app/views/events/event/_push.html.haml b/app/views/events/event/_push.html.haml index 489138887ae..60d7978b13f 100644 --- a/app/views/events/event/_push.html.haml +++ b/app/views/events/event/_push.html.haml @@ -21,5 +21,11 @@ %li.commits-stat - if event.commits_count > 2 %span ... and #{event.commits_count - 2} more commits. - = link_to namespace_project_compare_path(event.project.namespace, event.project, from: event.commit_from, to: event.commit_to) do - %strong Compare → #{truncate_sha(event.commit_from)}...#{truncate_sha(event.commit_to)} + - if event.md_ref? + - from = event.commit_from + - from_label = truncate_sha(from) + - else + - from = event.project.default_branch + - from_label = from + = link_to namespace_project_compare_path(event.project.namespace, event.project, from: from, to: event.commit_to) do + %strong Compare → #{from_label}...#{truncate_sha(event.commit_to)} diff --git a/lib/gitlab/push_data_builder.rb b/lib/gitlab/push_data_builder.rb index ea9012b8844..694a30db5df 100644 --- a/lib/gitlab/push_data_builder.rb +++ b/lib/gitlab/push_data_builder.rb @@ -27,6 +27,12 @@ module Gitlab # Get latest 20 commits ASC commits_limited = commits.last(20) + + # For performance purposes maximum 20 latest commits + # will be passed as post receive hook data. + commit_attrs = commits_limited.map do |commit| + commit.hook_attrs(project) + end type = Gitlab::Git.tag_ref?(ref) ? "tag_push" : "push" # Hash to be passed as post_receive_data @@ -49,17 +55,10 @@ module Gitlab git_ssh_url: project.ssh_url_to_repo, visibility_level: project.visibility_level }, - commits: [], + commits: commit_attrs, total_commits_count: commits_count } - # For performance purposes maximum 20 latest commits - # will be passed as post receive hook data. - commits_limited.each do |commit| - data[:commits] << commit.hook_attrs(project) - end - - data[:commits] = "" if data[:commits].count == 0 data end