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

valid_name

parent b6cef74d
Pipeline #1904 failed with stages
in 23 seconds
...@@ -16,7 +16,7 @@ import requests ...@@ -16,7 +16,7 @@ import requests
import git import git
from autoslug import AutoSlugField from autoslug import AutoSlugField
from ndh.models import Links, NamedModel, TimeStampedModel from ndh.models import Links, NamedModel, TimeStampedModel
from ndh.utils import enum_to_choices, query_sum from ndh.utils import enum_to_choices, query_sum, valid_name
from .utils import SOURCES, api_next, invalid_mail, slugify_with_dots from .utils import SOURCES, api_next, invalid_mail, slugify_with_dots
...@@ -143,7 +143,7 @@ class Forge(Links, NamedModel): ...@@ -143,7 +143,7 @@ class Forge(Links, NamedModel):
update_github(self, org, data) update_github(self, org, data)
for user in Namespace.objects.filter(group=False): for user in Namespace.objects.filter(group=False):
for data in self.api_list(f'/users/{user.slug}/repos'): for data in self.api_list(f'/users/{user.slug}/repos'):
if Project.objects.filter(name=data['name']).exists(): if Project.objects.filter(name=valid_name(data['name'])).exists():
update_github(self, user, data) update_github(self, user, data)
def get_projects_gitlab(self): def get_projects_gitlab(self):
...@@ -253,7 +253,7 @@ class Project(Links, NamedModel, TimeStampedModel): ...@@ -253,7 +253,7 @@ class Project(Links, NamedModel, TimeStampedModel):
except DataError: except DataError:
setattr(self, value, old) setattr(self, value, old)
for dependency in re.findall(r'ADD_[A-Z]+_DEPENDENCY\s*\(["\']?([^ "\')]+).*["\']?\)', content, re.I): for dependency in re.findall(r'ADD_[A-Z]+_DEPENDENCY\s*\(["\']?([^ "\')]+).*["\']?\)', content, re.I):
project = Project.objects.filter(models.Q(slug=dependency) | models.Q(slug=dependency.replace('_', '-'))) project = Project.objects.filter(name=valid_name(dependency))
if project.exists(): if project.exists():
dependency, _ = Dependency.objects.get_or_create(project=self, library=project.first()) dependency, _ = Dependency.objects.get_or_create(project=self, library=project.first())
if not dependency.cmake: if not dependency.cmake:
...@@ -270,7 +270,7 @@ class Project(Links, NamedModel, TimeStampedModel): ...@@ -270,7 +270,7 @@ class Project(Links, NamedModel, TimeStampedModel):
with filename.open() as f: with filename.open() as f:
content = f.read() content = f.read()
for dependency in re.findall(r'<run_depend>(\w+).*</run_depend>', content, re.I): for dependency in re.findall(r'<run_depend>(\w+).*</run_depend>', content, re.I):
project = Project.objects.filter(models.Q(slug=dependency) | models.Q(slug=dependency.replace('_', '-'))) project = Project.objects.filter(name=valid_name(dependency))
if project.exists(): if project.exists():
dependency, _ = Dependency.objects.get_or_create(project=self, library=project.first()) dependency, _ = Dependency.objects.get_or_create(project=self, library=project.first())
if not dependency.ros: if not dependency.ros:
...@@ -867,7 +867,7 @@ def update_gitlab(forge, data): ...@@ -867,7 +867,7 @@ def update_gitlab(forge, data):
logger.info(f'update {data["name"]} from {forge}') logger.info(f'update {data["name"]} from {forge}')
public = data['visibility'] not in ['private', 'internal'] public = data['visibility'] not in ['private', 'internal']
project, created = Project.objects.get_or_create( project, created = Project.objects.get_or_create(
name=data['name'].replace('-', ' ').replace('_', ' '), defaults={ name=valid_name(data['name']), defaults={
'main_forge': forge, 'main_forge': forge,
'public': public 'public': public
}) })
...@@ -904,7 +904,7 @@ def update_gitlab(forge, data): ...@@ -904,7 +904,7 @@ def update_gitlab(forge, data):
def update_github(forge, namespace, data): def update_github(forge, namespace, data):
logger.info(f'update {data["name"]} from {forge}') logger.info(f'update {data["name"]} from {forge}')
project, _ = Project.objects.get_or_create( project, _ = Project.objects.get_or_create(
name=data['name'].replace('_', ' ').replace('-', ' '), defaults={ name=valid_name(data['name']), defaults={
'homepage': data['homepage'], 'homepage': data['homepage'],
'main_namespace': namespace, 'main_namespace': namespace,
'main_forge': forge 'main_forge': forge
...@@ -947,7 +947,7 @@ def update_github(forge, namespace, data): ...@@ -947,7 +947,7 @@ def update_github(forge, namespace, data):
def update_travis(namespace, data): def update_travis(namespace, data):
project = Project.objects.filter(name=data['name'].replace('_', ' ').replace('-', ' ')).first() project = Project.objects.filter(name=valid_name(data['name'])).first()
if project is None: if project is None:
return return
forge = Forge.objects.get(source=SOURCES.github) forge = Forge.objects.get(source=SOURCES.github)
......
...@@ -63,3 +63,7 @@ def update_robotpkg(path): ...@@ -63,3 +63,7 @@ def update_robotpkg(path):
def invalid_mail(mail): def invalid_mail(mail):
return any(invalid in mail for invalid in INVALID_MAILS) return any(invalid in mail for invalid in INVALID_MAILS)
def valid_name(name):
return name.replace('_', ' ').replace('-', ' ').lower()
Markdown is supported
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