BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
c77d957b
Unverified
Commit
c77d957b
authored
Nov 11, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API: Edit file in repository
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
75303241
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
5 deletions
+85
-5
repositories.md
doc/api/repositories.md
+13
-0
files.rb
lib/api/files.rb
+34
-2
files_spec.rb
spec/requests/api/files_spec.rb
+38
-3
No files found.
doc/api/repositories.md
View file @
c77d957b
...
@@ -384,3 +384,16 @@ Parameters:
...
@@ -384,3 +384,16 @@ Parameters:
+
`branch_name`
(required) - The name of branch
+
`branch_name`
(required) - The name of branch
+
`content`
(required) - File content
+
`content`
(required) - File content
+
`commit_message`
(required) - Commit message
+
`commit_message`
(required) - Commit message
## Update existing file in repository
```
PUT /projects/:id/repository/files
```
Parameters:
+
`file_path`
(required) - Full path to file. Ex. lib/class.rb
+
`branch_name`
(required) - The name of branch
+
`content`
(required) - New file content
+
`commit_message`
(required) - Commit message
lib/api/files.rb
View file @
c77d957b
...
@@ -16,9 +16,10 @@ module API
...
@@ -16,9 +16,10 @@ module API
#
#
# Example Request:
# Example Request:
# POST /projects/:id/repository/files
# POST /projects/:id/repository/files
#
post
":id/repository/files"
do
post
":id/repository/files"
do
required_attributes!
[
:file_name
,
:branch_name
,
:content
]
required_attributes!
[
:file_name
,
:branch_name
,
:content
,
:commit_message
]
attrs
=
attributes_for_keys
[
:file_name
,
:file_path
,
:branch_name
,
:content
]
attrs
=
attributes_for_keys
[
:file_name
,
:file_path
,
:branch_name
,
:content
,
:commit_message
]
branch_name
=
attrs
.
delete
(
:branch_name
)
branch_name
=
attrs
.
delete
(
:branch_name
)
file_path
=
attrs
.
delete
(
:file_path
)
file_path
=
attrs
.
delete
(
:file_path
)
result
=
::
Files
::
CreateContext
.
new
(
user_project
,
current_user
,
attrs
,
branch_name
,
file_path
).
execute
result
=
::
Files
::
CreateContext
.
new
(
user_project
,
current_user
,
attrs
,
branch_name
,
file_path
).
execute
...
@@ -35,6 +36,37 @@ module API
...
@@ -35,6 +36,37 @@ module API
render_api_error!
(
result
[
:error
],
400
)
render_api_error!
(
result
[
:error
],
400
)
end
end
end
end
# Update existing file in repository
#
# Parameters:
# file_name (required) - The name of new file. Ex. class.rb
# file_path (optional) - The path to new file. Ex. lib/
# 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
required_attributes!
[
:file_path
,
:branch_name
,
:content
,
:commit_message
]
attrs
=
attributes_for_keys
[
:file_path
,
:branch_name
,
:content
,
:commit_message
]
branch_name
=
attrs
.
delete
(
:branch_name
)
file_path
=
attrs
.
delete
(
:file_path
)
result
=
::
Files
::
UpdateContext
.
new
(
user_project
,
current_user
,
attrs
,
branch_name
,
file_path
).
execute
if
result
[
:status
]
==
:success
status
(
200
)
{
file_path:
file_path
,
branch_name:
branch_name
}
else
render_api_error!
(
result
[
:error
],
400
)
end
end
end
end
end
end
end
end
...
...
spec/requests/api/files_spec.rb
View file @
c77d957b
...
@@ -10,6 +10,15 @@ describe API::API do
...
@@ -10,6 +10,15 @@ describe API::API do
before
{
project
.
team
<<
[
user
,
:developer
]
}
before
{
project
.
team
<<
[
user
,
:developer
]
}
describe
"POST /projects/:id/repository/files"
do
describe
"POST /projects/:id/repository/files"
do
let
(
:valid_params
)
{
{
file_name:
'newfile.rb'
,
branch_name:
'master'
,
content:
'puts 8'
,
commit_message:
'Added newfile'
}
}
it
"should create a new file in project repo"
do
it
"should create a new file in project repo"
do
Gitlab
::
Satellite
::
NewFileAction
.
any_instance
.
stub
(
Gitlab
::
Satellite
::
NewFileAction
.
any_instance
.
stub
(
commit!:
true
,
commit!:
true
,
...
@@ -35,12 +44,38 @@ describe API::API do
...
@@ -35,12 +44,38 @@ describe API::API do
end
end
end
end
def
valid_params
describe
"PUT /projects/:id/repository/files"
do
let
(
:valid_params
)
{
{
{
file_name:
'newfile
.rb'
,
file_path:
'spec/spec_helper
.rb'
,
branch_name:
'master'
,
branch_name:
'master'
,
content:
'puts 8'
,
content:
'puts 8'
,
commit_message:
'Added newfile'
commit_message:
'Changed file'
}
}
}
it
"should update existing file in project repo"
do
Gitlab
::
Satellite
::
EditFileAction
.
any_instance
.
stub
(
commit!:
true
,
)
put
api
(
"/projects/
#{
project
.
id
}
/repository/files"
,
user
),
valid_params
response
.
status
.
should
==
200
json_response
[
'file_path'
].
should
==
'spec/spec_helper.rb'
end
it
"should return a 400 bad request if no params given"
do
put
api
(
"/projects/
#{
project
.
id
}
/repository/files"
,
user
)
response
.
status
.
should
==
400
end
it
"should return a 400 if satellite fails to create file"
do
Gitlab
::
Satellite
::
EditFileAction
.
any_instance
.
stub
(
commit!:
false
,
)
put
api
(
"/projects/
#{
project
.
id
}
/repository/files"
,
user
),
valid_params
response
.
status
.
should
==
400
end
end
end
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