18 from typing
import Optional, Any, List, Dict
19 from typing_extensions
import Self
21 from .base
import BaseObject
22 from .task
import Task
23 from .project_type
import ProjectType
24 from .project_visibility
import ProjectVisibility
25 from ..entity_visibility_type
import EntityVisibilityType
26 from ..utils
import isEntityNameValid
27 from ...networking
import networkManager, NetworkRequestError
33 Represents the project entity from Coretex.ai\n
34 Contains properties that describe the project
38 visibility: ProjectVisibility
40 secretName: Optional[str]
46 projectType: ProjectType,
47 visiblity: ProjectVisibility = ProjectVisibility.private,
48 description: Optional[str] =
None
51 Creates a new project with the provided name and description
57 projectType : ProjectType
58 type of the created Project
59 visibility : ProjectVisibility
60 visibility of the created Project
61 description : Optional[str]
66 Self -> The created project object
70 NetworkRequestError -> If project creation failed
74 >>> from coretex import Project, ProjectType
77 >>> dummyProject = Project.createProject(
78 name = "dummyProject",
79 projectType = ProjectType.other,
80 description = "This is dummy Coretex Project"
83 print("Failed to create project.")
86 if not isEntityNameValid(name):
87 raise ValueError(
">> [Coretex] Project name is invalid. Requirements: alphanumeric characters (\"a-z\", and \"0-9\") and dash (\"-\") with length between 3 to 50")
91 project_task = projectType,
92 description = description,
97 def decode(cls, encodedObject: Dict[str, Any]) -> Self:
98 obj = super().decode(encodedObject)
99 obj.tasks = Task.fetchAll(queryParameters=[
105 def addTask(self, name: str, description: Optional[str]) -> bool:
107 Adds new task to the project
113 description : Optional[str]
118 bool -> True if the task was added. False if the task was not added
121 task = Task.createTask(name, self.id, description)
125 self.tasks.append(task)
131 Fetches Project based on specified name
136 The name of the Project to fetch
140 Self -> Fetched Project
144 RuntimeError -> If the Project with specified name is not found
147 results = cls.fetchAll(name = f
"={name}")
148 if len(results) == 0:
149 raise ValueError(f
"Project with name \"{name}\" not found.")
155 Updates visibility of the project
159 visibility : ProjectVisibility
160 visibility of the project
164 NetworkRequestError -> If request for updating the Project visibility failed
168 "entity_id": self.id,
169 "type": EntityVisibilityType.project,
170 "visibility": visibility
173 response = networkManager.post(
"entity-visibility", parameters)
175 if response.hasFailed():
176 raise NetworkRequestError(response,
"Failed to update visibility of the Project.")
bool addTask(self, str name, Optional[str] description)
None updateVisibility(self, ProjectVisibility visibility)
Self createProject(cls, str name, ProjectType projectType, ProjectVisibility visiblity=ProjectVisibility.private, Optional[str] description=None)
Self fetchByName(cls, str name)