Skip to content

Commit

Permalink
fixed forking
Browse files Browse the repository at this point in the history
  • Loading branch information
khoroshevskyi committed Jan 12, 2024
1 parent 46d0e08 commit 6d9fd85
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pepdbagent/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.7.0a4"
__version__ = "0.7.0a5"
2 changes: 2 additions & 0 deletions pepdbagent/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class UpdateItems(BaseModel):
config: Optional[dict] = None
samples: Optional[List[dict]] = None
subsamples: Optional[List[List[dict]]] = None
pop: Optional[bool] = False

model_config = ConfigDict(
arbitrary_types_allowed=True,
Expand Down Expand Up @@ -111,6 +112,7 @@ class UpdateModel(BaseModel):
pep_schema: Optional[str] = None
description: Optional[str] = ""
# last_update_date: Optional[datetime.datetime] = datetime.datetime.now(datetime.timezone.utc)
pop: Optional[bool] = False

@field_validator("tag", "name")
def value_must_not_be_empty(cls, v):
Expand Down
48 changes: 32 additions & 16 deletions pepdbagent/modules/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,16 +659,21 @@ def fork(
fork_namespace: str,
fork_name: str = None,
fork_tag: str = None,
description: str = None,
private: bool = False,
):
"""
:param original_namespace:
:param original_name:
:param original_tag:
:param fork_namespace:
:param fork_name:
:param fork_tag:
:return:
Fork project from one namespace to another
:param original_namespace: namespace of the project to be forked
:param original_name: name of the project to be forked
:param original_tag: tag of the project to be forked
:param fork_namespace: namespace of the forked project
:param fork_name: name of the forked project
:param fork_tag: tag of the forked project
:param description: description of the forked project
:param private: boolean value if the project should be visible just for user that creates it.
:return: None
"""
self.create(
project=self.get(
Expand All @@ -679,15 +684,26 @@ def fork(
namespace=fork_namespace,
name=fork_name,
tag=fork_tag,
description=description or None,
is_private=private,
)
original_id = self.get_project_id(original_namespace, original_name, original_tag)
original_statement = select(Projects).where(
Projects.namespace == original_namespace,
Projects.name == original_name,
Projects.tag == original_tag,
)
fork_statement = select(Projects).where(
Projects.namespace == fork_namespace,
Projects.name == fork_name,
Projects.tag == fork_tag,
)

with Session(self._sa_engine) as session:
statement = select(Projects).where(
Projects.namespace == fork_namespace,
Projects.name == fork_name,
Projects.tag == fork_tag,
)
prj = session.scalar(statement)
prj.forked_from_id = original_id
original_prj = session.scalar(original_statement)
fork_prj = session.scalar(fork_statement)
fork_prj.forked_from_id = original_prj.id
fork_prj.pop = original_prj.pop
fork_prj.submission_date = original_prj.submission_date

session.commit()
return None

0 comments on commit 6d9fd85

Please sign in to comment.