blob: 8bbdb7720191598e697ed23cc6b79952a6385a51 [file] [log] [blame]
Ales Komarek49a37292016-08-31 16:18:31 +02001# -*- coding: utf-8 -*-
2'''
3Management of gerrit projects
4==============================
5
6:depends: - gerritlib Python module
7:configuration: See :py:mod:`salt.modules.gerrit` for setup instructions.
8
9.. code-block:: yaml
10
11 gerrit project:
12 gerrit.project_present:
13 - name: gerrit project
14
15'''
16
17
18def __virtual__():
19 '''
20 Only load if the gerrit module is in __salt__
21 '''
22 return 'gerrit' if 'gerrit.auth' in __salt__ else False
23
24
25def project_present(name, description=None, **kwargs):
26 '''
27 Ensures that the gerrit project exists
28
29 :param name: new project name
30 :param description: short project description
31 '''
32 ret = {'name': name,
33 'changes': {},
34 'result': True,
35 'comment': 'Project "{0}" already exists'.format(name)}
36
37 # Check if project is already present
38 project = __salt__['gerrit.project_get'](name=name, **kwargs)
39
40 if 'Error' not in project:
41 #update project
42 pass
43 else:
44 # Create project
45 __salt__['gerrit.project_create'](name, **kwargs)
46 ret['comment'] = 'Project "{0}" has been added'.format(name)
47 ret['changes']['Project'] = 'Created'
48 return ret