-
Notifications
You must be signed in to change notification settings - Fork 1
/
hoster_base.py
133 lines (102 loc) · 4.28 KB
/
hoster_base.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018 Sandro Lutz <code@temparus.ch>
#
# This software is licensed under GPLv3, see LICENSE for details.
from abc import ABC, abstractmethod
class BaseHoster(ABC):
@abstractmethod
def __init__(self, name, user, password, organization=None, ignored_repositories=list()):
'''
Initialize a git hoster instance
:param str name: Hoster name
:param str user: Username for the git service
:param str password: Password for the git service (in plain text)
:param str organization: Organization name used for syncing
:param str ignored_repositories: List of repository names to be ignored
'''
self.name = name
self.user = user
self.password = password
self.organization = organization
self.ignored_repositories = ignored_repositories
@abstractmethod
def getRepositoryList(self, visibility):
'''
Get all repositories of the given type
:param str visibility: requested repository type (public, internal, private, all)
:return: returns a list of RemoteRepository objects
:rtype: list
:raises PermissionError: if the access is denied by the server
:raises ConnectionError: if another HTTP error has occurred
:raises NotImplementedError: if this operation is not implemented/supported with the given API version
:raises ValueError: if the given visibility is unknown
'''
pass
@abstractmethod
def getRepository(self, name):
'''
Get repository with the given name
:param str name: repository name
:return: returns a RemoteRepository object
:rtype: RemoteRepository
:raises PermissionError: if the access is denied by the server
:raises ConnectionError: if another HTTP error has occurred
:raises NotImplementedError: if this operation is not implemented/supported with the given API version
:raises ValueError: if the repository does not exist
'''
pass
@abstractmethod
def createRepository(self, name, visibility, description=None, website=None):
'''
Create a new repository
:param str name: repository name
:param str visibility: repository visibility
:param str description: repository description
:param str website: repository website
:return: returns a RemoteRepository object
:rtype: RemoteRepository
:raises PermissionError: if the access is denied by the server
:raises ConnectionError: if another HTTP error has occurred
:raises NotImplementedError: if this operation is not implemented/supported with the given API version
:raises ValueError: if the given parameters are invalid
'''
pass
@abstractmethod
def updateRepository(self, repo):
'''
Update an existing repository
:param RemoteRepository repo: remote repository containing updated values
:raises PermissionError: if the access is denied by the server
:raises ConnectionError: if another HTTP error has occurred
:raises NotImplementedError: if this operation is not implemented/supported with the given API version
:raises ValueError: if the given parameters are invalid
'''
pass
@abstractmethod
def deleteRepository(self, repo):
'''
Delete a repository
:param RemoteRepository repo: remote repository to be deleted
:raises PermissionError: if the access is denied by the server
:raises ConnectionError: if another HTTP error has occurred
:raises NotImplementedError: if this operation is not implemented/supported with the given API version
:raises ValueError: if the given repository does not exist
'''
pass
def _raisePermissionError(self, response):
json_response = response.json()
message = 'HTTP ERROR ' + str(response.status_code)
if 'error' in json_response:
message += ': ' + json_response['error']
else:
message += ': ' + response.text
raise PermissionError(message)
def _raiseConnectionError(self, response):
json_response = response.json()
message = 'HTTP ERROR ' + str(response.status_code)
if 'error' in json_response:
message += ': ' + json_response['error']
else:
message += ': ' + response.text
raise ConnectionError(message)