Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
c2102e6e
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 搜索 >>
提交
c2102e6e
编写于
2月 02, 2017
作者:
O
Oswaldo Ferreira
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move /projects/fork/:id to /projects/:id/fork
上级
49e44d88
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
133 addition
and
136 deletion
+133
-136
changelogs/unreleased/14492-change-fork-endpoint.yml
changelogs/unreleased/14492-change-fork-endpoint.yml
+4
-0
doc/api/projects.md
doc/api/projects.md
+1
-1
doc/api/v3_to_v4.md
doc/api/v3_to_v4.md
+1
-0
lib/api/projects.rb
lib/api/projects.rb
+1
-1
spec/requests/api/fork_spec.rb
spec/requests/api/fork_spec.rb
+0
-134
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+126
-0
未找到文件。
changelogs/unreleased/14492-change-fork-endpoint.yml
0 → 100644
浏览文件 @
c2102e6e
---
title
:
Move /projects/fork/:id to /projects/:id/fork
merge_request
:
8940
author
:
doc/api/projects.md
浏览文件 @
c2102e6e
...
...
@@ -705,7 +705,7 @@ Parameters:
Forks a project into the user namespace of the authenticated user or the one provided.
```
POST /projects/
fork/:id
POST /projects/
:id/fork
```
Parameters:
...
...
doc/api/v3_to_v4.md
浏览文件 @
c2102e6e
...
...
@@ -22,4 +22,5 @@ changes are in V4:
-
`/gitignores/:key`
-
`/gitlab_ci_ymls/:key`
-
`/dockerfiles/:key`
-
Moved
`/projects/fork/:id`
to
`/projects/:id/fork`
lib/api/projects.rb
浏览文件 @
c2102e6e
...
...
@@ -220,7 +220,7 @@ module API
params
do
optional
:namespace
,
type:
String
,
desc:
'The ID or name of the namespace that the project will be forked into'
end
post
'
fork/:id
'
do
post
'
:id/fork
'
do
fork_params
=
declared_params
(
include_missing:
false
)
namespace_id
=
fork_params
[
:namespace
]
...
...
spec/requests/api/fork_spec.rb
已删除
100644 → 0
浏览文件 @
49e44d88
require
'spec_helper'
describe
API
::
Projects
,
api:
true
do
include
ApiHelpers
let
(
:user
)
{
create
(
:user
)
}
let
(
:user2
)
{
create
(
:user
)
}
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:group
)
{
create
(
:group
)
}
let
(
:group2
)
do
group
=
create
(
:group
,
name:
'group2_name'
)
group
.
add_owner
(
user2
)
group
end
describe
'POST /projects/fork/:id'
do
let
(
:project
)
do
create
(
:project
,
:repository
,
creator:
user
,
namespace:
user
.
namespace
)
end
before
do
project
.
add_reporter
(
user2
)
end
context
'when authenticated'
do
it
'forks if user has sufficient access to project'
do
post
api
(
"/projects/fork/
#{
project
.
id
}
"
,
user2
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'name'
]).
to
eq
(
project
.
name
)
expect
(
json_response
[
'path'
]).
to
eq
(
project
.
path
)
expect
(
json_response
[
'owner'
][
'id'
]).
to
eq
(
user2
.
id
)
expect
(
json_response
[
'namespace'
][
'id'
]).
to
eq
(
user2
.
namespace
.
id
)
expect
(
json_response
[
'forked_from_project'
][
'id'
]).
to
eq
(
project
.
id
)
end
it
'forks if user is admin'
do
post
api
(
"/projects/fork/
#{
project
.
id
}
"
,
admin
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'name'
]).
to
eq
(
project
.
name
)
expect
(
json_response
[
'path'
]).
to
eq
(
project
.
path
)
expect
(
json_response
[
'owner'
][
'id'
]).
to
eq
(
admin
.
id
)
expect
(
json_response
[
'namespace'
][
'id'
]).
to
eq
(
admin
.
namespace
.
id
)
expect
(
json_response
[
'forked_from_project'
][
'id'
]).
to
eq
(
project
.
id
)
end
it
'fails on missing project access for the project to fork'
do
new_user
=
create
(
:user
)
post
api
(
"/projects/fork/
#{
project
.
id
}
"
,
new_user
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Project Not Found'
)
end
it
'fails if forked project exists in the user namespace'
do
post
api
(
"/projects/fork/
#{
project
.
id
}
"
,
user
)
expect
(
response
).
to
have_http_status
(
409
)
expect
(
json_response
[
'message'
][
'name'
]).
to
eq
([
'has already been taken'
])
expect
(
json_response
[
'message'
][
'path'
]).
to
eq
([
'has already been taken'
])
end
it
'fails if project to fork from does not exist'
do
post
api
(
'/projects/fork/424242'
,
user
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Project Not Found'
)
end
it
'forks with explicit own user namespace id'
do
post
api
(
"/projects/fork/
#{
project
.
id
}
"
,
user2
),
namespace:
user2
.
namespace
.
id
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'owner'
][
'id'
]).
to
eq
(
user2
.
id
)
end
it
'forks with explicit own user name as namespace'
do
post
api
(
"/projects/fork/
#{
project
.
id
}
"
,
user2
),
namespace:
user2
.
username
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'owner'
][
'id'
]).
to
eq
(
user2
.
id
)
end
it
'forks to another user when admin'
do
post
api
(
"/projects/fork/
#{
project
.
id
}
"
,
admin
),
namespace:
user2
.
username
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'owner'
][
'id'
]).
to
eq
(
user2
.
id
)
end
it
'fails if trying to fork to another user when not admin'
do
post
api
(
"/projects/fork/
#{
project
.
id
}
"
,
user2
),
namespace:
admin
.
namespace
.
id
expect
(
response
).
to
have_http_status
(
404
)
end
it
'fails if trying to fork to non-existent namespace'
do
post
api
(
"/projects/fork/
#{
project
.
id
}
"
,
user2
),
namespace:
42424242
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Target Namespace Not Found'
)
end
it
'forks to owned group'
do
post
api
(
"/projects/fork/
#{
project
.
id
}
"
,
user2
),
namespace:
group2
.
name
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'namespace'
][
'name'
]).
to
eq
(
group2
.
name
)
end
it
'fails to fork to not owned group'
do
post
api
(
"/projects/fork/
#{
project
.
id
}
"
,
user2
),
namespace:
group
.
name
expect
(
response
).
to
have_http_status
(
404
)
end
it
'forks to not owned group when admin'
do
post
api
(
"/projects/fork/
#{
project
.
id
}
"
,
admin
),
namespace:
group
.
name
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'namespace'
][
'name'
]).
to
eq
(
group
.
name
)
end
end
context
'when unauthenticated'
do
it
'returns authentication error'
do
post
api
(
"/projects/fork/
#{
project
.
id
}
"
)
expect
(
response
).
to
have_http_status
(
401
)
expect
(
json_response
[
'message'
]).
to
eq
(
'401 Unauthorized'
)
end
end
end
end
spec/requests/api/projects_spec.rb
浏览文件 @
c2102e6e
...
...
@@ -1332,4 +1332,130 @@ describe API::Projects, api: true do
end
end
end
describe
'POST /projects/:id/fork'
do
let
(
:project
)
do
create
(
:project
,
:repository
,
creator:
user
,
namespace:
user
.
namespace
)
end
let
(
:group
)
{
create
(
:group
)
}
let
(
:group2
)
do
group
=
create
(
:group
,
name:
'group2_name'
)
group
.
add_owner
(
user2
)
group
end
before
do
project
.
add_reporter
(
user2
)
end
context
'when authenticated'
do
it
'forks if user has sufficient access to project'
do
post
api
(
"/projects/
#{
project
.
id
}
/fork"
,
user2
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'name'
]).
to
eq
(
project
.
name
)
expect
(
json_response
[
'path'
]).
to
eq
(
project
.
path
)
expect
(
json_response
[
'owner'
][
'id'
]).
to
eq
(
user2
.
id
)
expect
(
json_response
[
'namespace'
][
'id'
]).
to
eq
(
user2
.
namespace
.
id
)
expect
(
json_response
[
'forked_from_project'
][
'id'
]).
to
eq
(
project
.
id
)
end
it
'forks if user is admin'
do
post
api
(
"/projects/
#{
project
.
id
}
/fork"
,
admin
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'name'
]).
to
eq
(
project
.
name
)
expect
(
json_response
[
'path'
]).
to
eq
(
project
.
path
)
expect
(
json_response
[
'owner'
][
'id'
]).
to
eq
(
admin
.
id
)
expect
(
json_response
[
'namespace'
][
'id'
]).
to
eq
(
admin
.
namespace
.
id
)
expect
(
json_response
[
'forked_from_project'
][
'id'
]).
to
eq
(
project
.
id
)
end
it
'fails on missing project access for the project to fork'
do
new_user
=
create
(
:user
)
post
api
(
"/projects/
#{
project
.
id
}
/fork"
,
new_user
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Project Not Found'
)
end
it
'fails if forked project exists in the user namespace'
do
post
api
(
"/projects/
#{
project
.
id
}
/fork"
,
user
)
expect
(
response
).
to
have_http_status
(
409
)
expect
(
json_response
[
'message'
][
'name'
]).
to
eq
([
'has already been taken'
])
expect
(
json_response
[
'message'
][
'path'
]).
to
eq
([
'has already been taken'
])
end
it
'fails if project to fork from does not exist'
do
post
api
(
'/projects/424242/fork'
,
user
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Project Not Found'
)
end
it
'forks with explicit own user namespace id'
do
post
api
(
"/projects/
#{
project
.
id
}
/fork"
,
user2
),
namespace:
user2
.
namespace
.
id
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'owner'
][
'id'
]).
to
eq
(
user2
.
id
)
end
it
'forks with explicit own user name as namespace'
do
post
api
(
"/projects/
#{
project
.
id
}
/fork"
,
user2
),
namespace:
user2
.
username
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'owner'
][
'id'
]).
to
eq
(
user2
.
id
)
end
it
'forks to another user when admin'
do
post
api
(
"/projects/
#{
project
.
id
}
/fork"
,
admin
),
namespace:
user2
.
username
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'owner'
][
'id'
]).
to
eq
(
user2
.
id
)
end
it
'fails if trying to fork to another user when not admin'
do
post
api
(
"/projects/
#{
project
.
id
}
/fork"
,
user2
),
namespace:
admin
.
namespace
.
id
expect
(
response
).
to
have_http_status
(
404
)
end
it
'fails if trying to fork to non-existent namespace'
do
post
api
(
"/projects/
#{
project
.
id
}
/fork"
,
user2
),
namespace:
42424242
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Target Namespace Not Found'
)
end
it
'forks to owned group'
do
post
api
(
"/projects/
#{
project
.
id
}
/fork"
,
user2
),
namespace:
group2
.
name
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'namespace'
][
'name'
]).
to
eq
(
group2
.
name
)
end
it
'fails to fork to not owned group'
do
post
api
(
"/projects/
#{
project
.
id
}
/fork"
,
user2
),
namespace:
group
.
name
expect
(
response
).
to
have_http_status
(
404
)
end
it
'forks to not owned group when admin'
do
post
api
(
"/projects/
#{
project
.
id
}
/fork"
,
admin
),
namespace:
group
.
name
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'namespace'
][
'name'
]).
to
eq
(
group
.
name
)
end
end
context
'when unauthenticated'
do
it
'returns authentication error'
do
post
api
(
"/projects/
#{
project
.
id
}
/fork"
)
expect
(
response
).
to
have_http_status
(
401
)
expect
(
json_response
[
'message'
]).
to
eq
(
'401 Unauthorized'
)
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录