-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhoster.py
46 lines (38 loc) · 1.71 KB
/
hoster.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018 Sandro Lutz <[email protected]>
#
# This software is licensed under GPLv3, see LICENSE for details.
from hoster_base import BaseHoster
from hoster_gitlab import GitLabHoster
from hoster_github import GitHubHoster
from hoster_bitbucket import BitbucketHoster
def getHosterInstance(config):
'''
Get an instance of git hoster
:param dict config: hoster configuration
:return: BaseHoster object
:rtype: BaseHoster
:raises ValueError: if the given configuration is invalid
'''
if any (key not in config for key in ['type', 'name', 'user', 'password', 'api-version']):
raise ValueError('Missing some required properties (type, name, user, password, api-version)')
if 'organization' in config:
organization = config['organization']
else:
organization = None
if 'ignored-repositories' in config:
ignored_repositories = config['ignored-repositories']
else:
ignored_repositories = list()
if config['type'] == 'github':
return GitHubHoster(config['name'], config['user'], config['password'], config['api-version'], organization, ignored_repositories)
elif config['type'] == 'gitlab':
if 'domain' not in config:
raise ValueError('Property \'domain\' required for hoster \'gitlab\'')
return GitLabHoster(config['name'], config['user'], config['password'], config['api-version'], \
config['domain'], organization, ignored_repositories)
elif config['type'] == 'bitbucket':
return BitbucketHoster(config['name'], config['user'], config['password'], config['api-version'], organization, ignored_repositories)
else:
raise ValueError('Unknown hoster \'' + config['type'] + '\'')