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
iv
gitlab-ce
Commits
959ebbca
Commit
959ebbca
authored
Apr 15, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up code around commit mentions.
parent
b73ffbd3
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
31 additions
and
25 deletions
+31
-25
app/controllers/projects/commit_controller.rb
app/controllers/projects/commit_controller.rb
+3
-3
app/models/commit.rb
app/models/commit.rb
+19
-0
app/models/concerns/mentionable.rb
app/models/concerns/mentionable.rb
+2
-2
app/models/note.rb
app/models/note.rb
+0
-8
app/services/notification_service.rb
app/services/notification_service.rb
+3
-8
app/services/projects/participants_service.rb
app/services/projects/participants_service.rb
+2
-2
app/views/projects/commits/_commit.html.haml
app/views/projects/commits/_commit.html.haml
+1
-1
spec/services/notification_service_spec.rb
spec/services/notification_service_spec.rb
+1
-1
No files found.
app/controllers/projects/commit_controller.rb
View file @
959ebbca
...
@@ -10,11 +10,11 @@ class Projects::CommitController < Projects::ApplicationController
...
@@ -10,11 +10,11 @@ class Projects::CommitController < Projects::ApplicationController
def
show
def
show
return
git_not_found!
unless
@commit
return
git_not_found!
unless
@commit
@line_notes
=
@project
.
notes
.
for_commit_id
(
commit
.
id
).
inline
@line_notes
=
commit
.
notes
(
@project
).
inline
@diffs
=
@commit
.
diffs
@diffs
=
@commit
.
diffs
@note
=
@project
.
build_commit_note
(
commit
)
@note
=
@project
.
build_commit_note
(
commit
)
@notes_count
=
@project
.
notes
.
for_commit_id
(
commit
.
id
).
count
@notes_count
=
commit
.
notes
(
@project
).
count
@notes
=
@project
.
notes
.
for_commit_id
(
@commit
.
id
).
not_inline
.
fresh
@notes
=
commit
.
notes
(
@project
).
not_inline
.
fresh
@noteable
=
@commit
@noteable
=
@commit
@comments_allowed
=
@reply_allowed
=
true
@comments_allowed
=
@reply_allowed
=
true
@comments_target
=
{
@comments_target
=
{
...
...
app/models/commit.rb
View file @
959ebbca
...
@@ -134,6 +134,25 @@ class Commit
...
@@ -134,6 +134,25 @@ class Commit
User
.
find_for_commit
(
committer_email
,
committer_name
)
User
.
find_for_commit
(
committer_email
,
committer_name
)
end
end
def
participants
(
project
,
current_user
=
nil
)
users
=
[]
users
<<
author
users
<<
committer
mentions
=
[]
mentions
<<
self
.
mentioned_users
(
current_user
,
project
)
notes
(
project
).
each
do
|
note
|
users
<<
note
.
author
mentions
<<
note
.
mentioned_users
(
current_user
,
project
)
end
users
.
concat
(
mentions
.
reduce
([],
:|
)).
uniq
end
def
notes
(
project
)
project
.
notes
.
for_commit_id
(
self
.
id
)
end
def
method_missing
(
m
,
*
args
,
&
block
)
def
method_missing
(
m
,
*
args
,
&
block
)
@raw
.
send
(
m
,
*
args
,
&
block
)
@raw
.
send
(
m
,
*
args
,
&
block
)
end
end
...
...
app/models/concerns/mentionable.rb
View file @
959ebbca
...
@@ -42,10 +42,10 @@ module Mentionable
...
@@ -42,10 +42,10 @@ module Mentionable
Note
.
cross_reference_exists?
(
target
,
local_reference
)
Note
.
cross_reference_exists?
(
target
,
local_reference
)
end
end
def
mentioned_users
(
current_user
=
nil
)
def
mentioned_users
(
current_user
=
nil
,
p
=
project
)
return
[]
if
mentionable_text
.
blank?
return
[]
if
mentionable_text
.
blank?
ext
=
Gitlab
::
ReferenceExtractor
.
new
(
self
.
project
,
current_user
)
ext
=
Gitlab
::
ReferenceExtractor
.
new
(
p
,
current_user
)
ext
.
analyze
(
mentionable_text
)
ext
.
analyze
(
mentionable_text
)
ext
.
users
.
uniq
ext
.
users
.
uniq
end
end
...
...
app/models/note.rb
View file @
959ebbca
...
@@ -327,14 +327,6 @@ class Note < ActiveRecord::Base
...
@@ -327,14 +327,6 @@ class Note < ActiveRecord::Base
current_application_settings
.
max_attachment_size
.
megabytes
.
to_i
current_application_settings
.
max_attachment_size
.
megabytes
.
to_i
end
end
def
commit_author
@commit_author
||=
project
.
team
.
users
.
find_by
(
email:
noteable
.
author_email
)
||
project
.
team
.
users
.
find_by
(
name:
noteable
.
author_name
)
rescue
nil
end
def
cross_reference?
def
cross_reference?
note
.
start_with?
(
self
.
class
.
cross_reference_note_prefix
)
note
.
start_with?
(
self
.
class
.
cross_reference_note_prefix
)
end
end
...
...
app/services/notification_service.rb
View file @
959ebbca
...
@@ -127,17 +127,12 @@ class NotificationService
...
@@ -127,17 +127,12 @@ class NotificationService
recipients
=
[]
recipients
=
[]
if
note
.
commit_id
.
present?
recipients
<<
note
.
commit_author
end
# Add all users participating in the thread (author, assignee, comment authors)
# Add all users participating in the thread (author, assignee, comment authors)
participants
=
participants
=
if
target
.
respond_to?
(
:participants
)
if
target
.
is_a?
(
Commit
)
target
.
participants
(
note
.
project
)
elsif
target
.
respond_to?
(
:participants
)
target
.
participants
target
.
participants
elsif
target
.
is_a?
(
Commit
)
author_ids
=
Note
.
for_commit_id
(
target
.
id
).
pluck
(
:author_id
).
uniq
User
.
where
(
id:
author_ids
)
else
else
note
.
mentioned_users
note
.
mentioned_users
end
end
...
...
app/services/projects/participants_service.rb
View file @
959ebbca
...
@@ -21,8 +21,8 @@ module Projects
...
@@ -21,8 +21,8 @@ module Projects
merge_request
=
project
.
merge_requests
.
find_by_iid
(
id
)
merge_request
=
project
.
merge_requests
.
find_by_iid
(
id
)
merge_request
?
merge_request
.
participants
(
current_user
)
:
[]
merge_request
?
merge_request
.
participants
(
current_user
)
:
[]
when
"Commit"
when
"Commit"
author_ids
=
Note
.
for_commit_id
(
id
).
pluck
(
:author_id
).
uniq
commit
=
project
.
repository
.
commit
(
id
)
User
.
where
(
id:
author_ids
)
commit
?
commit
.
participants
(
project
,
current_user
)
:
[]
else
else
[]
[]
end
end
...
...
app/views/projects/commits/_commit.html.haml
View file @
959ebbca
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
-
if
@note_counts
-
if
@note_counts
-
note_count
=
@note_counts
.
fetch
(
commit
.
id
,
0
)
-
note_count
=
@note_counts
.
fetch
(
commit
.
id
,
0
)
-
else
-
else
-
notes
=
project
.
notes
.
for_commit_id
(
commit
.
id
)
-
notes
=
commit
.
notes
(
project
)
-
note_count
=
notes
.
user
.
count
-
note_count
=
notes
.
user
.
count
-
if
note_count
>
0
-
if
note_count
>
0
...
...
spec/services/notification_service_spec.rb
View file @
959ebbca
...
@@ -149,7 +149,7 @@ describe NotificationService do
...
@@ -149,7 +149,7 @@ describe NotificationService do
before
do
before
do
build_team
(
note
.
project
)
build_team
(
note
.
project
)
note
.
stub
(
:commit_author
=>
@u_committer
)
allow_any_instance_of
(
Commit
).
to
receive
(
:author
).
and_return
(
)
end
end
describe
:new_note
do
describe
:new_note
do
...
...
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