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

Commit

Permalink
Patch 1 fixing create project (#17)
Browse files Browse the repository at this point in the history
* More care at handling private projects and JsonApi exceptions not defining 'detail'.

* ---
  • Loading branch information
why-not-try-calmer authored Feb 17, 2023
1 parent 8de3c34 commit 2ac0d13
Showing 1 changed file with 27 additions and 9 deletions.
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

0 comments on commit 2ac0d13

Please sign in to comment.