socialforge/app/helpers/pull_requests_helper.rb

85 lines
1.9 KiB
Ruby
Raw Normal View History

module PullRequestsHelper
2016-08-03 15:56:07 +08:00
# 获取diff内容行号
def diff_line_num content
2016-11-25 17:50:37 +08:00
result = content.scan(/@@ -(\d+),\d+ \+\d+,\d+ @@/).first.nil? ? "" : content.scan(/@@ -(\d+),\d+ \+\d+,\d+ @@/).first.join("").to_i
2016-08-03 15:56:07 +08:00
end
# 处理内容
def diff_content content
2016-11-25 17:50:37 +08:00
result = content.gsub!(/.*@@.*@@\n/m,'')
2016-08-03 15:56:07 +08:00
end
2016-08-04 18:30:04 +08:00
def get_user_name user_id
User.find(user_id).try(:login)
end
2016-08-10 16:49:48 +08:00
# 获取接受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
2016-08-08 15:23:55 +08:00
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
2016-08-09 15:28:06 +08:00
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
2016-10-26 15:40:44 +08:00
# 获取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
2016-08-11 15:19:58 +08:00
# 判断是否允许创建Pull Request
# 如果分支相同,并且项目相同则提示
def judge_pr_allow
end
# 获取统计数
2016-10-21 14:18:34 +08:00
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