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
0
Merge Requests
0
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
Tatuya Kamada
gitlab-ce
Commits
7bde6ae5
Commit
7bde6ae5
authored
Jun 05, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix editing files via API
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
dfccb06d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
24 deletions
+26
-24
lib/api/files.rb
lib/api/files.rb
+26
-24
No files found.
lib/api/files.rb
View file @
7bde6ae5
...
@@ -3,6 +3,26 @@ module API
...
@@ -3,6 +3,26 @@ module API
class
Files
<
Grape
::
API
class
Files
<
Grape
::
API
before
{
authenticate!
}
before
{
authenticate!
}
helpers
do
def
commit_params
(
attrs
)
{
file_path:
attrs
[
:file_path
],
current_branch:
attrs
[
:branch_name
],
target_branch:
attrs
[
:branch_name
],
commit_message:
attrs
[
:commit_message
],
file_content:
attrs
[
:content
],
file_content_encoding:
attrs
[
:encoding
]
}
end
def
commit_response
(
attrs
)
{
file_path:
attrs
[
:file_path
],
branch_name:
attrs
[
:branch_name
],
}
end
end
resource
:projects
do
resource
:projects
do
# Get file from repository
# Get file from repository
# File content is Base64 encoded
# File content is Base64 encoded
...
@@ -73,17 +93,11 @@ module API
...
@@ -73,17 +93,11 @@ module API
required_attributes!
[
:file_path
,
:branch_name
,
:content
,
:commit_message
]
required_attributes!
[
:file_path
,
:branch_name
,
:content
,
:commit_message
]
attrs
=
attributes_for_keys
[
:file_path
,
:branch_name
,
:content
,
:commit_message
,
:encoding
]
attrs
=
attributes_for_keys
[
:file_path
,
:branch_name
,
:content
,
:commit_message
,
:encoding
]
branch_name
=
attrs
.
delete
(
:branch_name
)
result
=
::
Files
::
CreateService
.
new
(
user_project
,
current_user
,
commit_params
(
attrs
)).
execute
file_path
=
attrs
.
delete
(
:file_path
)
result
=
::
Files
::
CreateService
.
new
(
user_project
,
current_user
,
attrs
,
branch_name
,
file_path
).
execute
if
result
[
:status
]
==
:success
if
result
[
:status
]
==
:success
status
(
201
)
status
(
201
)
commit_response
(
attrs
)
{
file_path:
file_path
,
branch_name:
branch_name
}
else
else
render_api_error!
(
result
[
:message
],
400
)
render_api_error!
(
result
[
:message
],
400
)
end
end
...
@@ -105,17 +119,11 @@ module API
...
@@ -105,17 +119,11 @@ module API
required_attributes!
[
:file_path
,
:branch_name
,
:content
,
:commit_message
]
required_attributes!
[
:file_path
,
:branch_name
,
:content
,
:commit_message
]
attrs
=
attributes_for_keys
[
:file_path
,
:branch_name
,
:content
,
:commit_message
,
:encoding
]
attrs
=
attributes_for_keys
[
:file_path
,
:branch_name
,
:content
,
:commit_message
,
:encoding
]
branch_name
=
attrs
.
delete
(
:branch_name
)
result
=
::
Files
::
UpdateService
.
new
(
user_project
,
current_user
,
commit_params
(
attrs
)).
execute
file_path
=
attrs
.
delete
(
:file_path
)
result
=
::
Files
::
UpdateService
.
new
(
user_project
,
current_user
,
attrs
,
branch_name
,
file_path
).
execute
if
result
[
:status
]
==
:success
if
result
[
:status
]
==
:success
status
(
200
)
status
(
200
)
commit_response
(
attrs
)
{
file_path:
file_path
,
branch_name:
branch_name
}
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
)
...
@@ -138,17 +146,11 @@ module API
...
@@ -138,17 +146,11 @@ module API
required_attributes!
[
:file_path
,
:branch_name
,
:commit_message
]
required_attributes!
[
:file_path
,
:branch_name
,
:commit_message
]
attrs
=
attributes_for_keys
[
:file_path
,
:branch_name
,
:commit_message
]
attrs
=
attributes_for_keys
[
:file_path
,
:branch_name
,
:commit_message
]
branch_name
=
attrs
.
delete
(
:branch_name
)
result
=
::
Files
::
DeleteService
.
new
(
user_project
,
current_user
,
commit_params
(
attrs
)).
execute
file_path
=
attrs
.
delete
(
:file_path
)
result
=
::
Files
::
DeleteService
.
new
(
user_project
,
current_user
,
attrs
,
branch_name
,
file_path
).
execute
if
result
[
:status
]
==
:success
if
result
[
:status
]
==
:success
status
(
200
)
status
(
200
)
commit_response
(
attrs
)
{
file_path:
file_path
,
branch_name:
branch_name
}
else
else
render_api_error!
(
result
[
:message
],
400
)
render_api_error!
(
result
[
:message
],
400
)
end
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