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
8681cb31
Commit
8681cb31
authored
Feb 07, 2015
by
Nikita Verkhovin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add labels notes
parent
0a34f2dc
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
98 additions
and
7 deletions
+98
-7
app/helpers/labels_helper.rb
app/helpers/labels_helper.rb
+1
-1
app/models/note.rb
app/models/note.rb
+30
-0
app/services/issuable_base_service.rb
app/services/issuable_base_service.rb
+5
-0
app/services/issues/update_service.rb
app/services/issues/update_service.rb
+7
-0
app/services/merge_requests/update_service.rb
app/services/merge_requests/update_service.rb
+10
-0
lib/gitlab/markdown.rb
lib/gitlab/markdown.rb
+16
-2
lib/gitlab/reference_extractor.rb
lib/gitlab/reference_extractor.rb
+9
-2
spec/services/issues/update_service_spec.rb
spec/services/issues/update_service_spec.rb
+10
-1
spec/services/merge_requests/update_service_spec.rb
spec/services/merge_requests/update_service_spec.rb
+10
-1
No files found.
app/helpers/labels_helper.rb
View file @
8681cb31
...
...
@@ -7,7 +7,7 @@ module LabelsHelper
label_color
=
label
.
color
||
Label
::
DEFAULT_COLOR
text_color
=
text_color_for_bg
(
label_color
)
content_tag
:span
,
class:
'label color-label'
,
style:
"background:
#{
label_color
}
;color:
#{
text_color
}
"
do
content_tag
:span
,
class:
'label color-label'
,
style:
"background
-color
:
#{
label_color
}
;color:
#{
text_color
}
"
do
label
.
name
end
end
...
...
app/models/note.rb
View file @
8681cb31
...
...
@@ -121,6 +121,36 @@ class Note < ActiveRecord::Base
})
end
def
create_labels_change_note
(
noteable
,
project
,
author
,
added_labels
,
removed_labels
)
labels_count
=
added_labels
.
count
+
removed_labels
.
count
added_labels
=
added_labels
.
map
{
|
label
|
"~
#{
label
.
id
}
"
}.
join
(
' '
)
removed_labels
=
removed_labels
.
map
{
|
label
|
"~
#{
label
.
id
}
"
}.
join
(
' '
)
message
=
''
if
added_labels
.
present?
message
<<
"added
#{
added_labels
}
"
end
if
added_labels
.
present?
&&
removed_labels
.
present?
message
<<
' and '
end
if
removed_labels
.
present?
message
<<
"removed
#{
removed_labels
}
"
end
message
<<
' '
<<
'label'
.
pluralize
(
labels_count
)
body
=
"_
#{
message
.
capitalize
}
_"
create
(
noteable:
noteable
,
project:
project
,
author:
author
,
note:
body
,
system:
true
)
end
def
create_new_commits_note
(
noteable
,
project
,
author
,
commits
)
commits_text
=
ActionController
::
Base
.
helpers
.
pluralize
(
commits
.
size
,
'new commit'
)
body
=
"Added
#{
commits_text
}
:
\n\n
"
...
...
app/services/issuable_base_service.rb
View file @
8681cb31
...
...
@@ -10,4 +10,9 @@ class IssuableBaseService < BaseService
Note
.
create_milestone_change_note
(
issuable
,
issuable
.
project
,
current_user
,
issuable
.
milestone
)
end
def
create_labels_note
(
issuable
,
added_labels
,
removed_labels
)
Note
.
create_labels_change_note
(
issuable
,
issuable
.
project
,
current_user
,
added_labels
,
removed_labels
)
end
end
app/services/issues/update_service.rb
View file @
8681cb31
...
...
@@ -14,10 +14,17 @@ module Issues
issue
.
update_nth_task
(
params
[
:task_num
].
to_i
,
false
)
end
old_labels
=
issue
.
labels
.
to_a
if
params
.
present?
&&
issue
.
update_attributes
(
params
.
except
(
:state_event
,
:task_num
))
issue
.
reset_events_cache
if
issue
.
labels
!=
old_labels
create_labels_note
(
issue
,
issue
.
labels
-
old_labels
,
old_labels
-
issue
.
labels
)
end
if
issue
.
previous_changes
.
include?
(
'milestone_id'
)
create_milestone_note
(
issue
)
end
...
...
app/services/merge_requests/update_service.rb
View file @
8681cb31
...
...
@@ -23,11 +23,21 @@ module MergeRequests
merge_request
.
update_nth_task
(
params
[
:task_num
].
to_i
,
false
)
end
old_labels
=
merge_request
.
labels
.
to_a
if
params
.
present?
&&
merge_request
.
update_attributes
(
params
.
except
(
:state_event
,
:task_num
)
)
merge_request
.
reset_events_cache
if
merge_request
.
labels
!=
old_labels
create_labels_note
(
merge_request
,
merge_request
.
labels
-
old_labels
,
old_labels
-
merge_request
.
labels
)
end
if
merge_request
.
previous_changes
.
include?
(
'milestone_id'
)
create_milestone_note
(
merge_request
)
end
...
...
lib/gitlab/markdown.rb
View file @
8681cb31
...
...
@@ -92,7 +92,7 @@ module Gitlab
allowed_tags
=
ActionView
::
Base
.
sanitized_allowed_tags
sanitize
text
.
html_safe
,
attributes:
allowed_attributes
+
%w(id class)
,
attributes:
allowed_attributes
+
%w(id class
style
)
,
tags:
allowed_tags
+
%w(table tr td th)
end
...
...
@@ -128,6 +128,7 @@ module Gitlab
(?<prefix>
\W
)? # Prefix
( # Reference
@(?<user>
#{
NAME_STR
}
) # User name
|~(?<label>
\d
+) # Label ID
|(?<issue>([A-Z
\-
]+-)
\d
+) # JIRA Issue ID
|
#{
PROJ_STR
}
?
\#
(?<issue>([a-zA-Z
\-
]+-)?
\d
+) # Issue ID
|
#{
PROJ_STR
}
?!(?<merge_request>
\d
+) # MR ID
...
...
@@ -138,7 +139,7 @@ module Gitlab
(?<suffix>
\W
)? # Suffix
}x
.
freeze
TYPES
=
[
:user
,
:issue
,
:merge_request
,
:snippet
,
:commit
].
freeze
TYPES
=
[
:user
,
:issue
,
:
label
,
:
merge_request
,
:snippet
,
:commit
].
freeze
def
parse_references
(
text
,
project
=
@project
)
# parse reference links
...
...
@@ -214,6 +215,19 @@ module Gitlab
end
end
def
reference_label
(
identifier
,
project
=
@project
,
_
=
nil
)
if
label
=
project
.
labels
.
find_by
(
id:
identifier
)
options
=
html_options
.
merge
(
class:
"gfm gfm-label
#{
html_options
[
:class
]
}
"
)
link_to
(
render_colored_label
(
label
),
project_issues_path
(
project
,
label_name:
label
.
name
),
options
)
end
end
def
reference_issue
(
identifier
,
project
=
@project
,
prefix_text
=
nil
)
if
project
.
default_issues_tracker?
if
project
.
issue_exists?
identifier
...
...
lib/gitlab/reference_extractor.rb
View file @
8681cb31
module
Gitlab
# Extract possible GFM references from an arbitrary String for further processing.
class
ReferenceExtractor
attr_accessor
:users
,
:issues
,
:merge_requests
,
:snippets
,
:commits
attr_accessor
:users
,
:
labels
,
:
issues
,
:merge_requests
,
:snippets
,
:commits
include
Markdown
def
initialize
@users
,
@issues
,
@merge_requests
,
@snippets
,
@commits
=
[],
[],
[],
[],
[]
@users
,
@labels
,
@issues
,
@merge_requests
,
@snippets
,
@commits
=
[],
[],
[],
[],
[],
[]
end
def
analyze
(
string
,
project
)
...
...
@@ -22,6 +23,12 @@ module Gitlab
end
.
reject
(
&
:nil?
)
end
def
labels_for
(
project
=
nil
)
labels
.
map
do
|
entry
|
project
.
labels
.
where
(
id:
entry
[
:id
]).
first
end
.
reject
(
&
:nil?
)
end
def
issues_for
(
project
=
nil
)
issues
.
map
do
|
entry
|
if
should_lookup?
(
project
,
entry
[
:project
])
...
...
spec/services/issues/update_service_spec.rb
View file @
8681cb31
...
...
@@ -5,6 +5,7 @@ describe Issues::UpdateService do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user2
)
{
create
(
:user
)
}
let
(
:issue
)
{
create
(
:issue
)
}
let
(
:label
)
{
create
(
:label
)
}
before
do
project
.
team
<<
[
user
,
:master
]
...
...
@@ -18,7 +19,8 @@ describe Issues::UpdateService do
title:
'New title'
,
description:
'Also please fix'
,
assignee_id:
user2
.
id
,
state_event:
'close'
state_event:
'close'
,
label_ids:
[
label
.
id
]
}
@issue
=
Issues
::
UpdateService
.
new
(
project
,
user
,
opts
).
execute
(
issue
)
...
...
@@ -29,6 +31,8 @@ describe Issues::UpdateService do
it
{
@issue
.
title
.
should
==
'New title'
}
it
{
@issue
.
assignee
.
should
==
user2
}
it
{
@issue
.
should
be_closed
}
it
{
@issue
.
labels
.
count
.
should
==
1
}
it
{
@issue
.
labels
.
first
.
title
.
should
==
'Bug'
}
it
'should send email to user2 about assign of new issue'
do
email
=
ActionMailer
::
Base
.
deliveries
.
last
...
...
@@ -40,6 +44,11 @@ describe Issues::UpdateService do
note
=
@issue
.
notes
.
last
note
.
note
.
should
include
"Reassigned to
\@
#{
user2
.
username
}
"
end
it
'should create system note about issue label edit'
do
note
=
@issue
.
notes
[
1
]
note
.
note
.
should
include
"Added ~
#{
label
.
id
}
label"
end
end
end
end
spec/services/merge_requests/update_service_spec.rb
View file @
8681cb31
...
...
@@ -5,6 +5,7 @@ describe MergeRequests::UpdateService do
let
(
:user2
)
{
create
(
:user
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
:simple
)
}
let
(
:project
)
{
merge_request
.
project
}
let
(
:label
)
{
create
(
:label
)
}
before
do
project
.
team
<<
[
user
,
:master
]
...
...
@@ -18,7 +19,8 @@ describe MergeRequests::UpdateService do
title:
'New title'
,
description:
'Also please fix'
,
assignee_id:
user2
.
id
,
state_event:
'close'
state_event:
'close'
,
label_ids:
[
label
.
id
]
}
end
...
...
@@ -35,6 +37,8 @@ describe MergeRequests::UpdateService do
it
{
@merge_request
.
title
.
should
==
'New title'
}
it
{
@merge_request
.
assignee
.
should
==
user2
}
it
{
@merge_request
.
should
be_closed
}
it
{
@merge_request
.
labels
.
count
.
should
==
1
}
it
{
@merge_request
.
labels
.
first
.
title
.
should
==
'Bug'
}
it
'should execute hooks with update action'
do
expect
(
service
).
to
have_received
(
:execute_hooks
).
...
...
@@ -51,6 +55,11 @@ describe MergeRequests::UpdateService do
note
=
@merge_request
.
notes
.
last
note
.
note
.
should
include
"Reassigned to
\@
#{
user2
.
username
}
"
end
it
'should create system note about merge_request label edit'
do
note
=
@merge_request
.
notes
[
1
]
note
.
note
.
should
include
"Added ~
#{
label
.
id
}
label"
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