Skip to content

Commit

Permalink
Add support for templates API
Browse files Browse the repository at this point in the history
Add gitlab CI and gitignores APIs

Rework the templates/license API docs
  • Loading branch information
Gauvain Pocentek committed Nov 6, 2016
1 parent 463893f commit 570e75d
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 30 deletions.
2 changes: 1 addition & 1 deletion docs/api-objects.rst
Expand Up @@ -16,7 +16,6 @@ API objects manipulation
gl_objects/groups
gl_objects/issues
gl_objects/labels
gl_objects/licenses
gl_objects/notifications
gl_objects/mrs
gl_objects/namespaces
Expand All @@ -25,6 +24,7 @@ API objects manipulation
gl_objects/runners
gl_objects/settings
gl_objects/system_hooks
gl_objects/templates
gl_objects/todos
gl_objects/users
gl_objects/sidekiq
8 changes: 0 additions & 8 deletions docs/gl_objects/licenses.py

This file was deleted.

21 changes: 0 additions & 21 deletions docs/gl_objects/licenses.rst

This file was deleted.

26 changes: 26 additions & 0 deletions docs/gl_objects/templates.py
@@ -0,0 +1,26 @@
# license list
licenses = gl.licenses.list()
# end license list

# license get
license = gl.licenses.get('apache-2.0', project='foobar', fullname='John Doe')
print(license.content)
# end license get

# gitignore list
gitignores = gl.gitignores.list()
# end gitignore list

# gitignore get
gitignore = gl.gitignores.get('Python')
print(gitignore.content)
# end gitignore get

# gitlabciyml list
gitlabciymls = gl.gitlabciymls.list()
# end gitlabciyml list

# gitlabciyml get
gitlabciyml = gl.gitlabciymls.get('Pelican')
print(gitlabciyml.content)
# end gitlabciyml get
72 changes: 72 additions & 0 deletions docs/gl_objects/templates.rst
@@ -0,0 +1,72 @@
#########
Templates
#########

You can request templates for different type of files:

* License files
* .gitignore files
* GitLab CI configuration files

License templates
=================

* Object class: :class:`~gitlab.objects.License`
* Manager object: :attr:`gitlab.Gitlab.licenses`

Examples
--------

List known license templates:

.. literalinclude:: templates.py
:start-after: # license list
:end-before: # end license list

Generate a license content for a project:

.. literalinclude:: templates.py
:start-after: # license get
:end-before: # end license get

.gitignore templates
====================

* Object class: :class:`~gitlab.objects.Gitignore`
* Manager object: :attr:`gitlab.Gitlab.gitognores`

Examples
--------

List known gitignore templates:

.. literalinclude:: templates.py
:start-after: # gitignore list
:end-before: # end gitignore list

Get a gitignore template:

.. literalinclude:: templates.py
:start-after: # gitignore get
:end-before: # end gitignore get

GitLab CI templates
===================

* Object class: :class:`~gitlab.objects.Gitlabciyml`
* Manager object: :attr:`gitlab.Gitlab.gitlabciymls`

Examples
--------

List known GitLab CI templates:

.. literalinclude:: templates.py
:start-after: # gitlabciyml list
:end-before: # end gitlabciyml list

Get a GitLab CI template:

.. literalinclude:: templates.py
:start-after: # gitlabciyml get
:end-before: # end gitlabciyml get
2 changes: 2 additions & 0 deletions gitlab/__init__.py
Expand Up @@ -91,6 +91,8 @@ def __init__(self, url, private_token=None, email=None, password=None,

self.broadcastmessages = BroadcastMessageManager(self)
self.keys = KeyManager(self)
self.gitlabciymls = GitlabciymlManager(self)
self.gitignores = GitignoreManager(self)
self.groups = GroupManager(self)
self.hooks = HookManager(self)
self.issues = IssueManager(self)
Expand Down
24 changes: 24 additions & 0 deletions gitlab/objects.py
Expand Up @@ -811,6 +811,30 @@ class NotificationSettingsManager(BaseManager):
obj_cls = NotificationSettings


class Gitignore(GitlabObject):
_url = '/templates/gitignores'
canDelete = False
canUpdate = False
canCreate = False
idAttr = 'name'


class GitignoreManager(BaseManager):
obj_cls = Gitignore


class Gitlabciyml(GitlabObject):
_url = '/templates/gitlab_ci_ymls'
canDelete = False
canUpdate = False
canCreate = False
idAttr = 'name'


class GitlabciymlManager(BaseManager):
obj_cls = Gitlabciyml


class GroupIssue(GitlabObject):
_url = '/groups/%(group_id)s/issues'
canGet = 'from_list'
Expand Down

0 comments on commit 570e75d

Please sign in to comment.