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

main_forge

parent f5f83aca
......@@ -2,7 +2,7 @@ import logging
from django.core.management.base import BaseCommand
from rainboard.models import Repo
from rainboard.models import Project
logger = logging.getLogger('rainboard.management.fetch')
......@@ -11,6 +11,8 @@ class Command(BaseCommand):
def handle(self, *args, **options):
logger.info(f'Fetching all repos')
for repo in Repo.objects.all():
logger.info(f' fetching {repo}')
repo.git().fetch()
for project in Project.objects.all():
logger.info(f' fetching repos for {project}')
for repo in project.repo_set.all():
logger.info(f' fetching {repo.forge} - {repo.namespace}')
repo.git().fetch()
# Generated by Django 2.0.1 on 2018-01-29 17:12
from django.db import migrations, models
import django.db.models.deletion
def forges(apps, schema_editor):
Forge = apps.get_model('rainboard', 'Forge')
forges = [Forge.objects.get(name=forge) for forge in ['Github', 'Gitlab', 'Redmine', 'Openrobots']]
Project = apps.get_model('rainboard', 'Project')
for project in Project.objects.all():
for forge in forges:
if project.repo_set.filter(forge=forge).exists():
project.main_forge = forge
project.save()
break
class Migration(migrations.Migration):
dependencies = [
('rainboard', '0003_slugify_with_dots'),
]
operations = [
migrations.AddField(
model_name='project',
name='main_forge',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='rainboard.Forge'),
),
migrations.RunPython(forges),
]
......@@ -35,25 +35,6 @@ class License(models.Model):
return self.spdx_id or self.name
class Project(Links, NamedModel, TimeStampedModel):
private = models.BooleanField(default=False)
main_namespace = models.ForeignKey(Namespace, on_delete=models.SET_NULL, null=True, blank=True)
license = models.ForeignKey(License, on_delete=models.SET_NULL, blank=True, null=True)
homepage = models.URLField(max_length=200, blank=True, null=True)
articles = models.ManyToManyField(Article)
# TODO: release github ↔ robotpkg
def get_absolute_url(self):
return reverse('rainboard:project', kwargs={'slug': self.slug})
def git(self):
path = settings.RAINBOARD_GITS / self.main_namespace.slug / self.slug
if not path.exists():
logger.info(f'Creating repo for {self.main_namespace.slug}/{self.slug}')
return git.Repo.init(path)
return git.Repo(str(path / '.git'))
class Forge(Links, NamedModel):
source = models.PositiveSmallIntegerField(choices=enum_to_choices(SOURCES))
url = models.URLField(max_length=200)
......@@ -163,6 +144,26 @@ class Forge(Links, NamedModel):
pass # TODO
class Project(Links, NamedModel, TimeStampedModel):
private = models.BooleanField(default=False)
main_namespace = models.ForeignKey(Namespace, on_delete=models.SET_NULL, null=True, blank=True)
main_forge = models.ForeignKey(Forge, on_delete=models.SET_NULL, null=True, blank=True)
license = models.ForeignKey(License, on_delete=models.SET_NULL, blank=True, null=True)
homepage = models.URLField(max_length=200, blank=True, null=True)
articles = models.ManyToManyField(Article)
# TODO: release github ↔ robotpkg
def get_absolute_url(self):
return reverse('rainboard:project', kwargs={'slug': self.slug})
def git(self):
path = settings.RAINBOARD_GITS / self.main_namespace.slug / self.slug
if not path.exists():
logger.info(f'Creating repo for {self.main_namespace.slug}/{self.slug}')
return git.Repo.init(path)
return git.Repo(str(path / '.git'))
class Repo(TimeStampedModel):
name = models.CharField(max_length=200)
slug = AutoSlugField(populate_from='name', slugify=slugify_with_dots)
......
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