Skip to content

Commit 2de5dd6

Browse files
committed
wip implementation of git repo resource
1 parent 0614ae4 commit 2de5dd6

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

src/posit/connect/content.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,56 @@
1717
from .tasks import Task
1818
from .variants import Variants
1919

20+
class ContentItemRepository(Resource):
21+
def __init__(self, params: ResourceParameters, content_guid: str, **kwargs) -> None:
22+
super().__init__(params, **kwargs)
23+
self.content_guid = content_guid
24+
25+
def delete(self) -> None:
26+
"""Delete the content's repository."""
27+
path = f"v1/content/{self.content_guid}/repository"
28+
url = self.params.url + path
29+
self.params.session.delete(url)
30+
31+
@overload
32+
def update(
33+
self,
34+
*,
35+
repository: Optional[str] = None,
36+
branch: Optional[str] = "main",
37+
directory: Optional[str] = ".",
38+
polling: Optional[bool] = False,
39+
) -> None:
40+
"""Update the content's repository.
41+
42+
Parameters
43+
----------
44+
repository: str, optional
45+
URL for the repository. Default is None.
46+
branch: str, optional
47+
The tracked Git branch. Default is 'main'.
48+
directory: str, optional
49+
Directory containing the content. Default is '.'
50+
polling: bool, optional
51+
Indicates that the Git repository is regularly polled. Default is False.
52+
53+
54+
Returns
55+
-------
56+
None
57+
"""
58+
...
59+
60+
@overload
61+
def update(self, **attributes: Any) -> None:
62+
"""Update the content's repository."""
63+
...
64+
65+
def update(self, **attributes: Any) -> None:
66+
"""Update the content's repository."""
67+
url = self.params.url + f"v1/content/{self.content_guid}/repository"
68+
response = self.params.session.patch(url, json=attributes)
69+
super().update(**response.json())
2070

2171
class ContentItemOAuth(Resource):
2272
def __init__(self, params: ResourceParameters, content_guid: str) -> None:
@@ -101,6 +151,16 @@ def render(self) -> Task:
101151
f"Render not supported for this application mode: {self.app_mode}. Did you need to use the 'restart()' method instead? Note that some application modes do not support 'render()' or 'restart()'."
102152
)
103153

154+
155+
def repository(self) -> ContentItemRepository:
156+
"""Return the content item's git repository, if one exists"""
157+
158+
path = f"v1/content/{self.guid}/repository"
159+
url = self.params.url + path
160+
response = self.params.session.get(url)
161+
return ContentItemRepository(self.params, self['guid'], **response.json())
162+
163+
104164
def restart(self) -> None:
105165
"""Mark for restart.
106166

0 commit comments

Comments
 (0)