forked from logicalclocks/hopsworks-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_remote.py
84 lines (72 loc) · 2.23 KB
/
git_remote.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
#
# Copyright 2022 Logical Clocks AB
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import humps
import json
from hopsworks.core import git_remote_api
from hopsworks import util
class GitRemote:
def __init__(
self,
remote_name=None,
remote_url=None,
url=None,
name=None,
type=None,
href=None,
expand=None,
items=None,
count=None,
project_id=None,
project_name=None,
**kwargs,
):
self._name = remote_name
self._url = remote_url
self._git_remote_api = git_remote_api.GitRemoteApi(project_id, project_name)
@classmethod
def from_response_json(cls, json_dict, project_id, project_name):
json_decamelized = humps.decamelize(json_dict)
if "count" in json_decamelized:
if json_decamelized["count"] == 0:
return []
return [
cls(**remote, project_id=project_id)
for remote in json_decamelized["items"]
]
else:
return cls(
**json_decamelized, project_id=project_id, project_name=project_name
)
@property
def name(self):
"""Name of the remote"""
return self._name
@property
def url(self):
"""Url of the remote"""
return self._url
def delete(self):
"""Remove the git remote from the repo.
# Raises
`RestAPIError`.
"""
self._git_remote_api._delete(self._repo_id, self.name)
def json(self):
return json.dumps(self, cls=util.Encoder)
def __str__(self):
return self.json()
def __repr__(self):
return f"GitRemote({self._name!r}, {self._url!r})"