[#19] support # for pull request too
This commit is contained in:
parent
f7cd301479
commit
24ad1485a6
|
@ -29,10 +29,10 @@ en:
|
||||||
reference_format: Reference Format
|
reference_format: Reference Format
|
||||||
reference_format_example: |
|
reference_format_example: |
|
||||||
for members: @abf
|
for members: @abf
|
||||||
for issues:
|
for issues and pull requests:
|
||||||
#123 abf#123 abf/rosa-build#123
|
#123
|
||||||
for pull requests:
|
abf#123
|
||||||
!123 abf!123 abf/rosa-build!123
|
abf/rosa-build#123
|
||||||
for commits: 123456
|
for commits: 123456
|
||||||
|
|
||||||
issues: Issues
|
issues: Issues
|
||||||
|
|
|
@ -29,10 +29,10 @@ ru:
|
||||||
reference_format: Формат ссылок
|
reference_format: Формат ссылок
|
||||||
reference_format_example: |
|
reference_format_example: |
|
||||||
для участников: @abf
|
для участников: @abf
|
||||||
для задач:
|
для задач и пул реквестов:
|
||||||
#123 abf#123 abf/rosa-build#123
|
#123
|
||||||
для пул реквестов:
|
abf#123
|
||||||
!123 abf!123 abf/rosa-build!123
|
abf/rosa-build#123
|
||||||
для коммитов: 123456
|
для коммитов: 123456
|
||||||
issues: Задачи
|
issues: Задачи
|
||||||
pull_requests: Пул реквесты
|
pull_requests: Пул реквесты
|
||||||
|
|
|
@ -9,14 +9,10 @@ module Modules
|
||||||
#
|
#
|
||||||
# Supported reference formats are:
|
# Supported reference formats are:
|
||||||
# * @foo for team members
|
# * @foo for team members
|
||||||
# * for issues:
|
# * for issues & pull requests:
|
||||||
# * #123
|
# * #123
|
||||||
# * abf#123
|
# * abf#123
|
||||||
# * abf/rosa-build#123
|
# * abf/rosa-build#123
|
||||||
# * for pull requests:
|
|
||||||
# * !123
|
|
||||||
# * abf!123
|
|
||||||
# * abf/rosa-build!123
|
|
||||||
# * 123456 for commits
|
# * 123456 for commits
|
||||||
#
|
#
|
||||||
# It also parses Emoji codes to insert images. See
|
# It also parses Emoji codes to insert images. See
|
||||||
|
@ -106,13 +102,12 @@ module Modules
|
||||||
( # Reference
|
( # Reference
|
||||||
@(?<user>[a-zA-Z][a-zA-Z0-9_\-\.]*) # User uname
|
@(?<user>[a-zA-Z][a-zA-Z0-9_\-\.]*) # User uname
|
||||||
|(?<issue>(?:[a-zA-Z0-9\-_]*\/)?(?:[a-zA-Z0-9\-_]*)?\#[0-9]+) # Issue ID
|
|(?<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
|
|(?<commit>[\h]{6,40}) # Commit ID
|
||||||
)
|
)
|
||||||
(?<suffix>\W)? # Suffix
|
(?<suffix>\W)? # Suffix
|
||||||
}x.freeze
|
}x.freeze
|
||||||
|
|
||||||
TYPES = [:user, :issue, :pull_request, :commit].freeze
|
TYPES = [:user, :issue, :commit].freeze
|
||||||
|
|
||||||
def parse_references(text)
|
def parse_references(text)
|
||||||
# parse reference links
|
# parse reference links
|
||||||
|
@ -173,20 +168,17 @@ module Modules
|
||||||
|
|
||||||
def reference_issue(identifier)
|
def reference_issue(identifier)
|
||||||
if issue = Issue.find_by_hash_tag(identifier, current_ability, @project)
|
if issue = Issue.find_by_hash_tag(identifier, current_ability, @project)
|
||||||
url = project_issue_path(issue.project.owner, issue.project.name, issue.serial_id)
|
if issue.pull_request
|
||||||
title = "#{Issue.model_name.human}: #{issue.title}"
|
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]}"))
|
link_to(identifier, url, html_options.merge(title: title, class: "gfm gfm-issue #{html_options[:class]}"))
|
||||||
end
|
end
|
||||||
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)
|
def reference_commit(identifier)
|
||||||
if commit = @project.repo.commit(identifier)
|
if commit = @project.repo.commit(identifier)
|
||||||
link_to shortest_hash_id(commit.id), commit_path(@project, commit.id)
|
link_to shortest_hash_id(commit.id), commit_path(@project, commit.id)
|
||||||
|
|
Loading…
Reference in New Issue