2012-06-25 17:04:43 +01:00
|
|
|
# -*- encoding : utf-8 -*-
|
|
|
|
module PullRequestHelper
|
2012-09-27 17:32:28 +01:00
|
|
|
def merge_activity comments, commits
|
2013-03-22 17:17:10 +00:00
|
|
|
common_comments, pull_comments = comments.partition {|c| c.automatic || c.data.blank?}
|
2012-10-15 17:33:16 +01:00
|
|
|
common_comments = common_comments.map{ |c| [c.created_at, c] }
|
|
|
|
pull_comments = pull_comments.group_by(&:data).map{|data, c| [c.first.created_at, [data || {}, [c].flatten]]}
|
|
|
|
commits = commits.map{ |c| [(c.committed_date || c.authored_date), c] }
|
|
|
|
(common_comments + pull_comments + commits).sort_by{ |c| c[0] }.map{ |c| c[1] }
|
2012-09-27 17:32:28 +01:00
|
|
|
end
|
|
|
|
|
2012-07-16 17:27:41 +01:00
|
|
|
def pull_status_label pull
|
2012-08-07 18:02:58 +01:00
|
|
|
statuses = {'ready' => 'success', 'closed' => 'important', 'merged' => 'important', 'blocked' => 'warning'}
|
2013-04-10 13:48:57 +01:00
|
|
|
content_tag :span, t("projects.pull_requests.statuses.#{pull.status}"), :class => "state label-bootstrap label-#{statuses[pull.status]}"
|
2012-07-16 17:27:41 +01:00
|
|
|
end
|
|
|
|
|
2012-06-25 17:04:43 +01:00
|
|
|
def pull_status pull
|
2012-07-18 19:02:27 +01:00
|
|
|
if %w(blocked merged closed ready open).include? pull.status
|
2012-10-03 12:36:04 +01:00
|
|
|
t("projects.pull_requests.#{pull.status}", :user => pull.issue.closer.try(:uname), :to_ref => show_ref(pull, 'to'),
|
|
|
|
:from_ref => show_ref(pull, 'from'), :time => pull.issue.closed_at).html_safe
|
2012-06-25 17:04:43 +01:00
|
|
|
else
|
|
|
|
raise "pull id (#{pull.id}) wrong status #{pull.status} "
|
|
|
|
end
|
|
|
|
end
|
2012-07-16 17:27:41 +01:00
|
|
|
|
|
|
|
def pull_header pull
|
2013-03-26 10:47:42 +00:00
|
|
|
str = "#{t '.header'} #{t 'from'} <span class='state label-bootstrap label-info font14'> \
|
2012-10-03 12:36:04 +01:00
|
|
|
#{show_ref pull, 'from'}</span> \
|
2012-09-28 16:49:10 +01:00
|
|
|
#{t 'into'} <span class='label-bootstrap label-info font14'> \
|
2012-10-03 12:36:04 +01:00
|
|
|
#{show_ref pull, 'to'}</span>"
|
2012-10-27 19:04:28 +01:00
|
|
|
str << " #{t 'by'} #{link_to pull.user.uname, user_path(pull.user)}" if pull.user# pull.persisted?
|
2012-07-16 17:27:41 +01:00
|
|
|
str.html_safe
|
|
|
|
end
|
2012-07-16 18:01:52 +01:00
|
|
|
|
|
|
|
#helper for helpers
|
|
|
|
def show_ref pull, which, limit = 30
|
2012-07-17 17:40:48 +01:00
|
|
|
project, ref = pull.send("#{which}_project"), pull.send("#{which}_ref")
|
2012-10-27 19:45:24 +01:00
|
|
|
fullname = if which == 'to'
|
2012-10-27 19:04:28 +01:00
|
|
|
"#{project.owner.uname.truncate limit}/#{project.name.truncate limit}"
|
|
|
|
elsif which == 'from'
|
|
|
|
"#{pull.from_project_owner_uname.truncate limit}/#{pull.from_project_name.truncate limit}"
|
|
|
|
end
|
|
|
|
link_to "#{fullname}: #{ref.truncate limit}", ref_path(project, ref)
|
2012-07-17 17:40:48 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def ref_path project, ref
|
2012-10-27 19:04:28 +01:00
|
|
|
if project && project.repo.branches_and_tags.map(&:name).include?(ref)
|
|
|
|
tree_path(project, ref)
|
|
|
|
else
|
|
|
|
'#'
|
|
|
|
end
|
2012-07-16 18:01:52 +01:00
|
|
|
end
|
2012-09-28 18:46:02 +01:00
|
|
|
|
|
|
|
def ref_selector_options(project, current)
|
|
|
|
res = []
|
2013-01-31 13:23:07 +00:00
|
|
|
value = Proc.new {|t| [t.name.truncate(50), t.name]}
|
2012-09-28 18:46:02 +01:00
|
|
|
res << [I18n.t('layout.git.repositories.branches'), project.repo.branches.map(&value)]
|
|
|
|
res << [I18n.t('layout.git.repositories.tags'), project.repo.tags.map(&value)]
|
|
|
|
|
|
|
|
grouped_options_for_select(res, current)
|
|
|
|
end
|
2012-07-17 17:40:48 +01:00
|
|
|
end
|