Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kazuhiko Shiozaki
gitlab-ce
Commits
0027c2dd
Commit
0027c2dd
authored
Apr 30, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Project#get_issue
parent
466bec7c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
19 deletions
+18
-19
app/models/project.rb
app/models/project.rb
+8
-8
lib/gitlab/markdown/issue_reference_filter.rb
lib/gitlab/markdown/issue_reference_filter.rb
+6
-7
spec/lib/gitlab/markdown/issue_reference_filter_spec.rb
spec/lib/gitlab/markdown/issue_reference_filter_spec.rb
+4
-4
No files found.
app/models/project.rb
View file @
0027c2dd
...
@@ -329,12 +329,16 @@ class Project < ActiveRecord::Base
...
@@ -329,12 +329,16 @@ class Project < ActiveRecord::Base
self
.
id
self
.
id
end
end
def
issue_exists?
(
issue_id
)
def
get_issue
(
issue_id
)
if
default_issues_tracker?
if
default_issues_tracker?
self
.
issues
.
where
(
iid:
issue_id
).
first
.
present?
issues
.
find_by
(
iid:
issue_id
)
else
else
true
ExternalIssue
.
new
(
issue_id
,
self
)
end
end
end
def
issue_exists?
(
issue_id
)
get_issue
(
issue_id
).
present?
end
end
def
default_issue_tracker
def
default_issue_tracker
...
@@ -350,11 +354,7 @@ class Project < ActiveRecord::Base
...
@@ -350,11 +354,7 @@ class Project < ActiveRecord::Base
end
end
def
default_issues_tracker?
def
default_issues_tracker?
if
external_issue_tracker
external_issue_tracker
.
blank?
false
else
true
end
end
end
def
external_issues_trackers
def
external_issues_trackers
...
...
lib/gitlab/markdown/issue_reference_filter.rb
View file @
0027c2dd
...
@@ -44,21 +44,20 @@ module Gitlab
...
@@ -44,21 +44,20 @@ module Gitlab
# Returns a String with `#123` references replaced with links. All links
# Returns a String with `#123` references replaced with links. All links
# have `gfm` and `gfm-issue` class names attached for styling.
# have `gfm` and `gfm-issue` class names attached for styling.
def
issue_link_filter
(
text
)
def
issue_link_filter
(
text
)
self
.
class
.
references_in
(
text
)
do
|
match
,
i
ssue
,
project_ref
|
self
.
class
.
references_in
(
text
)
do
|
match
,
i
d
,
project_ref
|
project
=
self
.
project_from_ref
(
project_ref
)
project
=
self
.
project_from_ref
(
project_ref
)
if
project
&&
project
.
issue_exists?
(
issue
)
if
project
&&
issue
=
project
.
get_issue
(
id
)
# FIXME (rspeicher): Law of Demeter
push_result
(
:issue
,
issue
)
push_result
(
:issue
,
project
.
issues
.
where
(
iid:
issue
).
first
)
url
=
url_for_issue
(
i
ssue
,
project
,
only_path:
context
[
:only_path
])
url
=
url_for_issue
(
i
d
,
project
,
only_path:
context
[
:only_path
])
title
=
escape_once
(
"Issue:
#{
title_for_issue
(
i
ssue
,
project
)
}
"
)
title
=
escape_once
(
"Issue:
#{
title_for_issue
(
i
d
,
project
)
}
"
)
klass
=
reference_class
(
:issue
)
klass
=
reference_class
(
:issue
)
%(<a href="#{url}"
%(<a href="#{url}"
title="#{title}"
title="#{title}"
class="#{klass}">#{project_ref}##{i
ssue
}</a>)
class="#{klass}">#{project_ref}##{i
d
}</a>)
else
else
match
match
end
end
...
...
spec/lib/gitlab/markdown/issue_reference_filter_spec.rb
View file @
0027c2dd
...
@@ -27,7 +27,7 @@ module Gitlab::Markdown
...
@@ -27,7 +27,7 @@ module Gitlab::Markdown
let
(
:reference
)
{
"#
#{
issue
.
iid
}
"
}
let
(
:reference
)
{
"#
#{
issue
.
iid
}
"
}
it
'ignores valid references when using non-default tracker'
do
it
'ignores valid references when using non-default tracker'
do
expect
(
project
).
to
receive
(
:
issue_exists?
).
with
(
issue
.
iid
).
and_return
(
false
)
expect
(
project
).
to
receive
(
:
get_issue
).
with
(
issue
.
iid
).
and_return
(
nil
)
exp
=
act
=
"Issue #
#{
issue
.
iid
}
"
exp
=
act
=
"Issue #
#{
issue
.
iid
}
"
expect
(
filter
(
act
).
to_html
).
to
eq
exp
expect
(
filter
(
act
).
to_html
).
to
eq
exp
...
@@ -48,7 +48,7 @@ module Gitlab::Markdown
...
@@ -48,7 +48,7 @@ module Gitlab::Markdown
it
'ignores invalid issue IDs'
do
it
'ignores invalid issue IDs'
do
exp
=
act
=
"Fixed #
#{
issue
.
iid
+
1
}
"
exp
=
act
=
"Fixed #
#{
issue
.
iid
+
1
}
"
expect
(
project
).
to
receive
(
:
issue_exists?
).
with
(
issue
.
iid
+
1
)
expect
(
project
).
to
receive
(
:
get_issue
).
with
(
issue
.
iid
+
1
).
and_return
(
nil
)
expect
(
filter
(
act
).
to_html
).
to
eq
exp
expect
(
filter
(
act
).
to_html
).
to
eq
exp
end
end
...
@@ -98,8 +98,8 @@ module Gitlab::Markdown
...
@@ -98,8 +98,8 @@ module Gitlab::Markdown
before
{
allow_cross_reference!
}
before
{
allow_cross_reference!
}
it
'ignores valid references when cross-reference project uses external tracker'
do
it
'ignores valid references when cross-reference project uses external tracker'
do
expect_any_instance_of
(
Project
).
to
receive
(
:
issue_exists?
).
expect_any_instance_of
(
Project
).
to
receive
(
:
get_issue
).
with
(
issue
.
iid
).
and_return
(
false
)
with
(
issue
.
iid
).
and_return
(
nil
)
exp
=
act
=
"Issue #
#{
issue
.
iid
}
"
exp
=
act
=
"Issue #
#{
issue
.
iid
}
"
expect
(
filter
(
act
).
to_html
).
to
eq
exp
expect
(
filter
(
act
).
to_html
).
to
eq
exp
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment