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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
c5d76600
Commit
c5d76600
authored
Mar 27, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix errors.
parent
8361ba81
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
114 additions
and
120 deletions
+114
-120
app/mailers/emails/groups.rb
app/mailers/emails/groups.rb
+1
-0
app/mailers/emails/profile.rb
app/mailers/emails/profile.rb
+3
-3
app/mailers/emails/projects.rb
app/mailers/emails/projects.rb
+3
-2
app/mailers/notify.rb
app/mailers/notify.rb
+9
-3
app/models/concerns/mentionable.rb
app/models/concerns/mentionable.rb
+1
-1
app/services/projects/participants_service.rb
app/services/projects/participants_service.rb
+7
-12
lib/gitlab/markdown.rb
lib/gitlab/markdown.rb
+2
-2
lib/gitlab/reference_extractor.rb
lib/gitlab/reference_extractor.rb
+6
-18
spec/helpers/gitlab_markdown_helper_spec.rb
spec/helpers/gitlab_markdown_helper_spec.rb
+8
-0
spec/lib/gitlab/reference_extractor_spec.rb
spec/lib/gitlab/reference_extractor_spec.rb
+74
-79
No files found.
app/mailers/emails/groups.rb
View file @
c5d76600
...
@@ -4,6 +4,7 @@ module Emails
...
@@ -4,6 +4,7 @@ module Emails
@group_member
=
GroupMember
.
find
(
group_member_id
)
@group_member
=
GroupMember
.
find
(
group_member_id
)
@group
=
@group_member
.
group
@group
=
@group_member
.
group
@target_url
=
group_url
(
@group
)
@target_url
=
group_url
(
@group
)
@current_user
=
@group_member
.
user
mail
(
to:
@group_member
.
user
.
email
,
mail
(
to:
@group_member
.
user
.
email
,
subject:
subject
(
"Access to group was granted"
))
subject:
subject
(
"Access to group was granted"
))
end
end
...
...
app/mailers/emails/profile.rb
View file @
c5d76600
module
Emails
module
Emails
module
Profile
module
Profile
def
new_user_email
(
user_id
,
token
=
nil
)
def
new_user_email
(
user_id
,
token
=
nil
)
@user
=
User
.
find
(
user_id
)
@
current_user
=
@
user
=
User
.
find
(
user_id
)
@target_url
=
user_url
(
@user
)
@target_url
=
user_url
(
@user
)
@token
=
token
@token
=
token
mail
(
to:
@user
.
notification_email
,
subject:
subject
(
"Account was created for you"
))
mail
(
to:
@user
.
notification_email
,
subject:
subject
(
"Account was created for you"
))
...
@@ -9,13 +9,13 @@ module Emails
...
@@ -9,13 +9,13 @@ module Emails
def
new_email_email
(
email_id
)
def
new_email_email
(
email_id
)
@email
=
Email
.
find
(
email_id
)
@email
=
Email
.
find
(
email_id
)
@user
=
@email
.
user
@
current_user
=
@
user
=
@email
.
user
mail
(
to:
@user
.
notification_email
,
subject:
subject
(
"Email was added to your account"
))
mail
(
to:
@user
.
notification_email
,
subject:
subject
(
"Email was added to your account"
))
end
end
def
new_ssh_key_email
(
key_id
)
def
new_ssh_key_email
(
key_id
)
@key
=
Key
.
find
(
key_id
)
@key
=
Key
.
find
(
key_id
)
@user
=
@key
.
user
@
current_user
=
@
user
=
@key
.
user
@target_url
=
user_url
(
@user
)
@target_url
=
user_url
(
@user
)
mail
(
to:
@user
.
notification_email
,
subject:
subject
(
"SSH key was added to your account"
))
mail
(
to:
@user
.
notification_email
,
subject:
subject
(
"SSH key was added to your account"
))
end
end
...
...
app/mailers/emails/projects.rb
View file @
c5d76600
...
@@ -4,12 +4,13 @@ module Emails
...
@@ -4,12 +4,13 @@ module Emails
@project_member
=
ProjectMember
.
find
user_project_id
@project_member
=
ProjectMember
.
find
user_project_id
@project
=
@project_member
.
project
@project
=
@project_member
.
project
@target_url
=
namespace_project_url
(
@project
.
namespace
,
@project
)
@target_url
=
namespace_project_url
(
@project
.
namespace
,
@project
)
@current_user
=
@project_member
.
user
mail
(
to:
@project_member
.
user
.
email
,
mail
(
to:
@project_member
.
user
.
email
,
subject:
subject
(
"Access to project was granted"
))
subject:
subject
(
"Access to project was granted"
))
end
end
def
project_was_moved_email
(
project_id
,
user_id
)
def
project_was_moved_email
(
project_id
,
user_id
)
@user
=
User
.
find
user_id
@
current_user
=
@
user
=
User
.
find
user_id
@project
=
Project
.
find
project_id
@project
=
Project
.
find
project_id
@target_url
=
namespace_project_url
(
@project
.
namespace
,
@project
)
@target_url
=
namespace_project_url
(
@project
.
namespace
,
@project
)
mail
(
to:
@user
.
notification_email
,
mail
(
to:
@user
.
notification_email
,
...
@@ -28,7 +29,7 @@ module Emails
...
@@ -28,7 +29,7 @@ module Emails
end
end
@project
=
Project
.
find
(
project_id
)
@project
=
Project
.
find
(
project_id
)
@author
=
User
.
find
(
author_id
)
@
current_user
=
@
author
=
User
.
find
(
author_id
)
@reverse_compare
=
reverse_compare
@reverse_compare
=
reverse_compare
@compare
=
compare
@compare
=
compare
@ref_name
=
Gitlab
::
Git
.
ref_name
(
ref
)
@ref_name
=
Gitlab
::
Git
.
ref_name
(
ref
)
...
...
app/mailers/notify.rb
View file @
c5d76600
...
@@ -13,6 +13,9 @@ class Notify < ActionMailer::Base
...
@@ -13,6 +13,9 @@ class Notify < ActionMailer::Base
add_template_helper
MergeRequestsHelper
add_template_helper
MergeRequestsHelper
add_template_helper
EmailsHelper
add_template_helper
EmailsHelper
attr_accessor
:current_user
helper_method
:current_user
,
:can?
default_url_options
[
:host
]
=
Gitlab
.
config
.
gitlab
.
host
default_url_options
[
:host
]
=
Gitlab
.
config
.
gitlab
.
host
default_url_options
[
:protocol
]
=
Gitlab
.
config
.
gitlab
.
protocol
default_url_options
[
:protocol
]
=
Gitlab
.
config
.
gitlab
.
protocol
default_url_options
[
:port
]
=
Gitlab
.
config
.
gitlab
.
port
unless
Gitlab
.
config
.
gitlab_on_standard_port?
default_url_options
[
:port
]
=
Gitlab
.
config
.
gitlab
.
port
unless
Gitlab
.
config
.
gitlab_on_standard_port?
...
@@ -79,9 +82,8 @@ class Notify < ActionMailer::Base
...
@@ -79,9 +82,8 @@ class Notify < ActionMailer::Base
#
#
# Returns a String containing the User's email address.
# Returns a String containing the User's email address.
def
recipient
(
recipient_id
)
def
recipient
(
recipient_id
)
if
recipient
=
User
.
find
(
recipient_id
)
@current_user
=
User
.
find
(
recipient_id
)
recipient
.
notification_email
@current_user
.
notification_email
end
end
end
# Set the References header field
# Set the References header field
...
@@ -154,4 +156,8 @@ class Notify < ActionMailer::Base
...
@@ -154,4 +156,8 @@ class Notify < ActionMailer::Base
mail
(
headers
,
&
block
)
mail
(
headers
,
&
block
)
end
end
def
can?
Ability
.
abilities
.
allowed?
(
user
,
action
,
subject
)
end
end
end
app/models/concerns/mentionable.rb
View file @
c5d76600
...
@@ -46,7 +46,7 @@ module Mentionable
...
@@ -46,7 +46,7 @@ module Mentionable
return
[]
if
mentionable_text
.
blank?
return
[]
if
mentionable_text
.
blank?
ext
=
Gitlab
::
ReferenceExtractor
.
new
(
self
.
project
,
current_user
)
ext
=
Gitlab
::
ReferenceExtractor
.
new
(
self
.
project
,
current_user
)
ext
.
analyze
(
text
)
ext
.
analyze
(
mentionable_
text
)
ext
.
users
.
uniq
ext
.
users
.
uniq
end
end
...
...
app/services/projects/participants_service.rb
View file @
c5d76600
module
Projects
module
Projects
class
ParticipantsService
<
BaseService
class
ParticipantsService
<
BaseService
def
initialize
(
project
,
user
)
@project
=
project
@user
=
user
end
def
execute
(
note_type
,
note_id
)
def
execute
(
note_type
,
note_id
)
participating
=
participating
=
if
note_type
&&
note_id
if
note_type
&&
note_id
...
@@ -12,7 +7,7 @@ module Projects
...
@@ -12,7 +7,7 @@ module Projects
else
else
[]
[]
end
end
project_members
=
sorted
(
@
project
.
team
.
members
)
project_members
=
sorted
(
project
.
team
.
members
)
participants
=
all_members
+
groups
+
project_members
+
participating
participants
=
all_members
+
groups
+
project_members
+
participating
participants
.
uniq
participants
.
uniq
end
end
...
@@ -20,11 +15,11 @@ module Projects
...
@@ -20,11 +15,11 @@ module Projects
def
participants_in
(
type
,
id
)
def
participants_in
(
type
,
id
)
users
=
case
type
users
=
case
type
when
"Issue"
when
"Issue"
issue
=
@
project
.
issues
.
find_by_iid
(
id
)
issue
=
project
.
issues
.
find_by_iid
(
id
)
issue
?
issue
.
participants
(
user
)
:
[]
issue
?
issue
.
participants
(
current_
user
)
:
[]
when
"MergeRequest"
when
"MergeRequest"
merge_request
=
@
project
.
merge_requests
.
find_by_iid
(
id
)
merge_request
=
project
.
merge_requests
.
find_by_iid
(
id
)
merge_request
?
merge_request
.
participants
(
user
)
:
[]
merge_request
?
merge_request
.
participants
(
current_
user
)
:
[]
when
"Commit"
when
"Commit"
author_ids
=
Note
.
for_commit_id
(
id
).
pluck
(
:author_id
).
uniq
author_ids
=
Note
.
for_commit_id
(
id
).
pluck
(
:author_id
).
uniq
User
.
where
(
id:
author_ids
)
User
.
where
(
id:
author_ids
)
...
@@ -41,14 +36,14 @@ module Projects
...
@@ -41,14 +36,14 @@ module Projects
end
end
def
groups
def
groups
@
user
.
authorized_groups
.
sort_by
(
&
:path
).
map
do
|
group
|
current_
user
.
authorized_groups
.
sort_by
(
&
:path
).
map
do
|
group
|
count
=
group
.
users
.
count
count
=
group
.
users
.
count
{
username:
group
.
path
,
name:
"
#{
group
.
name
}
(
#{
count
}
)"
}
{
username:
group
.
path
,
name:
"
#{
group
.
name
}
(
#{
count
}
)"
}
end
end
end
end
def
all_members
def
all_members
count
=
@
project
.
team
.
members
.
flatten
.
count
count
=
project
.
team
.
members
.
flatten
.
count
[{
username:
"all"
,
name:
"All Project and Group Members (
#{
count
}
)"
}]
[{
username:
"all"
,
name:
"All Project and Group Members (
#{
count
}
)"
}]
end
end
end
end
...
...
lib/gitlab/markdown.rb
View file @
c5d76600
...
@@ -192,7 +192,7 @@ module Gitlab
...
@@ -192,7 +192,7 @@ module Gitlab
project_path
=
$LAST_MATCH_INFO
[
:project
]
project_path
=
$LAST_MATCH_INFO
[
:project
]
if
project_path
if
project_path
actual_project
=
::
Project
.
find_with_namespace
(
project_path
)
actual_project
=
::
Project
.
find_with_namespace
(
project_path
)
actual_project
||
=
nil
unless
can?
(
user
,
:read_project
,
actual_project
)
actual_project
=
nil
unless
can?
(
user
,
:read_project
,
actual_project
)
project_prefix
=
project_path
project_prefix
=
project_path
end
end
...
@@ -235,7 +235,7 @@ module Gitlab
...
@@ -235,7 +235,7 @@ module Gitlab
#
#
# Returns string rendered by the processing method
# Returns string rendered by the processing method
def
reference_link
(
type
,
identifier
,
project
=
@project
,
user
=
current_user
,
prefix_text
=
nil
)
def
reference_link
(
type
,
identifier
,
project
=
@project
,
user
=
current_user
,
prefix_text
=
nil
)
send
(
"reference_
#{
type
}
"
,
identifier
,
project
,
prefix_text
)
send
(
"reference_
#{
type
}
"
,
identifier
,
project
,
user
,
prefix_text
)
end
end
def
reference_user
(
identifier
,
project
=
@project
,
user
=
current_user
,
_
=
nil
)
def
reference_user
(
identifier
,
project
=
@project
,
user
=
current_user
,
_
=
nil
)
...
...
lib/gitlab/reference_extractor.rb
View file @
c5d76600
...
@@ -7,7 +7,7 @@ module Gitlab
...
@@ -7,7 +7,7 @@ module Gitlab
def
initialize
(
project
,
current_user
=
nil
)
def
initialize
(
project
,
current_user
=
nil
)
@project
=
project
@project
=
project
@current_user
=
user
@current_user
=
current_
user
@references
=
Hash
.
new
{
[]
}
@references
=
Hash
.
new
{
[]
}
end
end
...
@@ -51,7 +51,7 @@ module Gitlab
...
@@ -51,7 +51,7 @@ module Gitlab
def
issues
def
issues
references
[
:issues
].
map
do
|
entry
|
references
[
:issues
].
map
do
|
entry
|
if
should_lookup?
(
entry
[
:project
])
if
entry
[
:project
].
default_issues_tracker?
entry
[
:project
].
issues
.
where
(
iid:
entry
[
:id
]).
first
entry
[
:project
].
issues
.
where
(
iid:
entry
[
:id
]).
first
end
end
end
.
compact
end
.
compact
...
@@ -59,9 +59,7 @@ module Gitlab
...
@@ -59,9 +59,7 @@ module Gitlab
def
merge_requests
def
merge_requests
references
[
:merge_requests
].
map
do
|
entry
|
references
[
:merge_requests
].
map
do
|
entry
|
if
should_lookup?
(
entry
[
:project
])
entry
[
:project
].
merge_requests
.
where
(
iid:
entry
[
:id
]).
first
entry
[
:project
].
merge_requests
.
where
(
iid:
entry
[
:id
]).
first
end
end
.
compact
end
.
compact
end
end
...
@@ -73,17 +71,15 @@ module Gitlab
...
@@ -73,17 +71,15 @@ module Gitlab
def
commits
def
commits
references
[
:commits
].
map
do
|
entry
|
references
[
:commits
].
map
do
|
entry
|
repo
=
entry
[
:project
].
repository
if
entry
[
:project
]
repo
=
entry
[
:project
].
repository
if
should_lookup?
(
entry
[
:project
])
repo
.
commit
(
entry
[
:id
])
if
repo
repo
.
commit
(
entry
[
:id
])
if
repo
end
end
.
compact
end
.
compact
end
end
def
commit_ranges
def
commit_ranges
references
[
:commit_ranges
].
map
do
|
entry
|
references
[
:commit_ranges
].
map
do
|
entry
|
repo
=
entry
[
:project
].
repository
if
entry
[
:project
]
repo
=
entry
[
:project
].
repository
if
entry
[
:project
]
if
repo
&&
should_lookup?
(
entry
[
:project
])
if
repo
from_id
,
to_id
=
entry
[
:id
].
split
(
/\.{2,3}/
,
2
)
from_id
,
to_id
=
entry
[
:id
].
split
(
/\.{2,3}/
,
2
)
[
repo
.
commit
(
from_id
),
repo
.
commit
(
to_id
)]
[
repo
.
commit
(
from_id
),
repo
.
commit
(
to_id
)]
end
end
...
@@ -95,13 +91,5 @@ module Gitlab
...
@@ -95,13 +91,5 @@ module Gitlab
def
reference_link
(
type
,
identifier
,
project
,
user
,
_
)
def
reference_link
(
type
,
identifier
,
project
,
user
,
_
)
references
[
type
]
<<
{
project:
project
,
id:
identifier
}
references
[
type
]
<<
{
project:
project
,
id:
identifier
}
end
end
def
should_lookup?
(
entry_project
)
if
entry_project
.
nil?
false
else
project
.
nil?
||
entry_project
.
default_issues_tracker?
end
end
end
end
end
end
spec/helpers/gitlab_markdown_helper_spec.rb
View file @
c5d76600
...
@@ -4,6 +4,11 @@ describe GitlabMarkdownHelper do
...
@@ -4,6 +4,11 @@ describe GitlabMarkdownHelper do
include
ApplicationHelper
include
ApplicationHelper
include
IssuesHelper
include
IssuesHelper
# TODO: Properly test this
def
can?
(
*
)
true
end
let!
(
:project
)
{
create
(
:project
)
}
let!
(
:project
)
{
create
(
:project
)
}
let
(
:empty_project
)
{
create
(
:empty_project
)
}
let
(
:empty_project
)
{
create
(
:empty_project
)
}
...
@@ -15,6 +20,9 @@ describe GitlabMarkdownHelper do
...
@@ -15,6 +20,9 @@ describe GitlabMarkdownHelper do
let
(
:snippet
)
{
create
(
:project_snippet
,
project:
project
)
}
let
(
:snippet
)
{
create
(
:project_snippet
,
project:
project
)
}
let
(
:member
)
{
project
.
project_members
.
where
(
user_id:
user
).
first
}
let
(
:member
)
{
project
.
project_members
.
where
(
user_id:
user
).
first
}
# Helper expects a current_user method.
let
(
:current_user
)
{
user
}
def
url_helper
(
image_name
)
def
url_helper
(
image_name
)
File
.
join
(
root_url
,
'assets'
,
image_name
)
File
.
join
(
root_url
,
'assets'
,
image_name
)
end
end
...
...
spec/lib/gitlab/reference_extractor_spec.rb
View file @
c5d76600
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
ReferenceExtractor
do
describe
Gitlab
::
ReferenceExtractor
do
let
(
:project
)
{
create
(
:project
)
}
subject
{
Gitlab
::
ReferenceExtractor
.
new
(
project
)
}
it
'extracts username references'
do
it
'extracts username references'
do
subject
.
analyze
(
'this contains a @user reference'
,
nil
)
subject
.
analyze
(
'this contains a @user reference'
)
expect
(
subject
.
users
).
to
eq
([{
project:
nil
,
id:
'user'
}])
expect
(
subject
.
users
).
to
eq
([{
project:
project
,
id:
'user'
}])
end
end
it
'extracts issue references'
do
it
'extracts issue references'
do
subject
.
analyze
(
'this one talks about issue #1234'
,
nil
)
subject
.
analyze
(
'this one talks about issue #1234'
)
expect
(
subject
.
issues
).
to
eq
([{
project:
nil
,
id:
'1234'
}])
expect
(
subject
.
issues
).
to
eq
([{
project:
project
,
id:
'1234'
}])
end
end
it
'extracts JIRA issue references'
do
it
'extracts JIRA issue references'
do
subject
.
analyze
(
'this one talks about issue JIRA-1234'
,
nil
)
subject
.
analyze
(
'this one talks about issue JIRA-1234'
)
expect
(
subject
.
issues
).
to
eq
([{
project:
nil
,
id:
'JIRA-1234'
}])
expect
(
subject
.
issues
).
to
eq
([{
project:
project
,
id:
'JIRA-1234'
}])
end
end
it
'extracts merge request references'
do
it
'extracts merge request references'
do
subject
.
analyze
(
"and here's !43, a merge request"
,
nil
)
subject
.
analyze
(
"and here's !43, a merge request"
)
expect
(
subject
.
merge_requests
).
to
eq
([{
project:
nil
,
id:
'43'
}])
expect
(
subject
.
merge_requests
).
to
eq
([{
project:
project
,
id:
'43'
}])
end
end
it
'extracts snippet ids'
do
it
'extracts snippet ids'
do
subject
.
analyze
(
'snippets like $12 get extracted as well'
,
nil
)
subject
.
analyze
(
'snippets like $12 get extracted as well'
)
expect
(
subject
.
snippets
).
to
eq
([{
project:
nil
,
id:
'12'
}])
expect
(
subject
.
snippets
).
to
eq
([{
project:
project
,
id:
'12'
}])
end
end
it
'extracts commit shas'
do
it
'extracts commit shas'
do
subject
.
analyze
(
'commit shas 98cf0ae3 are pulled out as Strings'
,
nil
)
subject
.
analyze
(
'commit shas 98cf0ae3 are pulled out as Strings'
)
expect
(
subject
.
commits
).
to
eq
([{
project:
nil
,
id:
'98cf0ae3'
}])
expect
(
subject
.
commits
).
to
eq
([{
project:
project
,
id:
'98cf0ae3'
}])
end
end
it
'extracts commit ranges'
do
it
'extracts commit ranges'
do
subject
.
analyze
(
'here you go, a commit range: 98cf0ae3...98cf0ae4'
,
nil
)
subject
.
analyze
(
'here you go, a commit range: 98cf0ae3...98cf0ae4'
)
expect
(
subject
.
commit_ranges
).
to
eq
([{
project:
nil
,
id:
'98cf0ae3...98cf0ae4'
}])
expect
(
subject
.
commit_ranges
).
to
eq
([{
project:
project
,
id:
'98cf0ae3...98cf0ae4'
}])
end
end
it
'extracts multiple references and preserves their order'
do
it
'extracts multiple references and preserves their order'
do
subject
.
analyze
(
'@me and @you both care about this'
,
nil
)
subject
.
analyze
(
'@me and @you both care about this'
)
expect
(
subject
.
users
).
to
eq
([
expect
(
subject
.
users
).
to
eq
([
{
project:
nil
,
id:
'me'
},
{
project:
project
,
id:
'me'
},
{
project:
nil
,
id:
'you'
}
{
project:
project
,
id:
'you'
}
])
])
end
end
it
'leaves the original note unmodified'
do
it
'leaves the original note unmodified'
do
text
=
'issue #123 is just the worst, @user'
text
=
'issue #123 is just the worst, @user'
subject
.
analyze
(
text
,
nil
)
subject
.
analyze
(
text
)
expect
(
text
).
to
eq
(
'issue #123 is just the worst, @user'
)
expect
(
text
).
to
eq
(
'issue #123 is just the worst, @user'
)
end
end
it
'extracts no references for <pre>..</pre> blocks'
do
it
'extracts no references for <pre>..</pre> blocks'
do
subject
.
analyze
(
"<pre>def puts '#1 issue'
\n
end
\n
</pre>```"
,
nil
)
subject
.
analyze
(
"<pre>def puts '#1 issue'
\n
end
\n
</pre>```"
)
expect
(
subject
.
issues
).
to
be_blank
expect
(
subject
.
issues
).
to
be_blank
end
end
it
'extracts no references for <code>..</code> blocks'
do
it
'extracts no references for <code>..</code> blocks'
do
subject
.
analyze
(
"<code>def puts '!1 request'
\n
end
\n
</code>```"
,
nil
)
subject
.
analyze
(
"<code>def puts '!1 request'
\n
end
\n
</code>```"
)
expect
(
subject
.
merge_requests
).
to
be_blank
expect
(
subject
.
merge_requests
).
to
be_blank
end
end
it
'extracts no references for code blocks with language'
do
it
'extracts no references for code blocks with language'
do
subject
.
analyze
(
"this code:
\n
```ruby
\n
def puts '#1 issue'
\n
end
\n
```"
,
nil
)
subject
.
analyze
(
"this code:
\n
```ruby
\n
def puts '#1 issue'
\n
end
\n
```"
)
expect
(
subject
.
issues
).
to
be_blank
expect
(
subject
.
issues
).
to
be_blank
end
end
it
'extracts issue references for invalid code blocks'
do
it
'extracts issue references for invalid code blocks'
do
subject
.
analyze
(
'test: ```this one talks about issue #1234```'
,
nil
)
subject
.
analyze
(
'test: ```this one talks about issue #1234```'
)
expect
(
subject
.
issues
).
to
eq
([{
project:
nil
,
id:
'1234'
}])
expect
(
subject
.
issues
).
to
eq
([{
project:
project
,
id:
'1234'
}])
end
end
it
'handles all possible kinds of references'
do
it
'handles all possible kinds of references'
do
...
@@ -75,70 +78,64 @@ describe Gitlab::ReferenceExtractor do
...
@@ -75,70 +78,64 @@ describe Gitlab::ReferenceExtractor do
expect
(
subject
).
to
respond_to
(
*
accessors
)
expect
(
subject
).
to
respond_to
(
*
accessors
)
end
end
context
'with a project'
do
it
'accesses valid user objects on the project team'
do
let
(
:project
)
{
create
(
:project
)
}
@u_foo
=
create
(
:user
,
username:
'foo'
)
@u_bar
=
create
(
:user
,
username:
'bar'
)
it
'accesses valid user objects on the project team'
do
create
(
:user
,
username:
'offteam'
)
@u_foo
=
create
(
:user
,
username:
'foo'
)
@u_bar
=
create
(
:user
,
username:
'bar'
)
create
(
:user
,
username:
'offteam'
)
project
.
team
<<
[
@u_foo
,
:reporter
]
project
.
team
<<
[
@u_foo
,
:reporter
]
project
.
team
<<
[
@u_bar
,
:guest
]
project
.
team
<<
[
@u_bar
,
:guest
]
subject
.
analyze
(
'@foo, @baduser, @bar, and @offteam'
,
project
)
subject
.
analyze
(
'@foo, @baduser, @bar, and @offteam'
)
expect
(
subject
.
users_for
(
project
)
).
to
eq
([
@u_foo
,
@u_bar
])
expect
(
subject
.
users
).
to
eq
([
@u_foo
,
@u_bar
])
end
end
it
'accesses valid issue objects'
do
it
'accesses valid issue objects'
do
@i0
=
create
(
:issue
,
project:
project
)
@i0
=
create
(
:issue
,
project:
project
)
@i1
=
create
(
:issue
,
project:
project
)
@i1
=
create
(
:issue
,
project:
project
)
subject
.
analyze
(
"#
#{
@i0
.
iid
}
, #
#{
@i1
.
iid
}
, and #999."
,
project
)
subject
.
analyze
(
"#
#{
@i0
.
iid
}
, #
#{
@i1
.
iid
}
, and #999."
)
expect
(
subject
.
issues_for
(
project
)
).
to
eq
([
@i0
,
@i1
])
expect
(
subject
.
issues
).
to
eq
([
@i0
,
@i1
])
end
end
it
'accesses valid merge requests'
do
it
'accesses valid merge requests'
do
@m0
=
create
(
:merge_request
,
source_project:
project
,
target_project:
project
,
source_branch:
'aaa'
)
@m0
=
create
(
:merge_request
,
source_project:
project
,
target_project:
project
,
source_branch:
'aaa'
)
@m1
=
create
(
:merge_request
,
source_project:
project
,
target_project:
project
,
source_branch:
'bbb'
)
@m1
=
create
(
:merge_request
,
source_project:
project
,
target_project:
project
,
source_branch:
'bbb'
)
subject
.
analyze
(
"!999, !
#{
@m1
.
iid
}
, and !
#{
@m0
.
iid
}
."
,
project
)
subject
.
analyze
(
"!999, !
#{
@m1
.
iid
}
, and !
#{
@m0
.
iid
}
."
)
expect
(
subject
.
merge_requests_for
(
project
)
).
to
eq
([
@m1
,
@m0
])
expect
(
subject
.
merge_requests
).
to
eq
([
@m1
,
@m0
])
end
end
it
'accesses valid snippets'
do
it
'accesses valid snippets'
do
@s0
=
create
(
:project_snippet
,
project:
project
)
@s0
=
create
(
:project_snippet
,
project:
project
)
@s1
=
create
(
:project_snippet
,
project:
project
)
@s1
=
create
(
:project_snippet
,
project:
project
)
@s2
=
create
(
:project_snippet
)
@s2
=
create
(
:project_snippet
)
subject
.
analyze
(
"$
#{
@s0
.
id
}
, $999, $
#{
@s2
.
id
}
, $
#{
@s1
.
id
}
"
,
project
)
subject
.
analyze
(
"$
#{
@s0
.
id
}
, $999, $
#{
@s2
.
id
}
, $
#{
@s1
.
id
}
"
)
expect
(
subject
.
snippets_for
(
project
)
).
to
eq
([
@s0
,
@s1
])
expect
(
subject
.
snippets
).
to
eq
([
@s0
,
@s1
])
end
end
it
'accesses valid commits'
do
it
'accesses valid commits'
do
commit
=
project
.
repository
.
commit
(
'master'
)
commit
=
project
.
repository
.
commit
(
'master'
)
subject
.
analyze
(
"this references commits
#{
commit
.
sha
[
0
..
6
]
}
and 012345"
,
subject
.
analyze
(
"this references commits
#{
commit
.
sha
[
0
..
6
]
}
and 012345"
)
project
)
extracted
=
subject
.
commits
extracted
=
subject
.
commits_for
(
project
)
expect
(
extracted
.
size
).
to
eq
(
1
)
expect
(
extracted
.
size
).
to
eq
(
1
)
expect
(
extracted
[
0
].
sha
).
to
eq
(
commit
.
sha
)
expect
(
extracted
[
0
].
sha
).
to
eq
(
commit
.
sha
)
expect
(
extracted
[
0
].
message
).
to
eq
(
commit
.
message
)
expect
(
extracted
[
0
].
message
).
to
eq
(
commit
.
message
)
end
end
it
'accesses valid commit ranges'
do
it
'accesses valid commit ranges'
do
commit
=
project
.
repository
.
commit
(
'master'
)
commit
=
project
.
repository
.
commit
(
'master'
)
earlier_commit
=
project
.
repository
.
commit
(
'master~2'
)
earlier_commit
=
project
.
repository
.
commit
(
'master~2'
)
subject
.
analyze
(
"this references commits
#{
earlier_commit
.
sha
[
0
..
6
]
}
...
#{
commit
.
sha
[
0
..
6
]
}
"
,
subject
.
analyze
(
"this references commits
#{
earlier_commit
.
sha
[
0
..
6
]
}
...
#{
commit
.
sha
[
0
..
6
]
}
"
)
project
)
extracted
=
subject
.
commit_ranges
extracted
=
subject
.
commit_ranges_for
(
project
)
expect
(
extracted
.
size
).
to
eq
(
1
)
expect
(
extracted
.
size
).
to
eq
(
1
)
expect
(
extracted
[
0
][
0
].
sha
).
to
eq
(
earlier_commit
.
sha
)
expect
(
extracted
[
0
][
0
].
sha
).
to
eq
(
earlier_commit
.
sha
)
expect
(
extracted
[
0
][
0
].
message
).
to
eq
(
earlier_commit
.
message
)
expect
(
extracted
[
0
][
0
].
message
).
to
eq
(
earlier_commit
.
message
)
expect
(
extracted
[
0
][
1
].
sha
).
to
eq
(
commit
.
sha
)
expect
(
extracted
[
0
][
1
].
sha
).
to
eq
(
commit
.
sha
)
expect
(
extracted
[
0
][
1
].
message
).
to
eq
(
commit
.
message
)
expect
(
extracted
[
0
][
1
].
message
).
to
eq
(
commit
.
message
)
end
end
end
context
'with a project with an underscore'
do
context
'with a project with an underscore'
do
...
@@ -146,12 +143,10 @@ describe Gitlab::ReferenceExtractor do
...
@@ -146,12 +143,10 @@ describe Gitlab::ReferenceExtractor do
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
it
'handles project issue references'
do
it
'handles project issue references'
do
subject
.
analyze
(
"this refers issue
#{
project
.
path_with_namespace
}
#
#{
issue
.
iid
}
"
,
subject
.
analyze
(
"this refers issue
#{
project
.
path_with_namespace
}
#
#{
issue
.
iid
}
"
)
project
)
extracted
=
subject
.
issues
extracted
=
subject
.
issues_for
(
project
)
expect
(
extracted
.
size
).
to
eq
(
1
)
expect
(
extracted
.
size
).
to
eq
(
1
)
expect
(
extracted
).
to
eq
([
issue
])
expect
(
extracted
).
to
eq
([
issue
])
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