rosa-build/app/helpers/pull_request_helper.rb

53 lines
2.1 KiB
Ruby
Raw Normal View History

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
issue_comments = @issue.comments.map{ |c| [c.created_at, c] }
commits = @commits.map{ |c| [(c.committed_date || c.authored_date), c] }
(issue_comments + commits).sort_by{ |c| c[0] }.map{ |c| c[1] }
end
2012-07-16 17:27:41 +01:00
def pull_status_label pull
statuses = {'ready' => 'success', 'closed' => 'important', 'merged' => 'important', 'blocked' => 'warning'}
content_tag :span, t("projects.pull_requests.statuses.#{pull.status}"), :class => "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
t("projects.pull_requests.#{pull.status}", :user => pull.issue.closer.try(:uname), :base_ref => show_ref(pull, 'base'),
:head_ref => show_ref(pull, 'head'), :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
2012-09-28 16:49:10 +01:00
str = "#{t '.header'} #{t 'from'} <span class='label-bootstrap label-info font14'> \
#{show_ref pull, 'head'}</span> \
#{t 'into'} <span class='label-bootstrap label-info font14'> \
#{show_ref pull, 'base'}</span>"
2012-07-16 17:27:41 +01:00
str << " #{t 'by'} #{link_to pull.user.uname, user_path(pull.user)}" if pull.persisted?
str.html_safe
end
#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")
link_to "#{project.owner.uname.truncate limit}/#{project.name.truncate limit}: #{ref.truncate limit}", ref_path(project, ref)
2012-07-17 17:40:48 +01:00
end
def ref_path project, ref
return tree_path(project, ref) if project.repo.branches_and_tags.map(&:name).include? ref
return commit_path(project, ref) if project.repo.commit ref
2012-07-17 17:40:48 +01:00
'#'
end
2012-09-28 18:46:02 +01:00
def ref_selector_options(project, current)
res = []
value = Proc.new {|t| [t.name.truncate(40)]}
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