Skip to content

Commit

Permalink
fix: fix bnrach uniqueness for upload case
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-nguyen-cs committed Feb 1, 2024
1 parent 43e6a43 commit c84cdcf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions backend/editor/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ async def import_from_github(
raise HTTPException(status_code=422, detail="branch_name: Enter a valid branch name!")
if await taxonomy.does_project_exist():
raise HTTPException(status_code=409, detail="Project already exists!")
if not await taxonomy.is_branch_unique():
if not await taxonomy.is_branch_unique(from_github=True):
raise HTTPException(status_code=409, detail="branch_name: Branch name should be unique!")

status = await taxonomy.import_taxonomy(description, background_tasks)
Expand All @@ -387,7 +387,7 @@ async def upload_taxonomy(
raise HTTPException(status_code=422, detail="branch_name: Enter a valid branch name!")
if await taxonomy.does_project_exist():
raise HTTPException(status_code=409, detail="Project already exists!")
if not await taxonomy.is_branch_unique():
if not await taxonomy.is_branch_unique(from_github=False):
raise HTTPException(status_code=409, detail="branch_name: Branch name should be unique!")

result = await taxonomy.import_taxonomy(description, background_tasks, file)
Expand Down
12 changes: 6 additions & 6 deletions backend/editor/entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,20 +271,20 @@ async def does_project_exist(self):
else:
return True

async def is_branch_unique(self):
async def is_branch_unique(self, from_github: bool):
"""
Helper function to check uniqueness of GitHub branch
Helper function to check uniqueness of branch
"""
query = """MATCH (n:PROJECT) WHERE n.branch_name = $branch_name RETURN n"""
result = await get_current_transaction().run(query, {"branch_name": self.branch_name})

if not from_github:
return (await result.value()) == []

github_object = GithubOperations(self.taxonomy_name, self.branch_name)
github_branch = await github_object.get_branch(self.branch_name)

if (await result.value() == []) and (github_branch is None):
return True
else:
return False
return (await result.value() == []) and (github_branch is None)

def is_valid_branch_name(self):
"""
Expand Down

0 comments on commit c84cdcf

Please sign in to comment.