Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
dd5f7113
Commit
dd5f7113
authored
Nov 28, 2016
by
Robert Schilling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Grapify the files API
parent
060ec3d7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
95 deletions
+62
-95
doc/api/repository_files.md
doc/api/repository_files.md
+2
-2
lib/api/files.rb
lib/api/files.rb
+60
-93
No files found.
doc/api/repository_files.md
View file @
dd5f7113
...
...
@@ -60,7 +60,7 @@ Parameters:
-
`file_path`
(required) - Full path to new file. Ex. lib/class.rb
-
`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_name`
(optional) - Specify the commit author's name
-
`content`
(required) - File content
...
...
@@ -89,7 +89,7 @@ Parameters:
-
`file_path`
(required) - Full path to file. Ex. lib/class.rb
-
`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_name`
(optional) - Specify the commit author's name
-
`content`
(required) - New file content
...
...
lib/api/files.rb
View file @
dd5f7113
...
...
@@ -23,140 +23,107 @@ module API
branch_name:
attrs
[
:branch_name
]
}
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
params
do
requires
:id
,
type:
String
,
desc:
'The project ID'
end
resource
:projects
do
# Get file from repository
# File content is Base64 encoded
#
# Parameters:
# file_path (required) - The path to the file. Ex. lib/class.rb
# 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",
# }
#
desc
'Get a file from repository'
params
do
requires
:file_path
,
type:
String
,
desc:
'The path to the file. Ex. lib/class.rb'
requires
:ref
,
type:
String
,
desc:
'The name of branch, tag, or commit'
end
get
":id/repository/files"
do
authorize!
:download_code
,
user_project
required_attributes!
[
:file_path
,
:ref
]
attrs
=
attributes_for_keys
[
:file_path
,
:ref
]
ref
=
attrs
.
delete
(
:ref
)
file_path
=
attrs
.
delete
(
:file_path
)
commit
=
user_project
.
commit
(
ref
)
not_found!
'Commit'
unless
commit
commit
=
user_project
.
commit
(
params
[
:ref
])
not_found!
(
'Commit'
)
unless
commit
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
)
status
(
200
)
blob
.
load_all_data!
(
repo
)
status
(
200
)
{
file_name:
blob
.
name
,
file_path:
blob
.
path
,
size:
blob
.
size
,
encoding:
"base64"
,
content:
Base64
.
strict_encode64
(
blob
.
data
),
ref:
ref
,
blob_id:
blob
.
id
,
commit_id:
commit
.
id
,
last_commit_id:
repo
.
last_commit_for_path
(
commit
.
sha
,
file_path
).
id
}
else
not_found!
'File'
end
{
file_name:
blob
.
name
,
file_path:
blob
.
path
,
size:
blob
.
size
,
encoding:
"base64"
,
content:
Base64
.
strict_encode64
(
blob
.
data
),
ref:
params
[
:ref
],
blob_id:
blob
.
id
,
commit_id:
commit
.
id
,
last_commit_id:
repo
.
last_commit_for_path
(
commit
.
sha
,
params
[
:file_path
]).
id
}
end
# Create new file in repository
#
# Parameters:
# file_path (required) - The path to new file. Ex. lib/class.rb
# branch_name (required) - The name of branch
# content (required) - File content
# commit_message (required) - Commit message
#
# Example Request:
# POST /projects/:id/repository/files
#
desc
'Create new file in repository'
params
do
use
:extended_file_params
end
post
":id/repository/files"
do
authorize!
:push_code
,
user_project
required_attributes!
[
:file_path
,
:branch_name
,
:content
,
:commit_message
]
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
(
attrs
)).
execute
file_params
=
declared_params
(
include_missing:
false
)
result
=
::
Files
::
CreateService
.
new
(
user_project
,
current_user
,
commit_params
(
file_params
)).
execute
if
result
[
:status
]
==
:success
status
(
201
)
commit_response
(
attr
s
)
commit_response
(
file_param
s
)
else
render_api_error!
(
result
[
:message
],
400
)
end
end
# Update existing file in repository
#
# Parameters:
# file_path (optional) - The path to file. Ex. lib/class.rb
# branch_name (required) - The name of branch
# content (required) - File content
# commit_message (required) - Commit message
#
# Example Request:
# PUT /projects/:id/repository/files
#
desc
'Update existing file in repository'
params
do
use
:extended_file_params
end
put
":id/repository/files"
do
authorize!
:push_code
,
user_project
required_attributes!
[
:file_path
,
:branch_name
,
:content
,
:commit_message
]
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
(
attrs
)).
execute
file_params
=
declared_params
(
include_missing:
false
)
result
=
::
Files
::
UpdateService
.
new
(
user_project
,
current_user
,
commit_params
(
file_params
)).
execute
if
result
[
:status
]
==
:success
status
(
200
)
commit_response
(
attr
s
)
commit_response
(
file_param
s
)
else
http_status
=
result
[
:http_status
]
||
400
render_api_error!
(
result
[
:message
],
http_status
)
end
end
# Delete existing file in repository
#
# Parameters:
# file_path (optional) - The path to file. Ex. lib/class.rb
# branch_name (required) - The name of branch
# content (required) - File content
# commit_message (required) - Commit message
#
# Example Request:
# DELETE /projects/:id/repository/files
#
desc
'Delete an existing file in repository'
params
do
use
:simple_file_params
end
delete
":id/repository/files"
do
authorize!
:push_code
,
user_project
required_attributes!
[
:file_path
,
:branch_name
,
:commit_message
]
attrs
=
attributes_for_keys
[
:file_path
,
:branch_name
,
:commit_message
,
:author_email
,
:author_name
]
result
=
::
Files
::
DeleteService
.
new
(
user_project
,
current_user
,
commit_params
(
attrs
)).
execute
file_params
=
declared_params
(
include_missing:
false
)
result
=
::
Files
::
DeleteService
.
new
(
user_project
,
current_user
,
commit_params
(
file_params
)).
execute
if
result
[
:status
]
==
:success
status
(
200
)
commit_response
(
attr
s
)
commit_response
(
file_param
s
)
else
render_api_error!
(
result
[
:message
],
400
)
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment