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
Jérome Perrin
gitlab-ce
Commits
044e0e33
Commit
044e0e33
authored
Dec 02, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow invalid URLs in closing pattern
parent
60828ab4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
1 deletion
+52
-1
lib/gitlab/closing_issue_extractor.rb
lib/gitlab/closing_issue_extractor.rb
+3
-1
spec/lib/gitlab/closing_issue_extractor_spec.rb
spec/lib/gitlab/closing_issue_extractor_spec.rb
+49
-0
No files found.
lib/gitlab/closing_issue_extractor.rb
View file @
044e0e33
module
Gitlab
module
Gitlab
class
ClosingIssueExtractor
class
ClosingIssueExtractor
ISSUE_CLOSING_REGEX
=
begin
ISSUE_CLOSING_REGEX
=
begin
link_pattern
=
URI
.
regexp
(
%w(http https)
)
pattern
=
Gitlab
.
config
.
gitlab
.
issue_closing_pattern
pattern
=
Gitlab
.
config
.
gitlab
.
issue_closing_pattern
pattern
=
pattern
.
sub
(
'%{issue_ref}'
,
"(?:(?:
#{
Issue
.
link_reference
_pattern
}
)|(?:
#{
Issue
.
reference_pattern
}
))"
)
pattern
=
pattern
.
sub
(
'%{issue_ref}'
,
"(?:(?:
#{
link
_pattern
}
)|(?:
#{
Issue
.
reference_pattern
}
))"
)
Regexp
.
new
(
pattern
).
freeze
Regexp
.
new
(
pattern
).
freeze
end
end
...
...
spec/lib/gitlab/closing_issue_extractor_spec.rb
View file @
044e0e33
...
@@ -2,11 +2,18 @@ require 'spec_helper'
...
@@ -2,11 +2,18 @@ require 'spec_helper'
describe
Gitlab
::
ClosingIssueExtractor
do
describe
Gitlab
::
ClosingIssueExtractor
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:project2
)
{
create
(
:project
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:issue2
)
{
create
(
:issue
,
project:
project2
)
}
let
(
:reference
)
{
issue
.
to_reference
}
let
(
:reference
)
{
issue
.
to_reference
}
let
(
:cross_reference
)
{
issue2
.
to_reference
(
project
)
}
subject
{
described_class
.
new
(
project
,
project
.
creator
)
}
subject
{
described_class
.
new
(
project
,
project
.
creator
)
}
before
do
project2
.
team
<<
[
project
.
creator
,
:master
]
end
describe
"#closed_by_message"
do
describe
"#closed_by_message"
do
context
'with a single reference'
do
context
'with a single reference'
do
it
do
it
do
...
@@ -130,6 +137,27 @@ describe Gitlab::ClosingIssueExtractor do
...
@@ -130,6 +137,27 @@ describe Gitlab::ClosingIssueExtractor do
end
end
end
end
context
"with a cross-project reference"
do
it
do
message
=
"Closes
#{
cross_reference
}
"
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue2
])
end
end
context
"with a cross-project URL"
do
it
do
message
=
"Closes
#{
Gitlab
.
config
.
gitlab
.
url
}
/
#{
project2
.
to_reference
}
/issues/
#{
issue2
.
iid
}
"
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue2
])
end
end
context
"with an invalid URL"
do
it
do
message
=
"Closes https://google.com/
#{
project2
.
to_reference
}
/issues/
#{
issue2
.
iid
}
"
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([])
end
end
context
'with multiple references'
do
context
'with multiple references'
do
let
(
:other_issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:other_issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:third_issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:third_issue
)
{
create
(
:issue
,
project:
project
)
}
...
@@ -171,6 +199,27 @@ describe Gitlab::ClosingIssueExtractor do
...
@@ -171,6 +199,27 @@ describe Gitlab::ClosingIssueExtractor do
expect
(
subject
.
closed_by_message
(
message
)).
expect
(
subject
.
closed_by_message
(
message
)).
to
match_array
([
issue
,
other_issue
,
third_issue
])
to
match_array
([
issue
,
other_issue
,
third_issue
])
end
end
it
"fetches cross-project references"
do
message
=
"Closes
#{
reference
}
and
#{
cross_reference
}
"
expect
(
subject
.
closed_by_message
(
message
)).
to
match_array
([
issue
,
issue2
])
end
it
"fetches cross-project URL references"
do
message
=
"Closes
#{
Gitlab
.
config
.
gitlab
.
url
}
/
#{
project2
.
to_reference
}
/issues/
#{
issue2
.
iid
}
and
#{
reference
}
"
expect
(
subject
.
closed_by_message
(
message
)).
to
match_array
([
issue
,
issue2
])
end
it
"ignores invalid cross-project URL references"
do
message
=
"Closes https://google.com/
#{
project2
.
to_reference
}
/issues/
#{
issue2
.
iid
}
and
#{
reference
}
"
expect
(
subject
.
closed_by_message
(
message
)).
to
match_array
([
issue
])
end
end
end
end
end
end
end
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