Skip to content

Commit

Permalink
docs: repository files API
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauvain Pocentek committed Aug 9, 2016
1 parent 71a2a4f commit f00340f
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
48 changes: 48 additions & 0 deletions docs/gl_objects/projects.py
Expand Up @@ -194,3 +194,51 @@
# repository contributors
contributors = project.repository_contributors()
# end repository contributors

# files get
f = gl.project_files.get(file_path='README.rst', ref='master',
project_id=1)
# or
f = project.files.get(file_path='README.rst', ref='master')

# get the base64 encoded content
print(f.content)

# get the decoded content
print(f.decode())
# end files get

# files create
f = gl.project_files.create({'file_path': 'testfile',
'branch_name': 'master',
'content': file_content,
'commit_message': 'Create testfile'},
project_id=1)
# or
f = project.files.create({'file_path': 'testfile',
'branch_name': 'master',
'content': file_content,
'commit_message': 'Create testfile'})
# end files create

# files update
f.content = 'new content'
f.save(branch='master', commit_message='Update testfile')

# or for binary data
f.content = base64.b64encode(open('image.png').read())
f.save(branch='master', commit_message='Update testfile', encoding='base64')
# end files update

# files delete
gl.project_files.delete({'file_path': 'testfile',
'branch_name': 'master',
'commit_message': 'Delete testfile'},
project_id=1)
# or
project.files.delete({'file_path': 'testfile',
'branch_name': 'master',
'commit_message': 'Delete testfile'})
# or
f.delete(commit_message='Delete testfile')
# end files delete
30 changes: 30 additions & 0 deletions docs/gl_objects/projects.rst
Expand Up @@ -139,6 +139,36 @@ Get a list of contributors for the repository:
:start-after: # repository contributors
:end-before: # end repository contributors

Files
-----

The following examples show how you can manipulate the project files.

Get a file:

.. literalinclude:: projects.py
:start-after: # files get
:end-before: # end files get

Create a new file:

.. literalinclude:: projects.py
:start-after: # files create
:end-before: # end files create

Update a file. The entire content must be uploaded, as plain text or as base64
encoded text:

.. literalinclude:: projects.py
:start-after: # files update
:end-before: # end files update

Delete a file:

.. literalinclude:: projects.py
:start-after: # files delete
:end-before: # end files delete

Events
------

Expand Down

0 comments on commit f00340f

Please sign in to comment.