Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
bf5e7252
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
bf5e7252
编写于
11月 30, 2015
作者:
D
Douwe Maan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Recognize commit range with named refs in compare URLs.
上级
4a292aa6
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
25 addition
and
17 deletion
+25
-17
app/models/commit_range.rb
app/models/commit_range.rb
+19
-12
spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb
...lib/gitlab/markdown/commit_range_reference_filter_spec.rb
+6
-5
未找到文件。
app/models/commit_range.rb
浏览文件 @
bf5e7252
...
...
@@ -22,16 +22,19 @@ class CommitRange
include
Referable
attr_reader
:commit_from
,
:notation
,
:commit_to
attr_reader
:ref_from
,
:ref_to
# Optional Project model
attr_accessor
:project
# See `exclude_start?`
attr_reader
:exclude_start
# The beginning and ending SHAs can be between 6 and 40 hex characters, and
# The beginning and ending refs can be named or SHAs, and
# the range notation can be double- or triple-dot.
PATTERN
=
/\h{6,40}\.{2,3}\h{6,40}/
REF_PATTERN
=
/[0-9a-zA-Z][0-9a-zA-Z_.-]*[0-9a-zA-Z\^]/
PATTERN
=
/
#{
REF_PATTERN
}
\.{2,3}
#{
REF_PATTERN
}
/
# In text references, the beginning and ending refs can only be SHAs
# between 6 and 40 hex characters.
STRICT_PATTERN
=
/\h{6,40}\.{2,3}\h{6,40}/
def
self
.
reference_prefix
'@'
...
...
@@ -45,7 +48,7 @@ class CommitRange
#{
link_reference_pattern
}
|
(?:
(?:
#{
Project
.
reference_pattern
}#{
reference_prefix
}
)?
(?<commit_range>
#{
PATTERN
}
)
(?<commit_range>
#{
STRICT_
PATTERN
}
)
)
}x
end
...
...
@@ -69,12 +72,16 @@ class CommitRange
raise
ArgumentError
,
"invalid CommitRange string format:
#{
range_string
}
"
end
ref_from
,
@notation
,
ref_to
=
range_string
.
split
(
/(\.{2,3})/
,
2
)
@ref_from
,
@notation
,
@
ref_to
=
range_string
.
split
(
/(\.{2,3})/
,
2
)
@exclude_start
=
@notation
==
'..'
if
project
.
valid_repo?
@commit_from
=
project
.
commit
(
ref_from
)
@commit_to
=
project
.
commit
(
ref_to
)
@commit_from
=
project
.
commit
(
@ref_from
)
@commit_to
=
project
.
commit
(
@ref_to
)
end
if
valid_commits?
@ref_from
=
Commit
.
truncate_sha
(
sha_from
)
if
sha_from
.
start_with?
(
@ref_from
)
@ref_to
=
Commit
.
truncate_sha
(
sha_to
)
if
sha_to
.
start_with?
(
@ref_to
)
end
end
...
...
@@ -89,7 +96,7 @@ class CommitRange
alias_method
:id
,
:to_s
def
to_reference
(
from_project
=
nil
)
reference
=
Commit
.
truncate_sha
(
sha_from
)
+
notation
+
Commit
.
truncate_sha
(
sha_to
)
reference
=
ref_from
+
notation
+
ref_to
if
cross_project_reference?
(
from_project
)
reference
=
project
.
to_reference
+
self
.
class
.
reference_prefix
+
reference
...
...
@@ -111,7 +118,7 @@ class CommitRange
end
def
exclude_start?
exclude_start
@notation
==
'..'
end
# Check if both the starting and ending commit IDs exist in a project's
...
...
spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb
浏览文件 @
bf5e7252
...
...
@@ -5,8 +5,8 @@ module Gitlab::Markdown
include
FilterSpecHelper
let
(
:project
)
{
create
(
:project
,
:public
)
}
let
(
:commit1
)
{
project
.
commit
}
let
(
:commit2
)
{
project
.
commit
(
"HEAD~2"
)
}
let
(
:commit1
)
{
project
.
commit
(
"HEAD~2"
)
}
let
(
:commit2
)
{
project
.
commit
}
let
(
:range
)
{
CommitRange
.
new
(
"
#{
commit1
.
id
}
...
#{
commit2
.
id
}
"
,
project
)
}
let
(
:range2
)
{
CommitRange
.
new
(
"
#{
commit1
.
id
}
..
#{
commit2
.
id
}
"
,
project
)
}
...
...
@@ -89,7 +89,7 @@ module Gitlab::Markdown
link
=
doc
.
css
(
'a'
).
first
expect
(
link
).
to
have_attribute
(
'data-commit-range'
)
expect
(
link
.
attr
(
'data-commit-range'
)).
to
eq
range
.
to_
reference
expect
(
link
.
attr
(
'data-commit-range'
)).
to
eq
range
.
to_
s
end
it
'supports an :only_path option'
do
...
...
@@ -146,7 +146,8 @@ module Gitlab::Markdown
context
'URL cross-project reference'
do
let
(
:namespace
)
{
create
(
:namespace
,
name:
'cross-reference'
)
}
let
(
:project2
)
{
create
(
:project
,
:public
,
namespace:
namespace
)
}
let
(
:reference
)
{
urls
.
namespace_project_compare_url
(
project2
.
namespace
,
project2
,
range
.
to_param
)
}
let
(
:range
)
{
CommitRange
.
new
(
"
#{
commit1
.
id
}
...master"
,
project
)
}
let
(
:reference
)
{
urls
.
namespace_project_compare_url
(
project2
.
namespace
,
project2
,
from:
commit1
.
id
,
to:
'master'
)
}
before
do
range
.
project
=
project2
...
...
@@ -156,7 +157,7 @@ module Gitlab::Markdown
doc
=
filter
(
"See
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
namespace_project_compare_url
(
project2
.
namespace
,
project2
,
range
.
to_param
)
to
eq
reference
end
it
'links with adjacent text'
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录