socialforge/app/helpers/pull_requests_helper.rb

85 lines
1.9 KiB
Ruby

module PullRequestsHelper
# 获取diff内容行号
def diff_line_num content
result = content.scan(/@@ -(\d+),\d+ \+\d+,\d+ @@/).first.nil? ? "" : content.scan(/@@ -(\d+),\d+ \+\d+,\d+ @@/).first.join("").to_i
end
# 处理内容
def diff_content content
result = content.gsub!(/.*@@.*@@\n/m,'')
end
def get_user_name user_id
User.find(user_id).try(:login)
end
# 获取接受PullRequest用户的信息
def accept_user pull_request_id
PullRequest.where(:pull_request_id => pull_request_id).first
end
# 通过gitlab项目id获取Trustie项目的用户名
def find_gitlab_project gitlab_project_id
Project.find_by_gpid(gitlab_project_id).owner.try(:show_name)
end
def get_state state
case state
when "open","reopened"
l(:label_state_open)
when "closed"
l(:label_state_closed)
when "merged"
l(:label_state_merged)
end
end
def type_count type, requests_opened_count, requests_merged_count, requests_closed_count
case type
when nil, "1"
requests_opened_count
when "2"
requests_merged_count
when "3"
requests_closed_count
end
end
# 获取pull request文件类型
def get_type_of_file change
if change['new_file']
"pullreques_icons_new"
elsif change['deleted_file']
"pullreques_icons_del"
else
"pullreques_icons_add"
end
end
# 判断是否允许创建Pull Request
# 如果分支相同,并且项目相同则提示
def judge_pr_allow
end
# 获取统计数
def request_commonts_count request_id, gpid
g = Gitlab.client
comments_count = g.merge_request_comments(gpid, request_id).count
end
# 通过状态获取样式
def pr_status_css status
case status
when "opened", "reopened"
"pullreques_blueicon"
when "merged"
"pullreques_greyicon"
when "closed"
"pullreques_greyicon02"
end
end
end