Commit f141cd9e authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

prefer slug in get_or_create

parent 1c589ede
...@@ -177,7 +177,7 @@ class Project(Links, NamedModel, TimeStampedModel): ...@@ -177,7 +177,7 @@ class Project(Links, NamedModel, TimeStampedModel):
for branch in branches: for branch in branches:
logger.info(f'update branch {branch}') logger.info(f'update branch {branch}')
if branch in MAIN_BRANCHES: if branch in MAIN_BRANCHES:
instance, created = Branch.objects.get_or_create(name=branch, project=self) instance, bcreated = Branch.objects.get_or_create(name=branch, project=self)
else: else:
if branch.startswith('remotes/'): if branch.startswith('remotes/'):
branch = branch[8:] branch = branch[8:]
...@@ -189,8 +189,8 @@ class Project(Links, NamedModel, TimeStampedModel): ...@@ -189,8 +189,8 @@ class Project(Links, NamedModel, TimeStampedModel):
'repo_id': 0}) 'repo_id': 0})
if created: if created:
repo.api_update() repo.api_update()
instance, created = Branch.objects.get_or_create(name=branch, project=self, repo=repo) instance, bcreated = Branch.objects.get_or_create(name=branch, project=self, repo=repo)
if created: if bcreated:
instance.update(pull=pull) instance.update(pull=pull)
def main_branch(self): def main_branch(self):
...@@ -599,7 +599,8 @@ def get_default_forge(project): ...@@ -599,7 +599,8 @@ def get_default_forge(project):
def update_gitlab(forge, data): def update_gitlab(forge, data):
logger.info(f'update {data["name"]} from {forge}') logger.info(f'update {data["name"]} from {forge}')
project, created = Project.objects.get_or_create(name=data['name'], defaults={'main_forge': forge}) project, created = Project.objects.get_or_create(name=data['name'], defaults={'main_forge': forge})
namespace, _ = Namespace.objects.get_or_create(name=data['namespace']['name']) namespace, _ = Namespace.objects.get_or_create(slug=data['namespace']['path'],
defaults={'name': data['namespace']['name']})
repo, _ = Repo.objects.get_or_create(forge=forge, namespace=namespace, project=project, repo, _ = Repo.objects.get_or_create(forge=forge, namespace=namespace, project=project,
defaults={'repo_id': data['id'], 'name': data['name'], defaults={'repo_id': data['id'], 'name': data['name'],
'url': data['web_url']}) 'url': data['web_url']})
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment