Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
6dc4d1b5
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,发现更多精彩内容 >>
提交
6dc4d1b5
编写于
8月 21, 2018
作者:
R
Robert Schilling
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Extend to PUT request
上级
ceaee58c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
23 addition
and
19 deletion
+23
-19
lib/api/files.rb
lib/api/files.rb
+1
-1
spec/requests/api/files_spec.rb
spec/requests/api/files_spec.rb
+22
-18
未找到文件。
lib/api/files.rb
浏览文件 @
6dc4d1b5
...
...
@@ -59,7 +59,7 @@ module API
params
:simple_file_params
do
requires
:file_path
,
type:
String
,
desc:
'The url encoded path to the file. Ex. lib%2Fclass%2Erb'
requires
:branch
,
type:
String
,
desc:
'Name of the branch to commit into. To create a new branch, also provide `start_branch`.'
requires
:commit_message
,
type:
String
,
regexp:
/^\S+$/
,
desc:
'Commit message'
requires
:commit_message
,
type:
String
,
allow_blank:
false
,
desc:
'Commit message'
optional
:start_branch
,
type:
String
,
desc:
'Name of the branch to start the new commit from'
optional
:author_email
,
type:
String
,
desc:
'The email of the author'
optional
:author_name
,
type:
String
,
desc:
'The name of the author'
...
...
spec/requests/api/files_spec.rb
浏览文件 @
6dc4d1b5
...
...
@@ -313,7 +313,7 @@ describe API::Files do
describe
"POST /projects/:id/repository/files/:file_path"
do
let!
(
:file_path
)
{
"new_subfolder%2Fnewfile%2Erb"
}
let
(
:
valid_
params
)
do
let
(
:params
)
do
{
branch:
"master"
,
content:
"puts 8"
,
...
...
@@ -322,7 +322,7 @@ describe API::Files do
end
it
"creates a new file in project repo"
do
post
api
(
route
(
file_path
),
user
),
valid_
params
post
api
(
route
(
file_path
),
user
),
params
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
json_response
[
"file_path"
]).
to
eq
(
CGI
.
unescape
(
file_path
))
...
...
@@ -338,13 +338,9 @@ describe API::Files do
end
it
'returns a 400 bad request if the commit message is empty'
do
invalid_params
=
{
branch:
'master'
,
content:
'puts 8'
,
commit_message:
''
}
params
[
:commit_message
]
=
''
post
api
(
route
(
file_path
),
user
),
invalid_
params
post
api
(
route
(
file_path
),
user
),
params
expect
(
response
).
to
have_gitlab_http_status
(
400
)
end
...
...
@@ -353,16 +349,16 @@ describe API::Files do
allow_any_instance_of
(
Repository
).
to
receive
(
:create_file
)
.
and_raise
(
Gitlab
::
Git
::
CommitError
,
'Cannot create file'
)
post
api
(
route
(
"any%2Etxt"
),
user
),
valid_
params
post
api
(
route
(
"any%2Etxt"
),
user
),
params
expect
(
response
).
to
have_gitlab_http_status
(
400
)
end
context
"when specifying an author"
do
it
"creates a new file with the specified author"
do
valid_
params
.
merge!
(
author_email:
author_email
,
author_name:
author_name
)
params
.
merge!
(
author_email:
author_email
,
author_name:
author_name
)
post
api
(
route
(
"new_file_with_author%2Etxt"
),
user
),
valid_
params
post
api
(
route
(
"new_file_with_author%2Etxt"
),
user
),
params
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
response
.
content_type
).
to
eq
(
'application/json'
)
...
...
@@ -376,7 +372,7 @@ describe API::Files do
let!
(
:project
)
{
create
(
:project_empty_repo
,
namespace:
user
.
namespace
)
}
it
"creates a new file in project repo"
do
post
api
(
route
(
"newfile%2Erb"
),
user
),
valid_
params
post
api
(
route
(
"newfile%2Erb"
),
user
),
params
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
json_response
[
'file_path'
]).
to
eq
(
'newfile.rb'
)
...
...
@@ -388,7 +384,7 @@ describe API::Files do
end
describe
"PUT /projects/:id/repository/files"
do
let
(
:
valid_
params
)
do
let
(
:params
)
do
{
branch:
'master'
,
content:
'puts 8'
,
...
...
@@ -397,7 +393,7 @@ describe API::Files do
end
it
"updates existing file in project repo"
do
put
api
(
route
(
file_path
),
user
),
valid_
params
put
api
(
route
(
file_path
),
user
),
params
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
[
'file_path'
]).
to
eq
(
CGI
.
unescape
(
file_path
))
...
...
@@ -406,8 +402,16 @@ describe API::Files do
expect
(
last_commit
.
author_name
).
to
eq
(
user
.
name
)
end
it
'returns a 400 bad request if the commit message is empty'
do
params
[
:commit_message
]
=
''
put
api
(
route
(
file_path
),
user
),
params
expect
(
response
).
to
have_gitlab_http_status
(
400
)
end
it
"returns a 400 bad request if update existing file with stale last commit id"
do
params_with_stale_id
=
valid_
params
.
merge
(
last_commit_id:
'stale'
)
params_with_stale_id
=
params
.
merge
(
last_commit_id:
'stale'
)
put
api
(
route
(
file_path
),
user
),
params_with_stale_id
...
...
@@ -418,7 +422,7 @@ describe API::Files do
it
"updates existing file in project repo with accepts correct last commit id"
do
last_commit
=
Gitlab
::
Git
::
Commit
.
last_for_path
(
project
.
repository
,
'master'
,
URI
.
unescape
(
file_path
))
params_with_correct_id
=
valid_
params
.
merge
(
last_commit_id:
last_commit
.
id
)
params_with_correct_id
=
params
.
merge
(
last_commit_id:
last_commit
.
id
)
put
api
(
route
(
file_path
),
user
),
params_with_correct_id
...
...
@@ -433,9 +437,9 @@ describe API::Files do
context
"when specifying an author"
do
it
"updates a file with the specified author"
do
valid_
params
.
merge!
(
author_email:
author_email
,
author_name:
author_name
,
content:
"New content"
)
params
.
merge!
(
author_email:
author_email
,
author_name:
author_name
,
content:
"New content"
)
put
api
(
route
(
file_path
),
user
),
valid_
params
put
api
(
route
(
file_path
),
user
),
params
expect
(
response
).
to
have_gitlab_http_status
(
200
)
last_commit
=
project
.
repository
.
commit
.
raw
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录