[#19] support # for pull request too

This commit is contained in:
Alexander Machehin 2013-04-10 01:55:32 +06:00
parent f7cd301479
commit 24ad1485a6
3 changed files with 17 additions and 25 deletions

View File

@ -29,10 +29,10 @@ en:
reference_format: Reference Format
reference_format_example: |
for members: @abf
for issues:
#123 abf#123 abf/rosa-build#123
for pull requests:
!123 abf!123 abf/rosa-build!123
for issues and pull requests:
#123
abf#123
abf/rosa-build#123
for commits: 123456
issues: Issues

View File

@ -29,10 +29,10 @@ ru:
reference_format: Формат ссылок
reference_format_example: |
для участников: @abf
для задач:
#123 abf#123 abf/rosa-build#123
для пул реквестов:
!123 abf!123 abf/rosa-build!123
для задач и пул реквестов:
#123
abf#123
abf/rosa-build#123
для коммитов: 123456
issues: Задачи
pull_requests: Пул реквесты

View File

@ -9,14 +9,10 @@ module Modules
#
# Supported reference formats are:
# * @foo for team members
# * for issues:
# * for issues & pull requests:
# * #123
# * abf#123
# * abf/rosa-build#123
# * for pull requests:
# * !123
# * abf!123
# * abf/rosa-build!123
# * 123456 for commits
#
# It also parses Emoji codes to insert images. See
@ -106,13 +102,12 @@ module Modules
( # Reference
@(?<user>[a-zA-Z][a-zA-Z0-9_\-\.]*) # User uname
|(?<issue>(?:[a-zA-Z0-9\-_]*\/)?(?:[a-zA-Z0-9\-_]*)?\#[0-9]+) # Issue ID
|(?<pull_request>(?:[a-zA-Z0-9\-_]*\/)?(?:[a-zA-Z0-9\-_]*)?\![0-9]+) # PR ID
|(?<commit>[\h]{6,40}) # Commit ID
)
(?<suffix>\W)? # Suffix
}x.freeze
TYPES = [:user, :issue, :pull_request, :commit].freeze
TYPES = [:user, :issue, :commit].freeze
def parse_references(text)
# parse reference links
@ -173,20 +168,17 @@ module Modules
def reference_issue(identifier)
if issue = Issue.find_by_hash_tag(identifier, current_ability, @project)
url = project_issue_path(issue.project.owner, issue.project.name, issue.serial_id)
title = "#{Issue.model_name.human}: #{issue.title}"
if issue.pull_request
title = "#{PullRequest.model_name.human}: #{pull_request.title}"
project_pull_request_path(pull_request.to_project, pull_request)
else
title = "#{Issue.model_name.human}: #{issue.title}"
url = project_issue_path(issue.project.owner, issue.project.name, issue.serial_id)
end
link_to(identifier, url, html_options.merge(title: title, class: "gfm gfm-issue #{html_options[:class]}"))
end
end
def reference_pull_request(identifier)
issue = Issue.find_by_hash_tag(identifier, current_ability, @project, '!')
if pull_request = issue.pull_request
title = "#{PullRequest.model_name.human}: #{pull_request.title}"
link_to(identifier, project_pull_request_path(pull_request.to_project, pull_request), html_options.merge(title: title, class: "gfm gfm-pull_request #{html_options[:class]}"))
end
end
def reference_commit(identifier)
if commit = @project.repo.commit(identifier)
link_to shortest_hash_id(commit.id), commit_path(@project, commit.id)