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
d9d8d3b7
Commit
d9d8d3b7
authored
Jul 30, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix old api compatibility and tests
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
70f868b7
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
47 additions
and
23 deletions
+47
-23
app/helpers/labels_helper.rb
app/helpers/labels_helper.rb
+11
-7
app/models/concerns/issuable.rb
app/models/concerns/issuable.rb
+11
-0
lib/api/entities.rb
lib/api/entities.rb
+2
-2
lib/api/issues.rb
lib/api/issues.rb
+11
-3
lib/api/merge_requests.rb
lib/api/merge_requests.rb
+10
-2
spec/helpers/labels_helper_spec.rb
spec/helpers/labels_helper_spec.rb
+2
-9
No files found.
app/helpers/labels_helper.rb
View file @
d9d8d3b7
...
...
@@ -5,13 +5,7 @@ module LabelsHelper
def
render_colored_label
(
label
)
label_color
=
label
.
color
||
"#428bca"
r
,
g
,
b
=
label_color
.
slice
(
1
,
7
).
scan
(
/.{2}/
).
map
(
&
:hex
)
if
(
r
+
g
+
b
)
>
500
text_color
=
"#333"
else
text_color
=
"#FFF"
end
text_color
=
text_color_for_bg
(
label_color
)
content_tag
:span
,
class:
'label color-label'
,
style:
"background:
#{
label_color
}
;color:
#{
text_color
}
"
do
label
.
name
...
...
@@ -30,4 +24,14 @@ module LabelsHelper
'#FFECDB'
]
end
def
text_color_for_bg
(
bg_color
)
r
,
g
,
b
=
bg_color
.
slice
(
1
,
7
).
scan
(
/.{2}/
).
map
(
&
:hex
)
if
(
r
+
g
+
b
)
>
500
"#333"
else
"#FFF"
end
end
end
app/models/concerns/issuable.rb
View file @
d9d8d3b7
...
...
@@ -133,4 +133,15 @@ module Issuable
object_attributes:
self
.
attributes
}
end
def
label_names
labels
.
order
(
'title ASC'
).
pluck
(
:title
)
end
def
add_labels_by_names
(
label_names
)
label_names
.
each
do
|
label_name
|
label
=
project
.
labels
.
find_or_create_by
(
title:
label_name
.
strip
)
self
.
labels
<<
label
end
end
end
lib/api/entities.rb
View file @
d9d8d3b7
...
...
@@ -126,7 +126,7 @@ module API
end
class
Issue
<
ProjectEntity
expose
:label_
list
,
as: :labels
expose
:label_
names
,
as: :labels
expose
:milestone
,
using:
Entities
::
Milestone
expose
:assignee
,
:author
,
using:
Entities
::
UserBasic
end
...
...
@@ -135,7 +135,7 @@ module API
expose
:target_branch
,
:source_branch
,
:upvotes
,
:downvotes
expose
:author
,
:assignee
,
using:
Entities
::
UserBasic
expose
:source_project_id
,
:target_project_id
expose
:label_
list
,
as: :labels
expose
:label_
names
,
as: :labels
end
class
SSHKey
<
Grape
::
Entity
...
...
lib/api/issues.rb
View file @
d9d8d3b7
...
...
@@ -50,10 +50,15 @@ module API
post
":id/issues"
do
required_attributes!
[
:title
]
attrs
=
attributes_for_keys
[
:title
,
:description
,
:assignee_id
,
:milestone_id
]
attrs
[
:label_list
]
=
params
[
:labels
]
if
params
[
:labels
].
present?
issue
=
::
Issues
::
CreateService
.
new
(
user_project
,
current_user
,
attrs
).
execute
if
issue
.
valid?
# Find or create labels and attach to issue
if
params
[
:labels
].
present?
issue
.
add_labels_by_names
(
params
[
:labels
].
split
(
","
))
end
present
issue
,
with:
Entities
::
Issue
else
not_found!
...
...
@@ -76,13 +81,16 @@ module API
put
":id/issues/:issue_id"
do
issue
=
user_project
.
issues
.
find
(
params
[
:issue_id
])
authorize!
:modify_issue
,
issue
attrs
=
attributes_for_keys
[
:title
,
:description
,
:assignee_id
,
:milestone_id
,
:state_event
]
attrs
[
:label_list
]
=
params
[
:labels
]
if
params
[
:labels
].
present?
issue
=
::
Issues
::
UpdateService
.
new
(
user_project
,
current_user
,
attrs
).
execute
(
issue
)
if
issue
.
valid?
# Find or create labels and attach to issue
if
params
[
:labels
].
present?
issue
.
add_labels_by_names
(
params
[
:labels
].
split
(
","
))
end
present
issue
,
with:
Entities
::
Issue
else
not_found!
...
...
lib/api/merge_requests.rb
View file @
d9d8d3b7
...
...
@@ -76,10 +76,14 @@ module API
authorize!
:write_merge_request
,
user_project
required_attributes!
[
:source_branch
,
:target_branch
,
:title
]
attrs
=
attributes_for_keys
[
:source_branch
,
:target_branch
,
:assignee_id
,
:title
,
:target_project_id
,
:description
]
attrs
[
:label_list
]
=
params
[
:labels
]
if
params
[
:labels
].
present?
merge_request
=
::
MergeRequests
::
CreateService
.
new
(
user_project
,
current_user
,
attrs
).
execute
if
merge_request
.
valid?
# Find or create labels and attach to issue
if
params
[
:labels
].
present?
merge_request
.
add_labels_by_names
(
params
[
:labels
].
split
(
","
))
end
present
merge_request
,
with:
Entities
::
MergeRequest
else
handle_merge_request_errors!
merge_request
.
errors
...
...
@@ -103,12 +107,16 @@ module API
#
put
":id/merge_request/:merge_request_id"
do
attrs
=
attributes_for_keys
[
:source_branch
,
:target_branch
,
:assignee_id
,
:title
,
:state_event
,
:description
]
attrs
[
:label_list
]
=
params
[
:labels
]
if
params
[
:labels
].
present?
merge_request
=
user_project
.
merge_requests
.
find
(
params
[
:merge_request_id
])
authorize!
:modify_merge_request
,
merge_request
merge_request
=
::
MergeRequests
::
UpdateService
.
new
(
user_project
,
current_user
,
attrs
).
execute
(
merge_request
)
if
merge_request
.
valid?
# Find or create labels and attach to issue
if
params
[
:labels
].
present?
merge_request
.
add_labels_by_names
(
params
[
:labels
].
split
(
","
))
end
present
merge_request
,
with:
Entities
::
MergeRequest
else
handle_merge_request_errors!
merge_request
.
errors
...
...
spec/helpers/labels_helper_spec.rb
View file @
d9d8d3b7
require
'spec_helper'
describe
LabelsHelper
do
describe
'#label_css_class'
do
it
'returns label-danger when given Bug as param'
do
expect
(
label_css_class
(
'bug'
)).
to
eq
(
'label-danger'
)
end
it
'returns label-danger when given Bug as param'
do
expect
(
label_css_class
(
'Bug'
)).
to
eq
(
'label-danger'
)
end
end
it
{
expect
(
text_color_for_bg
(
'#EEEEEE'
)).
to
eq
(
'#333'
)
}
it
{
expect
(
text_color_for_bg
(
'#222E2E'
)).
to
eq
(
'#FFF'
)
}
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