Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
2c7554e8
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
2c7554e8
编写于
1月 28, 2013
作者:
M
Matt Humphrey
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added methods to protect and unprotect branches
上级
df6db81e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
152 addition
and
5 deletion
+152
-5
doc/api/repositories.md
doc/api/repositories.md
+86
-3
lib/api/entities.rb
lib/api/entities.rb
+5
-0
lib/api/projects.rb
lib/api/projects.rb
+38
-2
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+23
-0
未找到文件。
doc/api/repositories.md
浏览文件 @
2c7554e8
...
...
@@ -33,7 +33,8 @@ Parameters:
},
"authored_date"
:
"2012-06-27T05:51:39-07:00"
,
"committed_date"
:
"2012-06-28T03:44:20-07:00"
}
},
"protected"
:
true
}
]
```
...
...
@@ -73,7 +74,88 @@ Parameters:
},
"authored_date"
:
"2012-06-27T05:51:39-07:00"
,
"committed_date"
:
"2012-06-28T03:44:20-07:00"
}
},
"protected"
:
true
}
```
## Protect a project repository branch
Protect a single project repository branch.
```
PUT /projects/:id/repository/branches/:branch/protect
```
Parameters:
+
`id`
(required) - The ID of a project
+
`branch`
(required) - The name of the branch
```
json
{
"name"
:
"master"
,
"commit"
:
{
"id"
:
"7b5c3cc8be40ee161ae89a06bba6229da1032a0c"
,
"parents"
:
[
{
"id"
:
"4ad91d3c1144c406e50c7b33bae684bd6837faf8"
}
],
"tree"
:
"46e82de44b1061621357f24c05515327f2795a95"
,
"message"
:
"add projects API"
,
"author"
:
{
"name"
:
"John Smith"
,
"email"
:
"john@example.com"
},
"committer"
:
{
"name"
:
"John Smith"
,
"email"
:
"john@example.com"
},
"authored_date"
:
"2012-06-27T05:51:39-07:00"
,
"committed_date"
:
"2012-06-28T03:44:20-07:00"
},
"protected"
:
true
}
```
## Unprotect a project repository branch
Unprotect a single project repository branch.
```
PUT /projects/:id/repository/branches/:branch/unprotect
```
Parameters:
+
`id`
(required) - The ID of a project
+
`branch`
(required) - The name of the branch
```
json
{
"name"
:
"master"
,
"commit"
:
{
"id"
:
"7b5c3cc8be40ee161ae89a06bba6229da1032a0c"
,
"parents"
:
[
{
"id"
:
"4ad91d3c1144c406e50c7b33bae684bd6837faf8"
}
],
"tree"
:
"46e82de44b1061621357f24c05515327f2795a95"
,
"message"
:
"add projects API"
,
"author"
:
{
"name"
:
"John Smith"
,
"email"
:
"john@example.com"
},
"committer"
:
{
"name"
:
"John Smith"
,
"email"
:
"john@example.com"
},
"authored_date"
:
"2012-06-27T05:51:39-07:00"
,
"committed_date"
:
"2012-06-28T03:44:20-07:00"
},
"protected"
:
false
}
```
...
...
@@ -110,7 +192,8 @@ Parameters:
},
"authored_date"
:
"2012-05-28T04:42:42-07:00"
,
"committed_date"
:
"2012-05-28T04:42:42-07:00"
}
},
"protected"
:
null
}
]
```
...
...
lib/api/entities.rb
浏览文件 @
2c7554e8
...
...
@@ -33,6 +33,11 @@ module Gitlab
class
RepoObject
<
Grape
::
Entity
expose
:name
,
:commit
expose
:protected
do
|
repo
,
options
|
if
options
[
:project
]
options
[
:project
].
protected_branch?
repo
.
name
end
end
end
class
RepoCommit
<
Grape
::
Entity
...
...
lib/api/projects.rb
浏览文件 @
2c7554e8
...
...
@@ -218,7 +218,7 @@ module Gitlab
# Example Request:
# GET /projects/:id/repository/branches
get
":id/repository/branches"
do
present
user_project
.
repo
.
heads
.
sort_by
(
&
:name
),
with:
Entities
::
RepoObject
present
user_project
.
repo
.
heads
.
sort_by
(
&
:name
),
with:
Entities
::
RepoObject
,
project:
user_project
end
# Get a single branch
...
...
@@ -230,7 +230,43 @@ module Gitlab
# GET /projects/:id/repository/branches/:branch
get
":id/repository/branches/:branch"
do
@branch
=
user_project
.
repo
.
heads
.
find
{
|
item
|
item
.
name
==
params
[
:branch
]
}
present
@branch
,
with:
Entities
::
RepoObject
present
@branch
,
with:
Entities
::
RepoObject
,
project:
user_project
end
# Protect a single branch
#
# Parameters:
# id (required) - The ID of a project
# branch (required) - The name of the branch
# Example Request:
# PUT /projects/:id/repository/branches/:branch/protect
put
":id/repository/branches/:branch/protect"
do
@branch
=
user_project
.
repo
.
heads
.
find
{
|
item
|
item
.
name
==
params
[
:branch
]
}
protected
=
user_project
.
protected_branches
.
find_by_name
(
@branch
.
name
)
unless
protected
user_project
.
protected_branches
.
create
(
:name
=>
@branch
.
name
)
end
present
@branch
,
with:
Entities
::
RepoObject
,
project:
user_project
end
# Unprotect a single branch
#
# Parameters:
# id (required) - The ID of a project
# branch (required) - The name of the branch
# Example Request:
# PUT /projects/:id/repository/branches/:branch/unprotect
put
":id/repository/branches/:branch/unprotect"
do
@branch
=
user_project
.
repo
.
heads
.
find
{
|
item
|
item
.
name
==
params
[
:branch
]
}
protected
=
user_project
.
protected_branches
.
find_by_name
(
@branch
.
name
)
if
protected
protected
.
destroy
end
present
@branch
,
with:
Entities
::
RepoObject
,
project:
user_project
end
# Get a project repository tags
...
...
spec/requests/api/projects_spec.rb
浏览文件 @
2c7554e8
...
...
@@ -107,6 +107,29 @@ describe Gitlab::API do
json_response
[
'name'
].
should
==
'new_design'
json_response
[
'commit'
][
'id'
].
should
==
'621491c677087aa243f165eab467bfdfbee00be1'
json_response
[
'protected'
].
should
==
false
end
end
describe
"PUT /projects/:id/repository/branches/:branch/protect"
do
it
"should protect a single branch"
do
put
api
(
"/projects/
#{
project
.
id
}
/repository/branches/new_design/protect"
,
user
)
response
.
status
.
should
==
200
json_response
[
'name'
].
should
==
'new_design'
json_response
[
'commit'
][
'id'
].
should
==
'621491c677087aa243f165eab467bfdfbee00be1'
json_response
[
'protected'
].
should
==
true
end
end
describe
"PUT /projects/:id/repository/branches/:branch/unprotect"
do
it
"should unprotect a single branch"
do
put
api
(
"/projects/
#{
project
.
id
}
/repository/branches/new_design/unprotect"
,
user
)
response
.
status
.
should
==
200
json_response
[
'name'
].
should
==
'new_design'
json_response
[
'commit'
][
'id'
].
should
==
'621491c677087aa243f165eab467bfdfbee00be1'
json_response
[
'protected'
].
should
==
false
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录