Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
dd5f7113
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,发现更多精彩内容 >>
提交
dd5f7113
编写于
11月 28, 2016
作者:
R
Robert Schilling
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Grapify the files API
上级
060ec3d7
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
62 addition
and
95 deletion
+62
-95
doc/api/repository_files.md
doc/api/repository_files.md
+2
-2
lib/api/files.rb
lib/api/files.rb
+60
-93
未找到文件。
doc/api/repository_files.md
浏览文件 @
dd5f7113
...
@@ -60,7 +60,7 @@ Parameters:
...
@@ -60,7 +60,7 @@ Parameters:
-
`file_path`
(required) - Full path to new file. Ex. lib/class.rb
-
`file_path`
(required) - Full path to new file. Ex. lib/class.rb
-
`branch_name`
(required) - The name of branch
-
`branch_name`
(required) - The name of branch
-
`encoding`
(optional) -
'text' or 'base64'. Text is defaul
t.
-
`encoding`
(optional) -
Change encoding to 'base64'. Default is tex
t.
-
`author_email`
(optional) - Specify the commit author's email address
-
`author_email`
(optional) - Specify the commit author's email address
-
`author_name`
(optional) - Specify the commit author's name
-
`author_name`
(optional) - Specify the commit author's name
-
`content`
(required) - File content
-
`content`
(required) - File content
...
@@ -89,7 +89,7 @@ Parameters:
...
@@ -89,7 +89,7 @@ Parameters:
-
`file_path`
(required) - Full path to file. Ex. lib/class.rb
-
`file_path`
(required) - Full path to file. Ex. lib/class.rb
-
`branch_name`
(required) - The name of branch
-
`branch_name`
(required) - The name of branch
-
`encoding`
(optional) -
'text' or 'base64'. Text is defaul
t.
-
`encoding`
(optional) -
Change encoding to 'base64'. Default is tex
t.
-
`author_email`
(optional) - Specify the commit author's email address
-
`author_email`
(optional) - Specify the commit author's email address
-
`author_name`
(optional) - Specify the commit author's name
-
`author_name`
(optional) - Specify the commit author's name
-
`content`
(required) - New file content
-
`content`
(required) - New file content
...
...
lib/api/files.rb
浏览文件 @
dd5f7113
...
@@ -23,140 +23,107 @@ module API
...
@@ -23,140 +23,107 @@ module API
branch_name:
attrs
[
:branch_name
]
branch_name:
attrs
[
:branch_name
]
}
}
end
end
params
:simple_file_params
do
requires
:file_path
,
type:
String
,
desc:
'The path to new file. Ex. lib/class.rb'
requires
:branch_name
,
type:
String
,
desc:
'The name of branch'
requires
:commit_message
,
type:
String
,
desc:
'Commit Message'
optional
:author_email
,
type:
String
,
desc:
'The email of the author'
optional
:author_name
,
type:
String
,
desc:
'The name of the author'
end
params
:extended_file_params
do
use
:simple_file_params
requires
:content
,
type:
String
,
desc:
'File content'
optional
:encoding
,
type:
String
,
values:
%w[base64]
,
desc:
'File encoding'
end
end
end
params
do
requires
:id
,
type:
String
,
desc:
'The project ID'
end
resource
:projects
do
resource
:projects
do
# Get file from repository
desc
'Get a file from repository'
# File content is Base64 encoded
params
do
#
requires
:file_path
,
type:
String
,
desc:
'The path to the file. Ex. lib/class.rb'
# Parameters:
requires
:ref
,
type:
String
,
desc:
'The name of branch, tag, or commit'
# file_path (required) - The path to the file. Ex. lib/class.rb
end
# ref (required) - The name of branch, tag or commit
#
# Example Request:
# GET /projects/:id/repository/files
#
# Example response:
# {
# "file_name": "key.rb",
# "file_path": "app/models/key.rb",
# "size": 1476,
# "encoding": "base64",
# "content": "IyA9PSBTY2hlbWEgSW5mb3...",
# "ref": "master",
# "blob_id": "79f7bbd25901e8334750839545a9bd021f0e4c83",
# "commit_id": "d5a3ff139356ce33e37e73add446f16869741b50",
# "last_commit_id": "570e7b2abdd848b95f2f578043fc23bd6f6fd24d",
# }
#
get
":id/repository/files"
do
get
":id/repository/files"
do
authorize!
:download_code
,
user_project
authorize!
:download_code
,
user_project
required_attributes!
[
:file_path
,
:ref
]
commit
=
user_project
.
commit
(
params
[
:ref
])
attrs
=
attributes_for_keys
[
:file_path
,
:ref
]
not_found!
(
'Commit'
)
unless
commit
ref
=
attrs
.
delete
(
:ref
)
file_path
=
attrs
.
delete
(
:file_path
)
commit
=
user_project
.
commit
(
ref
)
not_found!
'Commit'
unless
commit
repo
=
user_project
.
repository
repo
=
user_project
.
repository
blob
=
repo
.
blob_at
(
commit
.
sha
,
file_path
)
blob
=
repo
.
blob_at
(
commit
.
sha
,
params
[
:file_path
])
not_found!
(
'File'
)
unless
blob
if
blob
blob
.
load_all_data!
(
repo
)
blob
.
load_all_data!
(
repo
)
status
(
200
)
status
(
200
)
{
{
file_name:
blob
.
name
,
file_name:
blob
.
name
,
file_path:
blob
.
path
,
file_path:
blob
.
path
,
size:
blob
.
size
,
size:
blob
.
size
,
encoding:
"base64"
,
encoding:
"base64"
,
content:
Base64
.
strict_encode64
(
blob
.
data
),
content:
Base64
.
strict_encode64
(
blob
.
data
),
ref:
ref
,
ref:
params
[
:ref
],
blob_id:
blob
.
id
,
blob_id:
blob
.
id
,
commit_id:
commit
.
id
,
commit_id:
commit
.
id
,
last_commit_id:
repo
.
last_commit_for_path
(
commit
.
sha
,
file_path
).
id
last_commit_id:
repo
.
last_commit_for_path
(
commit
.
sha
,
params
[
:file_path
]).
id
}
}
else
not_found!
'File'
end
end
end
# Create new file in repository
desc
'Create new file in repository'
#
params
do
# Parameters:
use
:extended_file_params
# file_path (required) - The path to new file. Ex. lib/class.rb
end
# branch_name (required) - The name of branch
# content (required) - File content
# commit_message (required) - Commit message
#
# Example Request:
# POST /projects/:id/repository/files
#
post
":id/repository/files"
do
post
":id/repository/files"
do
authorize!
:push_code
,
user_project
authorize!
:push_code
,
user_project
required_attributes!
[
:file_path
,
:branch_name
,
:content
,
:commit_message
]
file_params
=
declared_params
(
include_missing:
false
)
attrs
=
attributes_for_keys
[
:file_path
,
:branch_name
,
:content
,
:commit_message
,
:encoding
,
:author_email
,
:author_name
]
result
=
::
Files
::
CreateService
.
new
(
user_project
,
current_user
,
commit_params
(
file_params
)).
execute
result
=
::
Files
::
CreateService
.
new
(
user_project
,
current_user
,
commit_params
(
attrs
)).
execute
if
result
[
:status
]
==
:success
if
result
[
:status
]
==
:success
status
(
201
)
status
(
201
)
commit_response
(
attr
s
)
commit_response
(
file_param
s
)
else
else
render_api_error!
(
result
[
:message
],
400
)
render_api_error!
(
result
[
:message
],
400
)
end
end
end
end
# Update existing file in repository
desc
'Update existing file in repository'
#
params
do
# Parameters:
use
:extended_file_params
# file_path (optional) - The path to file. Ex. lib/class.rb
end
# branch_name (required) - The name of branch
# content (required) - File content
# commit_message (required) - Commit message
#
# Example Request:
# PUT /projects/:id/repository/files
#
put
":id/repository/files"
do
put
":id/repository/files"
do
authorize!
:push_code
,
user_project
authorize!
:push_code
,
user_project
required_attributes!
[
:file_path
,
:branch_name
,
:content
,
:commit_message
]
file_params
=
declared_params
(
include_missing:
false
)
attrs
=
attributes_for_keys
[
:file_path
,
:branch_name
,
:content
,
:commit_message
,
:encoding
,
:author_email
,
:author_name
]
result
=
::
Files
::
UpdateService
.
new
(
user_project
,
current_user
,
commit_params
(
file_params
)).
execute
result
=
::
Files
::
UpdateService
.
new
(
user_project
,
current_user
,
commit_params
(
attrs
)).
execute
if
result
[
:status
]
==
:success
if
result
[
:status
]
==
:success
status
(
200
)
status
(
200
)
commit_response
(
attr
s
)
commit_response
(
file_param
s
)
else
else
http_status
=
result
[
:http_status
]
||
400
http_status
=
result
[
:http_status
]
||
400
render_api_error!
(
result
[
:message
],
http_status
)
render_api_error!
(
result
[
:message
],
http_status
)
end
end
end
end
# Delete existing file in repository
desc
'Delete an existing file in repository'
#
params
do
# Parameters:
use
:simple_file_params
# file_path (optional) - The path to file. Ex. lib/class.rb
end
# branch_name (required) - The name of branch
# content (required) - File content
# commit_message (required) - Commit message
#
# Example Request:
# DELETE /projects/:id/repository/files
#
delete
":id/repository/files"
do
delete
":id/repository/files"
do
authorize!
:push_code
,
user_project
authorize!
:push_code
,
user_project
required_attributes!
[
:file_path
,
:branch_name
,
:commit_message
]
file_params
=
declared_params
(
include_missing:
false
)
attrs
=
attributes_for_keys
[
:file_path
,
:branch_name
,
:commit_message
,
:author_email
,
:author_name
]
result
=
::
Files
::
DeleteService
.
new
(
user_project
,
current_user
,
commit_params
(
file_params
)).
execute
result
=
::
Files
::
DeleteService
.
new
(
user_project
,
current_user
,
commit_params
(
attrs
)).
execute
if
result
[
:status
]
==
:success
if
result
[
:status
]
==
:success
status
(
200
)
status
(
200
)
commit_response
(
attr
s
)
commit_response
(
file_param
s
)
else
else
render_api_error!
(
result
[
:message
],
400
)
render_api_error!
(
result
[
:message
],
400
)
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录