Skip to content

Commit f00340f

Browse files
author
Gauvain Pocentek
committed
docs: repository files API
1 parent 71a2a4f commit f00340f

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

docs/gl_objects/projects.py

+48
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,51 @@
194194
# repository contributors
195195
contributors = project.repository_contributors()
196196
# end repository contributors
197+
198+
# files get
199+
f = gl.project_files.get(file_path='README.rst', ref='master',
200+
project_id=1)
201+
# or
202+
f = project.files.get(file_path='README.rst', ref='master')
203+
204+
# get the base64 encoded content
205+
print(f.content)
206+
207+
# get the decoded content
208+
print(f.decode())
209+
# end files get
210+
211+
# files create
212+
f = gl.project_files.create({'file_path': 'testfile',
213+
'branch_name': 'master',
214+
'content': file_content,
215+
'commit_message': 'Create testfile'},
216+
project_id=1)
217+
# or
218+
f = project.files.create({'file_path': 'testfile',
219+
'branch_name': 'master',
220+
'content': file_content,
221+
'commit_message': 'Create testfile'})
222+
# end files create
223+
224+
# files update
225+
f.content = 'new content'
226+
f.save(branch='master', commit_message='Update testfile')
227+
228+
# or for binary data
229+
f.content = base64.b64encode(open('image.png').read())
230+
f.save(branch='master', commit_message='Update testfile', encoding='base64')
231+
# end files update
232+
233+
# files delete
234+
gl.project_files.delete({'file_path': 'testfile',
235+
'branch_name': 'master',
236+
'commit_message': 'Delete testfile'},
237+
project_id=1)
238+
# or
239+
project.files.delete({'file_path': 'testfile',
240+
'branch_name': 'master',
241+
'commit_message': 'Delete testfile'})
242+
# or
243+
f.delete(commit_message='Delete testfile')
244+
# end files delete

docs/gl_objects/projects.rst

+30
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,36 @@ Get a list of contributors for the repository:
139139
:start-after: # repository contributors
140140
:end-before: # end repository contributors
141141

142+
Files
143+
-----
144+
145+
The following examples show how you can manipulate the project files.
146+
147+
Get a file:
148+
149+
.. literalinclude:: projects.py
150+
:start-after: # files get
151+
:end-before: # end files get
152+
153+
Create a new file:
154+
155+
.. literalinclude:: projects.py
156+
:start-after: # files create
157+
:end-before: # end files create
158+
159+
Update a file. The entire content must be uploaded, as plain text or as base64
160+
encoded text:
161+
162+
.. literalinclude:: projects.py
163+
:start-after: # files update
164+
:end-before: # end files update
165+
166+
Delete a file:
167+
168+
.. literalinclude:: projects.py
169+
:start-after: # files delete
170+
:end-before: # end files delete
171+
142172
Events
143173
------
144174

0 commit comments

Comments
 (0)