X Tutup
Skip to content

Latest commit

 

History

History
757 lines (475 loc) · 17.1 KB

File metadata and controls

757 lines (475 loc) · 17.1 KB
 
Jul 16, 2016
Jul 16, 2016
1
########
2
Projects
3
########
4
Aug 11, 2017
Aug 11, 2017
5
Projects
6
========
7
8
Reference
9
---------
10
11
* v4 API:
12
13
+ :class:`gitlab.v4.objects.Project`
14
+ :class:`gitlab.v4.objects.ProjectManager`
15
+ :attr:`gitlab.Gitlab.projects`
16
17
* GitLab API: https://docs.gitlab.com/ce/api/projects.html
Jul 16, 2016
Jul 16, 2016
18
19
Examples
Aug 11, 2017
Aug 11, 2017
20
--------
Jul 16, 2016
Jul 16, 2016
21
May 20, 2018
May 20, 2018
22
List projects::
23
24
projects = gl.projects.list()
Jul 16, 2016
Jul 16, 2016
25
26
The API provides several filtering parameters for the listing methods:
27
28
* ``archived``: if ``True`` only archived projects will be returned
29
* ``visibility``: returns only projects with the specified visibility (can be
30
``public``, ``internal`` or ``private``)
31
* ``search``: returns project matching the given pattern
32
33
Results can also be sorted using the following parameters:
34
35
* ``order_by``: sort using the given argument. Valid values are ``id``,
36
``name``, ``path``, ``created_at``, ``updated_at`` and ``last_activity_at``.
37
The default is to sort by ``created_at``
38
* ``sort``: sort order (``asc`` or ``desc``)
39
May 20, 2018
May 20, 2018
40
::
41
Jul 21, 2019
Jul 21, 2019
42
# List all projects (default 20)
43
projects = gl.projects.list(all=True)
May 20, 2018
May 20, 2018
44
# Archived projects
45
projects = gl.projects.list(archived=1)
46
# Limit to projects with a defined visibility
47
projects = gl.projects.list(visibility='public')
Jul 16, 2016
Jul 16, 2016
48
May 20, 2018
May 20, 2018
49
# List owned projects
Sep 4, 2018
Sep 4, 2018
50
projects = gl.projects.list(owned=True)
Jul 16, 2016
Jul 16, 2016
51
May 20, 2018
May 20, 2018
52
# List starred projects
Sep 4, 2018
Sep 4, 2018
53
projects = gl.projects.list(starred=True)
Jul 16, 2016
Jul 16, 2016
54
May 20, 2018
May 20, 2018
55
# Search projects
56
projects = gl.projects.list(search='keyword')
Jul 16, 2016
Jul 16, 2016
57
Oct 2, 2019
Oct 2, 2019
58
.. note::
59
60
Fetching a list of projects, doesn't include all attributes of all projects.
61
To retrieve all attributes, you'll need to fetch a single project
62
May 20, 2018
May 20, 2018
63
Get a single project::
Jul 16, 2016
Jul 16, 2016
64
May 20, 2018
May 20, 2018
65
# Get a project by ID
Jun 27, 2018
Jun 27, 2018
66
project = gl.projects.get(project_id)
May 20, 2018
May 20, 2018
67
# Get a project by userspace/name
68
project = gl.projects.get('myteam/myproject')
Jul 16, 2016
Jul 16, 2016
69
May 20, 2018
May 20, 2018
70
Create a project::
Sep 21, 2016
Sep 21, 2016
71
May 20, 2018
May 20, 2018
72
project = gl.projects.create({'name': 'project1'})
Sep 21, 2016
Sep 21, 2016
73
May 20, 2018
May 20, 2018
74
Create a project for a user (admin only)::
Sep 21, 2016
Sep 21, 2016
75
May 20, 2018
May 20, 2018
76
alice = gl.users.list(username='alice')[0]
77
user_project = alice.projects.create({'name': 'project'})
78
user_projects = alice.projects.list()
Sep 21, 2016
Sep 21, 2016
79
May 20, 2018
May 20, 2018
80
Create a project in a group::
Sep 21, 2016
Sep 21, 2016
81
May 20, 2018
May 20, 2018
82
# You need to get the id of the group, then use the namespace_id attribute
83
# to create the group
84
group_id = gl.groups.search('my-group')[0].id
85
project = gl.projects.create({'name': 'myrepo', 'namespace_id': group_id})
Jul 16, 2016
Jul 16, 2016
86
May 20, 2018
May 20, 2018
87
Update a project::
Jul 16, 2016
Jul 16, 2016
88
May 20, 2018
May 20, 2018
89
project.snippets_enabled = 1
90
project.save()
Jul 16, 2016
Jul 16, 2016
91
Aug 14, 2019
Aug 14, 2019
92
Set the avatar image for a project::
93
94
# the avatar image can be passed as data (content of the file) or as a file
95
# object opened in binary mode
96
project.avatar = open('path/to/file.png', 'rb')
97
project.save()
98
May 20, 2018
May 20, 2018
99
Delete a project::
Jul 16, 2016
Jul 16, 2016
100
Jun 27, 2018
Jun 27, 2018
101
gl.projects.delete(project_id)
May 20, 2018
May 20, 2018
102
# or
103
project.delete()
104
105
Fork a project::
106
107
fork = project.forks.create({})
Jul 16, 2016
Jul 16, 2016
108
May 20, 2018
May 20, 2018
109
# fork to a specific namespace
110
fork = project.forks.create({'namespace': 'myteam'})
Jul 16, 2016
Jul 16, 2016
111
Jul 26, 2018
Jul 26, 2018
112
Get a list of forks for the project::
113
114
forks = project.forks.list()
115
May 20, 2018
May 20, 2018
116
Create/delete a fork relation between projects (requires admin permissions)::
Jul 17, 2016
Jul 17, 2016
117
May 20, 2018
May 20, 2018
118
project.create_fork_relation(source_project.id)
119
project.delete_fork_relation()
Jul 17, 2016
Jul 17, 2016
120
May 29, 2018
May 29, 2018
121
Get languages used in the project with percentage value::
122
123
languages = project.languages()
124
May 20, 2018
May 20, 2018
125
Star/unstar a project::
Jul 16, 2016
Jul 16, 2016
126
May 20, 2018
May 20, 2018
127
project.star()
128
project.unstar()
Jul 16, 2016
Jul 16, 2016
129
May 20, 2018
May 20, 2018
130
Archive/unarchive a project::
Jul 16, 2016
Jul 16, 2016
131
May 20, 2018
May 20, 2018
132
project.archive()
133
project.unarchive()
Jul 16, 2016
Jul 16, 2016
134
May 20, 2018
May 20, 2018
135
Start the housekeeping job::
Jul 16, 2016
Jul 16, 2016
136
May 20, 2018
May 20, 2018
137
project.housekeeping()
Jul 16, 2016
Jul 16, 2016
138
May 20, 2018
May 20, 2018
139
List the repository tree::
Nov 12, 2017
Nov 12, 2017
140
May 20, 2018
May 20, 2018
141
# list the content of the root directory for the default branch
142
items = project.repository_tree()
Nov 12, 2017
Nov 12, 2017
143
May 20, 2018
May 20, 2018
144
# list the content of a subdirectory on a specific branch
145
items = project.repository_tree(path='docs', ref='branch1')
Aug 9, 2016
Aug 9, 2016
146
May 20, 2018
May 20, 2018
147
Get the content and metadata of a file for a commit, using a blob sha::
Aug 9, 2016
Aug 9, 2016
148
May 20, 2018
May 20, 2018
149
items = project.repository_tree(path='docs', ref='branch1')
150
file_info = p.repository_blob(items[0]['id'])
151
content = base64.b64decode(file_info['content'])
152
size = file_info['size']
Aug 9, 2016
Aug 9, 2016
153
Oct 6, 2019
Oct 6, 2019
154
Update a project submodule::
155
156
items = project.update_submodule(
157
submodule="foo/bar",
158
branch="master",
159
commit_sha="4c3674f66071e30b3311dac9b9ccc90502a72664",
160
commit_message="Message", # optional
161
)
162
May 20, 2018
May 20, 2018
163
Get the repository archive::
Aug 9, 2016
Aug 9, 2016
164
May 20, 2018
May 20, 2018
165
tgz = project.repository_archive()
Aug 9, 2016
Aug 9, 2016
166
May 20, 2018
May 20, 2018
167
# get the archive for a branch/tag/commit
168
tgz = project.repository_archive(sha='4567abc')
Aug 9, 2016
Aug 9, 2016
169
170
.. warning::
171
172
Archives are entirely stored in memory unless you use the streaming feature.
173
See :ref:`the artifacts example <streaming_example>`.
174
May 20, 2018
May 20, 2018
175
Get the content of a file using the blob id::
Aug 9, 2016
Aug 9, 2016
176
May 20, 2018
May 20, 2018
177
# find the id for the blob (simple search)
178
id = [d['id'] for d in p.repository_tree() if d['name'] == 'README.rst'][0]
179
180
# get the content
181
file_content = p.repository_raw_blob(id)
Aug 9, 2016
Aug 9, 2016
182
183
.. warning::
184
185
Blobs are entirely stored in memory unless you use the streaming feature.
186
See :ref:`the artifacts example <streaming_example>`.
187
May 29, 2018
May 29, 2018
188
Get a snapshot of the repository::
189
190
tar_file = project.snapshot()
191
192
.. warning::
193
194
Snapshots are entirely stored in memory unless you use the streaming
195
feature. See :ref:`the artifacts example <streaming_example>`.
196
May 20, 2018
May 20, 2018
197
Compare two branches, tags or commits::
198
199
result = project.repository_compare('master', 'branch1')
Aug 9, 2016
Aug 9, 2016
200
May 20, 2018
May 20, 2018
201
# get the commits
202
for commit in result['commits']:
203
print(commit)
Aug 9, 2016
Aug 9, 2016
204
May 20, 2018
May 20, 2018
205
# get the diffs
206
for file_diff in result['diffs']:
207
print(file_diff)
Aug 9, 2016
Aug 9, 2016
208
May 20, 2018
May 20, 2018
209
Get a list of contributors for the repository::
Aug 9, 2016
Aug 9, 2016
210
May 20, 2018
May 20, 2018
211
contributors = project.repository_contributors()
Oct 8, 2017
Oct 8, 2017
212
May 20, 2018
May 20, 2018
213
Get a list of users for the repository::
214
215
users = p.users.list()
216
217
# search for users
218
users = p.users.list(search='pattern')
Oct 8, 2017
Oct 8, 2017
219
Jun 10, 2018
Jun 10, 2018
220
Start the pull mirroring process (EE edition)::
221
222
project.mirror_pull()
223
May 21, 2018
May 21, 2018
224
Import / Export
225
===============
226
227
You can export projects from gitlab, and re-import them to create new projects
228
or overwrite existing ones.
229
230
Reference
231
---------
232
233
* v4 API:
234
235
+ :class:`gitlab.v4.objects.ProjectExport`
236
+ :class:`gitlab.v4.objects.ProjectExportManager`
237
+ :attr:`gitlab.v4.objects.Project.exports`
238
+ :class:`gitlab.v4.objects.ProjectImport`
239
+ :class:`gitlab.v4.objects.ProjectImportManager`
240
+ :attr:`gitlab.v4.objects.Project.imports`
241
+ :attr:`gitlab.v4.objects.ProjectManager.import_project`
242
243
* GitLab API: https://docs.gitlab.com/ce/api/project_import_export.html
244
245
Examples
246
--------
247
248
A project export is an asynchronous operation. To retrieve the archive
249
generated by GitLab you need to:
250
251
#. Create an export using the API
252
#. Wait for the export to be done
253
#. Download the result
254
255
::
256
257
# Create the export
258
p = gl.projects.get(my_project)
259
export = p.exports.create({})
260
261
# Wait for the 'finished' status
262
export.refresh()
263
while export.export_status != 'finished':
264
time.sleep(1)
265
export.refresh()
266
267
# Download the result
268
with open('/tmp/export.tgz', 'wb') as f:
269
export.download(streamed=True, action=f.write)
270
271
Import the project::
272
Feb 28, 2019
Feb 28, 2019
273
output = gl.projects.import_project(open('/tmp/export.tgz', 'rb'), 'my_new_project')
May 21, 2018
May 21, 2018
274
# Get a ProjectImport object to track the import status
275
project_import = gl.projects.get(output['id'], lazy=True).imports.get()
276
while project_import.import_status != 'finished':
277
time.sleep(1)
278
project_import.refresh()
279
280
Jan 1, 2018
Jan 1, 2018
281
Project custom attributes
282
=========================
283
284
Reference
285
---------
286
287
* v4 API:
288
289
+ :class:`gitlab.v4.objects.ProjectCustomAttribute`
290
+ :class:`gitlab.v4.objects.ProjectCustomAttributeManager`
291
+ :attr:`gitlab.v4.objects.Project.customattributes`
292
293
* GitLab API: https://docs.gitlab.com/ce/api/custom_attributes.html
294
295
Examples
296
--------
297
298
List custom attributes for a project::
299
300
attrs = project.customattributes.list()
301
302
Get a custom attribute for a project::
303
304
attr = project.customattributes.get(attr_key)
305
306
Set (create or update) a custom attribute for a project::
307
308
attr = project.customattributes.set(attr_key, attr_value)
309
310
Delete a custom attribute for a project::
311
312
attr.delete()
313
# or
314
project.customattributes.delete(attr_key)
315
Jan 1, 2018
Jan 1, 2018
316
Search projects by custom attribute::
317
Aug 20, 2018
Aug 20, 2018
318
project.customattributes.set('type', 'internal')
Jan 1, 2018
Jan 1, 2018
319
gl.projects.list(custom_attributes={'type': 'internal'})
320
Aug 11, 2017
Aug 11, 2017
321
Project files
322
=============
323
324
Reference
325
---------
326
327
* v4 API:
Aug 9, 2016
Aug 9, 2016
328
Aug 11, 2017
Aug 11, 2017
329
+ :class:`gitlab.v4.objects.ProjectFile`
330
+ :class:`gitlab.v4.objects.ProjectFileManager`
331
+ :attr:`gitlab.v4.objects.Project.files`
332
333
* GitLab API: https://docs.gitlab.com/ce/api/repository_files.html
334
335
Examples
336
--------
Aug 9, 2016
Aug 9, 2016
337
May 20, 2018
May 20, 2018
338
Get a file::
339
340
f = project.files.get(file_path='README.rst', ref='master')
Aug 9, 2016
Aug 9, 2016
341
May 20, 2018
May 20, 2018
342
# get the base64 encoded content
343
print(f.content)
Aug 9, 2016
Aug 9, 2016
344
May 20, 2018
May 20, 2018
345
# get the decoded content
346
print(f.decode())
Aug 9, 2016
Aug 9, 2016
347
May 20, 2018
May 20, 2018
348
Create a new file::
349
350
f = project.files.create({'file_path': 'testfile.txt',
351
'branch': 'master',
352
'content': file_content,
353
'author_email': 'test@example.com',
354
'author_name': 'yourname',
355
'encoding': 'text',
356
'commit_message': 'Create testfile'})
Aug 9, 2016
Aug 9, 2016
357
358
Update a file. The entire content must be uploaded, as plain text or as base64
May 20, 2018
May 20, 2018
359
encoded text::
360
361
f.content = 'new content'
Jun 10, 2018
Jun 10, 2018
362
f.save(branch='master', commit_message='Update testfile')
Aug 9, 2016
Aug 9, 2016
363
May 20, 2018
May 20, 2018
364
# or for binary data
365
# Note: decode() is required with python 3 for data serialization. You can omit
366
# it with python 2
367
f.content = base64.b64encode(open('image.png').read()).decode()
368
f.save(branch='master', commit_message='Update testfile', encoding='base64')
Aug 9, 2016
Aug 9, 2016
369
May 20, 2018
May 20, 2018
370
Delete a file::
Aug 9, 2016
Aug 9, 2016
371
May 20, 2018
May 20, 2018
372
f.delete(commit_message='Delete testfile')
Aug 9, 2016
Aug 9, 2016
373
Oct 4, 2019
Oct 4, 2019
374
Get file blame::
375
376
b = project.files.blame(file_path='README.rst', ref='master')
377
Aug 11, 2017
Aug 11, 2017
378
Project tags
379
============
380
381
Reference
382
---------
383
384
* v4 API:
385
386
+ :class:`gitlab.v4.objects.ProjectTag`
387
+ :class:`gitlab.v4.objects.ProjectTagManager`
388
+ :attr:`gitlab.v4.objects.Project.tags`
389
390
* GitLab API: https://docs.gitlab.com/ce/api/tags.html
391
392
Examples
393
--------
Aug 9, 2016
Aug 9, 2016
394
May 20, 2018
May 20, 2018
395
List the project tags::
Aug 9, 2016
Aug 9, 2016
396
May 20, 2018
May 20, 2018
397
tags = project.tags.list()
Aug 9, 2016
Aug 9, 2016
398
May 20, 2018
May 20, 2018
399
Get a tag::
Aug 9, 2016
Aug 9, 2016
400
May 20, 2018
May 20, 2018
401
tag = project.tags.get('1.0')
Aug 9, 2016
Aug 9, 2016
402
May 20, 2018
May 20, 2018
403
Create a tag::
Aug 9, 2016
Aug 9, 2016
404
May 20, 2018
May 20, 2018
405
tag = project.tags.create({'tag_name': '1.0', 'ref': 'master'})
Aug 9, 2016
Aug 9, 2016
406
May 20, 2018
May 20, 2018
407
Set or update the release note for a tag::
Aug 9, 2016
Aug 9, 2016
408
May 20, 2018
May 20, 2018
409
tag.set_release_description('awesome v1.0 release')
Aug 9, 2016
Aug 9, 2016
410
May 20, 2018
May 20, 2018
411
Delete a tag::
Aug 9, 2016
Aug 9, 2016
412
May 20, 2018
May 20, 2018
413
project.tags.delete('1.0')
414
# or
415
tag.delete()
Aug 9, 2016
Aug 9, 2016
416
Dec 25, 2016
Dec 25, 2016
417
.. _project_snippets:
418
Aug 11, 2017
Aug 11, 2017
419
Project snippets
420
================
Aug 9, 2016
Aug 9, 2016
421
Mar 2, 2018
Mar 2, 2018
422
The snippet visibility can be defined using the following constants:
Aug 11, 2017
Aug 11, 2017
423
424
* ``gitlab.VISIBILITY_PRIVATE``
425
* ``gitlab.VISIBILITY_INTERNAL``
426
* ``gitlab.VISIBILITY_PUBLIC``
427
428
Reference
429
---------
430
431
* v4 API:
432
433
+ :class:`gitlab.v4.objects.ProjectSnippet`
434
+ :class:`gitlab.v4.objects.ProjectSnippetManager`
435
+ :attr:`gitlab.v4.objects.Project.files`
436
437
* GitLab API: https://docs.gitlab.com/ce/api/project_snippets.html
438
439
Examples
440
--------
Aug 9, 2016
Aug 9, 2016
441
May 20, 2018
May 20, 2018
442
List the project snippets::
Aug 9, 2016
Aug 9, 2016
443
May 20, 2018
May 20, 2018
444
snippets = project.snippets.list()
Aug 9, 2016
Aug 9, 2016
445
May 20, 2018
May 20, 2018
446
Get a snippet::
Aug 9, 2016
Aug 9, 2016
447
May 20, 2018
May 20, 2018
448
snippets = project.snippets.list(snippet_id)
Aug 9, 2016
Aug 9, 2016
449
May 20, 2018
May 20, 2018
450
Get the content of a snippet::
Aug 9, 2016
Aug 9, 2016
451
May 20, 2018
May 20, 2018
452
print(snippet.content())
Aug 9, 2016
Aug 9, 2016
453
454
.. warning::
455
456
The snippet content is entirely stored in memory unless you use the
457
streaming feature. See :ref:`the artifacts example <streaming_example>`.
458
May 20, 2018
May 20, 2018
459
Create a snippet::
Aug 9, 2016
Aug 9, 2016
460
May 20, 2018
May 20, 2018
461
snippet = project.snippets.create({'title': 'sample 1',
462
'file_name': 'foo.py',
463
'code': 'import gitlab',
464
'visibility_level':
465
gitlab.VISIBILITY_PRIVATE})
Aug 9, 2016
Aug 9, 2016
466
May 20, 2018
May 20, 2018
467
Update a snippet::
Aug 9, 2016
Aug 9, 2016
468
May 20, 2018
May 20, 2018
469
snippet.code = 'import gitlab\nimport whatever'
470
snippet.save
Aug 9, 2016
Aug 9, 2016
471
May 20, 2018
May 20, 2018
472
Delete a snippet::
Aug 9, 2016
Aug 9, 2016
473
May 20, 2018
May 20, 2018
474
project.snippets.delete(snippet_id)
475
# or
476
snippet.delete()
Aug 9, 2016
Aug 9, 2016
477
May 27, 2018
May 27, 2018
478
Get user agent detail (admin only)::
479
480
detail = snippet.user_agent_detail()
481
Aug 9, 2016
Aug 9, 2016
482
Notes
Aug 11, 2017
Aug 11, 2017
483
=====
Aug 9, 2016
Aug 9, 2016
484
Mar 28, 2018
Mar 28, 2018
485
See :ref:`project-notes`.
Aug 9, 2016
Aug 9, 2016
486
Aug 11, 2017
Aug 11, 2017
487
Project members
488
===============
Jul 16, 2016
Jul 16, 2016
489
Aug 11, 2017
Aug 11, 2017
490
Reference
491
---------
492
493
* v4 API:
494
495
+ :class:`gitlab.v4.objects.ProjectMember`
496
+ :class:`gitlab.v4.objects.ProjectMemberManager`
497
+ :attr:`gitlab.v4.objects.Project.members`
498
499
* GitLab API: https://docs.gitlab.com/ce/api/members.html
500
501
Examples
502
--------
Jul 16, 2016
Jul 16, 2016
503
May 20, 2018
May 20, 2018
504
List the project members::
Jul 16, 2016
Jul 16, 2016
505
May 20, 2018
May 20, 2018
506
members = project.members.list()
Jul 16, 2016
Jul 16, 2016
507
Nov 24, 2018
Nov 24, 2018
508
List the project members recursively (including inherited members through
509
ancestor groups)::
510
511
members = project.members.all(all=True)
512
May 20, 2018
May 20, 2018
513
Search project members matching a query string::
Jul 16, 2016
Jul 16, 2016
514
May 20, 2018
May 20, 2018
515
members = project.members.list(query='bar')
Jul 16, 2016
Jul 16, 2016
516
May 20, 2018
May 20, 2018
517
Get a single project member::
Jul 16, 2016
Jul 16, 2016
518
Jun 27, 2018
Jun 27, 2018
519
member = project.members.get(user_id)
Jul 16, 2016
Jul 16, 2016
520
May 20, 2018
May 20, 2018
521
Add a project member::
Jul 16, 2016
Jul 16, 2016
522
May 20, 2018
May 20, 2018
523
member = project.members.create({'user_id': user.id, 'access_level':
524
gitlab.DEVELOPER_ACCESS})
Jul 16, 2016
Jul 16, 2016
525
May 20, 2018
May 20, 2018
526
Modify a project member (change the access level)::
Jul 16, 2016
Jul 16, 2016
527
Oct 6, 2018
Oct 6, 2018
528
member.access_level = gitlab.MAINTAINER_ACCESS
May 20, 2018
May 20, 2018
529
member.save()
Jul 16, 2016
Jul 16, 2016
530
May 20, 2018
May 20, 2018
531
Remove a member from the project team::
Jul 16, 2016
Jul 16, 2016
532
May 20, 2018
May 20, 2018
533
project.members.delete(user.id)
534
# or
535
member.delete()
Jul 16, 2016
Jul 16, 2016
536
May 20, 2018
May 20, 2018
537
Share/unshare the project with a group::
Jul 16, 2016
Jul 16, 2016
538
May 20, 2018
May 20, 2018
539
project.share(group.id, gitlab.DEVELOPER_ACCESS)
540
project.unshare(group.id)
Jul 17, 2016
Jul 17, 2016
541
Aug 11, 2017
Aug 11, 2017
542
Project hooks
543
=============
544
545
Reference
546
---------
547
548
* v4 API:
549
550
+ :class:`gitlab.v4.objects.ProjectHook`
551
+ :class:`gitlab.v4.objects.ProjectHookManager`
552
+ :attr:`gitlab.v4.objects.Project.hooks`
553
554
* GitLab API: https://docs.gitlab.com/ce/api/projects.html#hooks
Jul 17, 2016
Jul 17, 2016
555
Aug 11, 2017
Aug 11, 2017
556
Examples
557
--------
Jul 17, 2016
Jul 17, 2016
558
May 20, 2018
May 20, 2018
559
List the project hooks::
Jul 17, 2016
Jul 17, 2016
560
May 20, 2018
May 20, 2018
561
hooks = project.hooks.list()
Jul 17, 2016
Jul 17, 2016
562
May 20, 2018
May 20, 2018
563
Get a project hook::
Jul 17, 2016
Jul 17, 2016
564
Jun 27, 2018
Jun 27, 2018
565
hook = project.hooks.get(hook_id)
Jul 17, 2016
Jul 17, 2016
566
May 20, 2018
May 20, 2018
567
Create a project hook::
Jul 17, 2016
Jul 17, 2016
568
May 20, 2018
May 20, 2018
569
hook = project.hooks.create({'url': 'http://my/action/url', 'push_events': 1})
Jul 17, 2016
Jul 17, 2016
570
May 20, 2018
May 20, 2018
571
Update a project hook::
Jul 17, 2016
Jul 17, 2016
572
May 20, 2018
May 20, 2018
573
hook.push_events = 0
574
hook.save()
Jul 17, 2016
Jul 17, 2016
575
May 20, 2018
May 20, 2018
576
Delete a project hook::
Jul 17, 2016
Jul 17, 2016
577
Jun 27, 2018
Jun 27, 2018
578
project.hooks.delete(hook_id)
May 20, 2018
May 20, 2018
579
# or
580
hook.delete()
Aug 13, 2016
Aug 13, 2016
581
Aug 11, 2017
Aug 11, 2017
582
Project Services
583
================
584
585
Reference
586
---------
587
588
* v4 API:
589
590
+ :class:`gitlab.v4.objects.ProjectService`
591
+ :class:`gitlab.v4.objects.ProjectServiceManager`
592
+ :attr:`gitlab.v4.objects.Project.services`
593
594
* GitLab API: https://docs.gitlab.com/ce/api/services.html
595
Apr 12, 2018
Apr 12, 2018
596
Examples
Aug 11, 2017
Aug 11, 2017
597
---------
Aug 13, 2016
Aug 13, 2016
598
May 20, 2018
May 20, 2018
599
Get a service::
Aug 13, 2016
Aug 13, 2016
600
May 20, 2018
May 20, 2018
601
service = project.services.get('asana')
602
# display its status (enabled/disabled)
603
print(service.active)
Aug 13, 2016
Aug 13, 2016
604
May 20, 2018
May 20, 2018
605
List the code names of available services (doesn't return objects)::
Aug 13, 2016
Aug 13, 2016
606
May 20, 2018
May 20, 2018
607
services = project.services.available()
Aug 13, 2016
Aug 13, 2016
608
May 20, 2018
May 20, 2018
609
Configure and enable a service::
Aug 13, 2016
Aug 13, 2016
610
May 20, 2018
May 20, 2018
611
service.api_key = 'randomkey'
612
service.save()
Aug 13, 2016
Aug 13, 2016
613
May 20, 2018
May 20, 2018
614
Disable a service::
Aug 13, 2016
Aug 13, 2016
615
May 20, 2018
May 20, 2018
616
service.delete()
Oct 23, 2016
Oct 23, 2016
617
Oct 8, 2017
Oct 8, 2017
618
File uploads
Sep 12, 2017
Sep 12, 2017
619
============
620
621
Reference
622
---------
623
624
* v4 API:
625
626
+ :attr:`gitlab.v4.objects.Project.upload`
627
628
* Gitlab API: https://docs.gitlab.com/ce/api/projects.html#upload-a-file
629
630
Examples
631
--------
632
May 20, 2018
May 20, 2018
633
Upload a file into a project using a filesystem path::
Sep 12, 2017
Sep 12, 2017
634
May 20, 2018
May 20, 2018
635
project.upload("filename.txt", filepath="/some/path/filename.txt")
Sep 12, 2017
Sep 12, 2017
636
May 20, 2018
May 20, 2018
637
Upload a file into a project without a filesystem path::
Sep 12, 2017
Sep 12, 2017
638
May 20, 2018
May 20, 2018
639
project.upload("filename.txt", filedata="Raw data")
Sep 12, 2017
Sep 12, 2017
640
641
Upload a file and comment on an issue using the uploaded file's
May 20, 2018
May 20, 2018
642
markdown::
Sep 12, 2017
Sep 12, 2017
643
May 20, 2018
May 20, 2018
644
uploaded_file = project.upload("filename.txt", filedata="data")
645
issue = project.issues.get(issue_id)
646
issue.notes.create({
647
"body": "See the attached file: {}".format(uploaded_file["markdown"])
648
})
Sep 12, 2017
Sep 12, 2017
649
650
Upload a file and comment on an issue while using custom
May 20, 2018
May 20, 2018
651
markdown to reference the uploaded file::
Sep 12, 2017
Sep 12, 2017
652
May 20, 2018
May 20, 2018
653
uploaded_file = project.upload("filename.txt", filedata="data")
654
issue = project.issues.get(issue_id)
655
issue.notes.create({
656
"body": "See the [attached file]({})".format(uploaded_file["url"])
657
})
Jun 11, 2018
Jun 11, 2018
658
659
Project push rules
660
==================
661
662
Reference
663
---------
664
665
* v4 API:
666
667
+ :class:`gitlab.v4.objects.ProjectPushRules`
668
+ :class:`gitlab.v4.objects.ProjectPushRulesManager`
669
+ :attr:`gitlab.v4.objects.Project.pushrules`
670
671
* GitLab API: https://docs.gitlab.com/ee/api/projects.html#push-rules
672
673
Examples
674
---------
675
676
Create project push rules (at least one rule is necessary)::
677
678
project.pushrules.create({'deny_delete_tag': True})
679
680
Get project push rules (returns None is there are no push rules)::
681
682
pr = project.pushrules.get()
683
684
Edit project push rules::
685
686
pr.branch_name_regex = '^(master|develop|support-\d+|release-\d+\..+|hotfix-.+|feature-.+)$'
687
pr.save()
688
689
Delete project push rules::
690
691
pr.delete()
Oct 3, 2018
Oct 3, 2018
692
Mar 27, 2019
Mar 27, 2019
693
Project releases
694
================
695
696
Reference
697
---------
698
699
* v4 API:
700
701
+ :class:`gitlab.v4.objects.ProjectRelease`
702
+ :class:`gitlab.v4.objects.ProjectReleaseManager`
703
+ :attr:`gitlab.v4.objects.Project.releases`
704
705
* Gitlab API: https://docs.gitlab.com/ee/api/releases/index.html
706
707
Examples
708
--------
709
710
Get a list of releases from a project::
711
712
release = project.releases.list()
713
714
Get a single release::
715
716
release = project.releases.get('v1.2.3')
717
718
Create a release for a project tag::
719
720
release = project.releases.create({'name':'Demo Release', 'tag_name':'v1.2.3', 'description':'release notes go here'})
721
722
Delete a release::
723
724
release = p.releases.delete('v1.2.3')
725
Oct 3, 2018
Oct 3, 2018
726
Project protected tags
Nov 22, 2018
Nov 22, 2018
727
======================
Oct 3, 2018
Oct 3, 2018
728
729
Reference
730
---------
731
732
* v4 API:
733
734
+ :class:`gitlab.v4.objects.ProjectProtectedTag`
735
+ :class:`gitlab.v4.objects.ProjectProtectedTagManager`
736
+ :attr:`gitlab.v4.objects.Project.protectedtags`
737
738
* GitLab API: https://docs.gitlab.com/ce/api/protected_tags.html
739
740
Examples
741
---------
742
743
Get a list of protected tags from a project::
744
745
protected_tags = project.protectedtags.list()
746
747
Get a single protected tag or wildcard protected tag::
748
749
protected_tag = project.protectedtags.get('v*')
750
751
Protect a single repository tag or several project repository tags using a wildcard protected tag::
752
753
project.protectedtags.create({'name': 'v*', 'create_access_level': '40'})
754
755
Unprotect the given protected tag or wildcard protected tag.::
756
757
protected_tag.delete()
X Tutup