Skip to content

Commit 570e75d

Browse files
author
Gauvain Pocentek
committed
Add support for templates API
Add gitlab CI and gitignores APIs Rework the templates/license API docs
1 parent 463893f commit 570e75d

File tree

7 files changed

+125
-30
lines changed

7 files changed

+125
-30
lines changed

docs/api-objects.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ API objects manipulation
1616
gl_objects/groups
1717
gl_objects/issues
1818
gl_objects/labels
19-
gl_objects/licenses
2019
gl_objects/notifications
2120
gl_objects/mrs
2221
gl_objects/namespaces
@@ -25,6 +24,7 @@ API objects manipulation
2524
gl_objects/runners
2625
gl_objects/settings
2726
gl_objects/system_hooks
27+
gl_objects/templates
2828
gl_objects/todos
2929
gl_objects/users
3030
gl_objects/sidekiq

docs/gl_objects/licenses.py

-8
This file was deleted.

docs/gl_objects/licenses.rst

-21
This file was deleted.

docs/gl_objects/templates.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# license list
2+
licenses = gl.licenses.list()
3+
# end license list
4+
5+
# license get
6+
license = gl.licenses.get('apache-2.0', project='foobar', fullname='John Doe')
7+
print(license.content)
8+
# end license get
9+
10+
# gitignore list
11+
gitignores = gl.gitignores.list()
12+
# end gitignore list
13+
14+
# gitignore get
15+
gitignore = gl.gitignores.get('Python')
16+
print(gitignore.content)
17+
# end gitignore get
18+
19+
# gitlabciyml list
20+
gitlabciymls = gl.gitlabciymls.list()
21+
# end gitlabciyml list
22+
23+
# gitlabciyml get
24+
gitlabciyml = gl.gitlabciymls.get('Pelican')
25+
print(gitlabciyml.content)
26+
# end gitlabciyml get

docs/gl_objects/templates.rst

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#########
2+
Templates
3+
#########
4+
5+
You can request templates for different type of files:
6+
7+
* License files
8+
* .gitignore files
9+
* GitLab CI configuration files
10+
11+
License templates
12+
=================
13+
14+
* Object class: :class:`~gitlab.objects.License`
15+
* Manager object: :attr:`gitlab.Gitlab.licenses`
16+
17+
Examples
18+
--------
19+
20+
List known license templates:
21+
22+
.. literalinclude:: templates.py
23+
:start-after: # license list
24+
:end-before: # end license list
25+
26+
Generate a license content for a project:
27+
28+
.. literalinclude:: templates.py
29+
:start-after: # license get
30+
:end-before: # end license get
31+
32+
.gitignore templates
33+
====================
34+
35+
* Object class: :class:`~gitlab.objects.Gitignore`
36+
* Manager object: :attr:`gitlab.Gitlab.gitognores`
37+
38+
Examples
39+
--------
40+
41+
List known gitignore templates:
42+
43+
.. literalinclude:: templates.py
44+
:start-after: # gitignore list
45+
:end-before: # end gitignore list
46+
47+
Get a gitignore template:
48+
49+
.. literalinclude:: templates.py
50+
:start-after: # gitignore get
51+
:end-before: # end gitignore get
52+
53+
GitLab CI templates
54+
===================
55+
56+
* Object class: :class:`~gitlab.objects.Gitlabciyml`
57+
* Manager object: :attr:`gitlab.Gitlab.gitlabciymls`
58+
59+
Examples
60+
--------
61+
62+
List known GitLab CI templates:
63+
64+
.. literalinclude:: templates.py
65+
:start-after: # gitlabciyml list
66+
:end-before: # end gitlabciyml list
67+
68+
Get a GitLab CI template:
69+
70+
.. literalinclude:: templates.py
71+
:start-after: # gitlabciyml get
72+
:end-before: # end gitlabciyml get

gitlab/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ def __init__(self, url, private_token=None, email=None, password=None,
9191

9292
self.broadcastmessages = BroadcastMessageManager(self)
9393
self.keys = KeyManager(self)
94+
self.gitlabciymls = GitlabciymlManager(self)
95+
self.gitignores = GitignoreManager(self)
9496
self.groups = GroupManager(self)
9597
self.hooks = HookManager(self)
9698
self.issues = IssueManager(self)

gitlab/objects.py

+24
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,30 @@ class NotificationSettingsManager(BaseManager):
811811
obj_cls = NotificationSettings
812812

813813

814+
class Gitignore(GitlabObject):
815+
_url = '/templates/gitignores'
816+
canDelete = False
817+
canUpdate = False
818+
canCreate = False
819+
idAttr = 'name'
820+
821+
822+
class GitignoreManager(BaseManager):
823+
obj_cls = Gitignore
824+
825+
826+
class Gitlabciyml(GitlabObject):
827+
_url = '/templates/gitlab_ci_ymls'
828+
canDelete = False
829+
canUpdate = False
830+
canCreate = False
831+
idAttr = 'name'
832+
833+
834+
class GitlabciymlManager(BaseManager):
835+
obj_cls = Gitlabciyml
836+
837+
814838
class GroupIssue(GitlabObject):
815839
_url = '/groups/%(group_id)s/issues'
816840
canGet = 'from_list'

0 commit comments

Comments
 (0)