1717from .tasks import Task
1818from .variants import Variants
1919
20+
2021class ContentItemRepository (Resource ):
2122 def __init__ (self , params : ResourceParameters , content_guid : str , ** kwargs ) -> None :
2223 super ().__init__ (params , ** kwargs )
@@ -83,6 +84,7 @@ class ContentItemOwner(Resource):
8384
8485
8586class ContentItem (Resource ):
87+
8688 def __getitem__ (self , key : Any ) -> Any :
8789 v = super ().__getitem__ (key )
8890 if key == "owner" and isinstance (v , dict ):
@@ -93,6 +95,66 @@ def __getitem__(self, key: Any) -> Any:
9395 def oauth (self ) -> ContentItemOAuth :
9496 return ContentItemOAuth (self .params , content_guid = self ["guid" ])
9597
98+ @property
99+ def repository (self ) -> Optional [ContentItemRepository ]:
100+ path = f"v1/content/{ self .guid } /repository"
101+ url = self .params .url + path
102+ try :
103+ response = self .params .session .get (url )
104+ return ContentItemRepository (self .params , self ["guid" ], ** response .json ())
105+ except :
106+ return None
107+
108+ @overload
109+ def create_repository (
110+ self ,
111+ * ,
112+ repository : str ,
113+ branch : Optional [str ] = "main" ,
114+ directory : Optional [str ] = "." ,
115+ polling : Optional [bool ] = False ,
116+ ) -> ContentItemRepository :
117+ """Create repository.
118+
119+ Parameters
120+ ----------
121+ repository : str
122+ URL for the respository.
123+ branch : str, optional
124+ The tracked Git branch. Default is 'main'.
125+ directory : str, optional
126+ Directory containing the content. Default is '.'.
127+ polling : bool, optional
128+ Indicates that the Git repository is regularly polled. Default is False.
129+
130+ Returns
131+ -------
132+ ContentItemRepository
133+ """
134+ ...
135+
136+ @overload
137+ def create_repository (self , ** attributes ) -> ContentItemRepository :
138+ """Create a repository.
139+
140+ Returns
141+ -------
142+ ContentItemRepository
143+ """
144+ ...
145+
146+ def create_repository (self , ** attributes ):
147+ """Create a repository.
148+
149+ Returns
150+ -------
151+ ContentItemRepository
152+ """
153+ path = f"v1/content/{ self .guid } /repository"
154+ url = self .params .url + path
155+ response = self .params .session .put (url , json = attributes )
156+ return ContentItemRepository (self .params , ** response .json ())
157+
96158 def delete (self ) -> None :
97159 """Delete the content item."""
98160 path = f"v1/content/{ self .guid } "
@@ -152,15 +214,6 @@ def render(self) -> Task:
152214 )
153215
154216
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-
164217 def restart (self ) -> None :
165218 """Mark for restart.
166219
0 commit comments