Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Patch 1 fixing create project #17

Merged
merged 2 commits into from
Feb 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions pytransifex/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,36 @@ def create_project(
project_name = project_slug

try:
res = tx_api.Project.create(
name=project_name,
slug=project_slug,
source_language=source_language,
private=private,
organization=self.organization,
)
if private:
return tx_api.Project.create(
name=project_name,
slug=project_slug,
source_language=source_language,
private=private,
organization=self.organization,
)
else:
if repository_url := kwargs.get("repository_url", None):
return tx_api.Project.create(
name=project_name,
slug=project_slug,
source_language=source_language,
private=private,
repository_url=repository_url,
organization=self.organization,
)
else:
raise ValueError(
f"Private projects need to pass a 'repository_url' (non-empty string) argument."
)

logging.info("Project created!")
return res

except JsonApiException as error:
if "already exists" in error.detail: # type: ignore
if hasattr(error, "detail") and "already exists" in error.detail: # type: ignore
return self.get_project(project_slug=project_slug)
else:
logging.error(f"Unable to create project; API replied with {error}")

@ensure_login
def get_project(self, project_slug: str) -> None | Resource:
Expand Down