Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
GitLab
管理
动态
成员
标记
计划
议题
议题看板
里程碑
迭代
需求
代码
合并请求
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
锁定的文件
构建
流水线
作业
流水线计划
测试用例
产物
部署
发布
Package registry
容器镜像库
模型注册表
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
贡献者分析
CI/CD 分析
仓库分析
代码评审分析
议题分析
洞察
模型实验
效能分析
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
显示更多面包屑
gitlab-cn
GitLab
提交
cf3ba020
提交
cf3ba020
编辑于
10 years ago
作者:
Robert Schilling
浏览文件
操作
下载
补丁
差异文件
Update labels via API
上级
9284038d
No related branches found
No related tags found
无相关合并请求
变更
5
隐藏空白变更内容
行内
左右并排
显示
5 个更改的文件
CHANGELOG
+1
-0
1 个添加, 0 个删除
CHANGELOG
app/models/label.rb
+1
-4
1 个添加, 4 个删除
app/models/label.rb
doc/api/labels.md
+23
-1
23 个添加, 1 个删除
doc/api/labels.md
lib/api/labels.rb
+35
-0
35 个添加, 0 个删除
lib/api/labels.rb
spec/requests/api/labels_spec.rb
+66
-4
66 个添加, 4 个删除
spec/requests/api/labels_spec.rb
有
126 个添加
和
9 个删除
CHANGELOG
+
1
−
0
浏览文件 @
cf3ba020
...
@@ -11,6 +11,7 @@ v 7.2.0
...
@@ -11,6 +11,7 @@ v 7.2.0
- Fix bug when MR download patch return invalid diff
- Fix bug when MR download patch return invalid diff
- Test gitlab-shell integration
- Test gitlab-shell integration
- Repository import timeout increased from 2 to 4 minutes allowing larger repos to be imported
- Repository import timeout increased from 2 to 4 minutes allowing larger repos to be imported
- API for labels (Robert Schilling)
v 7.1.0
v 7.1.0
- Remove observers
- Remove observers
...
...
此差异已折叠。
点击以展开。
app/models/label.rb
+
1
−
4
浏览文件 @
cf3ba020
...
@@ -7,10 +7,7 @@ class Label < ActiveRecord::Base
...
@@ -7,10 +7,7 @@ class Label < ActiveRecord::Base
validates
:project
,
presence:
true
validates
:project
,
presence:
true
# Dont allow '?', '&', and ',' for label titles
# Dont allow '?', '&', and ',' for label titles
validates
:title
,
validates
:title
,
presence:
true
,
format:
{
with:
/\A[^&\?,&]*\z/
}
presence:
true
,
format:
{
with:
/\A[^&\?,&]*\z/
},
uniqueness:
true
scope
:order_by_name
,
->
{
reorder
(
"labels.title ASC"
)
}
scope
:order_by_name
,
->
{
reorder
(
"labels.title ASC"
)
}
...
...
此差异已折叠。
点击以展开。
doc/api/labels.md
+
23
−
1
浏览文件 @
cf3ba020
...
@@ -60,4 +60,26 @@ DELETE /projects/:id/labels
...
@@ -60,4 +60,26 @@ DELETE /projects/:id/labels
It returns 200 if the label successfully was deleted, 404 for wrong parameters
It returns 200 if the label successfully was deleted, 404 for wrong parameters
and 400 if the label does not exist.
and 400 if the label does not exist.
In case of an error, additionally an error is returned.
In case of an error, additionally an error message is returned.
## Edit an existing label
Updates an existing label with new name or now color. At least one parameter
is required, to update the label.
```
PUT /projects/:id/labels
```
Parameters:
-
`id`
(required) - The ID of a project
-
`name`
(required) - The name of the existing label
-
`new_name`
(optional) - The new name of the label
-
`color`
(optional) - New color of the label given in 6-digit hex notation with leading '#' sign (e.g. #FFAABB)
On success, this method returns 200 with the updated label.
If required parameters are missing, 400 is returned.
If the label to be updated is missing, 404 is returned.
If parameters are invalid, 405 is returned. In case of an error,
additionally an error message is returned.
此差异已折叠。
点击以展开。
lib/api/labels.rb
+
35
−
0
浏览文件 @
cf3ba020
...
@@ -60,6 +60,41 @@ class Labels < Grape::API
...
@@ -60,6 +60,41 @@ class Labels < Grape::API
label
.
destroy
label
.
destroy
end
end
# Updates an existing label. At least one optional parameter is required.
#
# Parameters:
# id (required) - The ID of a project
# name (optional) - The name of the label to be deleted
# color (optional) - Color of the label given in 6-digit hex
# notation with leading '#' sign (e.g. #FFAABB)
# Example Request:
# PUT /projects/:id/labels
put
':id/labels'
do
required_attributes!
[
:name
]
label
=
user_project
.
find_label
(
params
[
:name
])
if
!
label
return
render_api_error!
(
'Label not found'
,
404
)
end
attrs
=
attributes_for_keys
[
:new_name
,
:color
]
if
attrs
.
empty?
return
render_api_error!
(
'Required parameters "name" or "color" '
\
'missing'
,
400
)
end
# Rename new name to the actual label attribute name
attrs
[
:name
]
=
attrs
.
delete
(
:new_name
)
if
attrs
.
key?
(
:new_name
)
if
label
.
update
(
attrs
)
present
label
,
with:
Entities
::
Label
else
render_api_error!
(
label
.
errors
.
full_messages
.
join
(
', '
),
405
)
end
end
end
end
end
end
end
end
此差异已折叠。
点击以展开。
spec/requests/api/labels_spec.rb
+
66
−
4
浏览文件 @
cf3ba020
...
@@ -69,14 +69,12 @@
...
@@ -69,14 +69,12 @@
describe
'DELETE /projects/:id/labels'
do
describe
'DELETE /projects/:id/labels'
do
it
'should return 200 for existing label'
do
it
'should return 200 for existing label'
do
delete
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
delete
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
name:
'label1'
name:
'label1'
response
.
status
.
should
==
200
response
.
status
.
should
==
200
end
end
it
'should return 404 for non existing label'
do
it
'should return 404 for non existing label'
do
delete
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
delete
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
name:
'label2'
name:
'label2'
response
.
status
.
should
==
404
response
.
status
.
should
==
404
json_response
[
'message'
].
should
==
'Label not found'
json_response
[
'message'
].
should
==
'Label not found'
end
end
...
@@ -86,4 +84,68 @@
...
@@ -86,4 +84,68 @@
response
.
status
.
should
==
400
response
.
status
.
should
==
400
end
end
end
end
describe
'PUT /projects/:id/labels'
do
it
'should return 200 if name and colors are changed'
do
put
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
name:
'label1'
,
new_name:
'New Label'
,
color:
'#FFFFFF'
response
.
status
.
should
==
200
json_response
[
'name'
].
should
==
'New Label'
json_response
[
'color'
].
should
==
'#FFFFFF'
end
it
'should return 200 if name is changed'
do
put
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
name:
'label1'
,
new_name:
'New Label'
response
.
status
.
should
==
200
json_response
[
'name'
].
should
==
'New Label'
json_response
[
'color'
].
should
==
label1
.
color
end
it
'should return 200 if colors is changed'
do
put
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
name:
'label1'
,
color:
'#FFFFFF'
response
.
status
.
should
==
200
json_response
[
'name'
].
should
==
label1
.
name
json_response
[
'color'
].
should
==
'#FFFFFF'
end
it
'should return 404 if label does not exist'
do
put
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
name:
'label2'
,
new_name:
'label3'
response
.
status
.
should
==
404
end
it
'should return 400 if no label name given'
do
put
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
new_name:
'label2'
response
.
status
.
should
==
400
end
it
'should return 400 if no new parameters given'
do
put
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
name:
'label1'
response
.
status
.
should
==
400
end
it
'should return 405 for invalid name'
do
put
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
name:
'label1'
,
new_name:
'?'
,
color:
'#FFFFFF'
response
.
status
.
should
==
405
json_response
[
'message'
].
should
==
'Title is invalid'
end
it
'should return 405 for invalid name'
do
put
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
name:
'label1'
,
color:
'#FF'
response
.
status
.
should
==
405
json_response
[
'message'
].
should
==
'Color is invalid'
end
end
end
end
此差异已折叠。
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录