rosa-build/app/helpers/pull_request_helper.rb

47 lines
1.6 KiB
Ruby
Raw Normal View History

2012-06-25 17:04:43 +01:00
# -*- encoding : utf-8 -*-
module PullRequestHelper
2012-07-16 17:27:41 +01:00
def pull_status_label pull
label = case pull.status
when 'ready'
'success'
when 'closed', 'merged'
'important'
when 'blocked'
'warning'
end
"<span class='label-bootstrap label-#{label}'>#{t "projects.pull_requests.statuses.#{pull.status}"}</span>".html_safe
end
2012-06-25 17:04:43 +01:00
def pull_status pull
2012-07-10 17:58:39 +01:00
if %w(blocked merged closed ready).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
str = "#{t '.header'} #{t 'into'} <span class='label-bootstrap label-info font14'> \
#{show_ref pull, 'base'}</span> \
2012-07-16 17:27:41 +01:00
#{t 'from'} <span class='label-bootstrap label-info font14'> \
#{show_ref pull, 'head'}</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")
name = "#{project.owner.uname.truncate limit}: #{ref.truncate limit}"
link_to name, ref_path(project, ref)
end
def ref_path project, ref
2012-07-18 12:17:15 +01:00
return tree_path(project, ref) if project.branches_and_tags.map(&:name).include? ref
2012-07-17 17:40:48 +01:00
return commit_path(project, ref) if project.git_repository.commit ref
'#'
end
2012-07-17 17:40:48 +01:00
end