SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 339d9d2d authored by George Katsikas's avatar George Katsikas :goat:
Browse files

Merge branch 'dev_GK_20230718_gitlab_race_condition_fix' into 'master'

Fix gitlab race conditions with repo creation

See merge request !56
parents 94edbb42 9cf4a0e5
No related branches found
No related tags found
1 merge request!56Fix gitlab race conditions with repo creation
...@@ -5,6 +5,8 @@ from datetime import datetime ...@@ -5,6 +5,8 @@ from datetime import datetime
from functools import reduce from functools import reduce
from itertools import cycle from itertools import cycle
from typing import Any, Callable, Dict, List, Tuple from typing import Any, Callable, Dict, List, Tuple
from time import sleep
from django.core.management.base import BaseCommand, CommandParser from django.core.management.base import BaseCommand, CommandParser
from django.conf import settings from django.conf import settings
...@@ -189,6 +191,10 @@ class Command(BaseCommand): ...@@ -189,6 +191,10 @@ class Command(BaseCommand):
base_actions = self._get_project_cloning_actions(base_template_project) base_actions = self._get_project_cloning_actions(base_template_project)
journal_actions = self._get_project_cloning_actions(journal_template_project) journal_actions = self._get_project_cloning_actions(journal_template_project)
# Add some delays to avoid:
# - Commiting the files before the branch has finished being created
# - Changing the protected branch before the files have been commited
sleep(3)
# Commit the actions # Commit the actions
project.commits.create( project.commits.create(
{ {
...@@ -197,6 +203,7 @@ class Command(BaseCommand): ...@@ -197,6 +203,7 @@ class Command(BaseCommand):
"actions": base_actions + journal_actions, "actions": base_actions + journal_actions,
} }
) )
sleep(3)
# Allow Developers to push to the protected "main" branch # Allow Developers to push to the protected "main" branch
# Protected branches lay on top of the branches. Deleting and recreating them is # Protected branches lay on top of the branches. Deleting and recreating them is
......
...@@ -130,7 +130,10 @@ class TestProofRepository(TestCase): ...@@ -130,7 +130,10 @@ class TestProofRepository(TestCase):
stream__submission__preprint__identifier_w_vn_nr="scipost_202101_00001v1" stream__submission__preprint__identifier_w_vn_nr="scipost_202101_00001v1"
) )
self.assertEqual(proofs_repo.name, "scipost_202101_00001v1_User") self.assertEqual(
ProofsRepository._get_repo_name(proofs_repo.stream),
"scipost_202101_00001v1_User",
)
def test_repo_name_nonexisting_profile(self): def test_repo_name_nonexisting_profile(self):
proofs_repo = ProofsRepository.objects.get( proofs_repo = ProofsRepository.objects.get(
...@@ -140,7 +143,10 @@ class TestProofRepository(TestCase): ...@@ -140,7 +143,10 @@ class TestProofRepository(TestCase):
# delete profile # delete profile
Contributor.objects.get(user__username="testuser").profile.delete() Contributor.objects.get(user__username="testuser").profile.delete()
self.assertEqual(proofs_repo.name, "scipost_202101_00001v1_User") self.assertEqual(
ProofsRepository._get_repo_name(proofs_repo.stream),
"scipost_202101_00001v1_User",
)
def test_repo_name_double_last_name_profile(self): def test_repo_name_double_last_name_profile(self):
proofs_repo = ProofsRepository.objects.get( proofs_repo = ProofsRepository.objects.get(
...@@ -153,7 +159,10 @@ class TestProofRepository(TestCase): ...@@ -153,7 +159,10 @@ class TestProofRepository(TestCase):
user_profile.last_name = "Usable User" user_profile.last_name = "Usable User"
user_profile.save() user_profile.save()
self.assertEqual(proofs_repo.name, "scipost_202101_00001v1_Usable-User") self.assertEqual(
ProofsRepository._get_repo_name(proofs_repo.stream),
"scipost_202101_00001v1_Usable-User",
)
def test_repo_name_two_authors(self): def test_repo_name_two_authors(self):
proofs_repo = ProofsRepository.objects.get( proofs_repo = ProofsRepository.objects.get(
...@@ -164,7 +173,10 @@ class TestProofRepository(TestCase): ...@@ -164,7 +173,10 @@ class TestProofRepository(TestCase):
"Another Personable Person, Test Usable User" "Another Personable Person, Test Usable User"
) )
self.assertEqual(proofs_repo.name, "scipost_202101_00001v1_Person") self.assertEqual(
ProofsRepository._get_repo_name(proofs_repo.stream),
"scipost_202101_00001v1_Person",
)
def test_repo_name_accented_authors(self): def test_repo_name_accented_authors(self):
proofs_repo = ProofsRepository.objects.get( proofs_repo = ProofsRepository.objects.get(
...@@ -178,7 +190,10 @@ class TestProofRepository(TestCase): ...@@ -178,7 +190,10 @@ class TestProofRepository(TestCase):
proofs_repo.stream.submission.author_list = "Some Pérsønüsær (陈)" proofs_repo.stream.submission.author_list = "Some Pérsønüsær (陈)"
self.assertEqual(proofs_repo.name, "scipost_202101_00001v1_Personusaer") self.assertEqual(
ProofsRepository._get_repo_name(proofs_repo.stream),
"scipost_202101_00001v1_Personusaer",
)
def test_repo_paths_scipostphys(self): def test_repo_paths_scipostphys(self):
proofs_repo = ProofsRepository.objects.get( proofs_repo = ProofsRepository.objects.get(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment