This repository has been archived by the owner on Feb 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(entity): import services and libraries into entity model
- Loading branch information
1 parent
2c8bb9b
commit eff8221
Showing
7 changed files
with
137 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import structlog | ||
from django.core.management.base import BaseCommand | ||
|
||
from zoo.entities.enums import Kind | ||
from zoo.entities.models import Entity, Link | ||
from zoo.libraries.models import Library | ||
from zoo.services.models import Service | ||
|
||
log = structlog.get_logger() | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Create entities from services and libraries" | ||
|
||
def handle(self, *args, **options): | ||
self.service_to_entity() | ||
self.library_to_entity() | ||
|
||
@staticmethod | ||
def service_to_entity(): | ||
with open("service_exceptions.csv", "w+") as exceptions: | ||
exceptions.write( | ||
"Service name;Service owner;Service repository;Exception\n" | ||
) | ||
for service in Service.objects.all(): | ||
if service.repository: | ||
log.info("entity.import_services.processing", service=service) | ||
try: | ||
entity = Entity.objects.create( | ||
name=service.name, | ||
owner=service.owner, | ||
description=service.description, | ||
kind=Kind.COMPONENT, | ||
type="service", | ||
source=service.repository, | ||
tags=service.tags, | ||
service=service, | ||
) | ||
|
||
if service.docs_url: | ||
Link.objects.create( | ||
name="Documentation", | ||
url=service.docs_url, | ||
entity=entity, | ||
) | ||
|
||
if service.slack_channel: | ||
Link.objects.create( | ||
name="Discussion", | ||
url=f"https://app.slack.com/client/T024Z3H2Y/{service.slack_channel}", | ||
entity=entity, | ||
) | ||
except Exception as err: | ||
exceptions.write( | ||
f"{getattr(service, 'name', '')};{getattr(service, 'owner', '')};{getattr(service, 'repository', '')};{repr((err))}\n" | ||
) | ||
else: | ||
exceptions.write( | ||
f"{getattr(service, 'name', '')};{getattr(service, 'owner', '')};;Missing repository for service\n" | ||
) | ||
|
||
@staticmethod | ||
def library_to_entity(): | ||
with open("library_exceptions.csv", "w+") as exceptions: | ||
exceptions.write( | ||
"Library name;Library owner;Library repository;Exception\n" | ||
) | ||
for library in Library.objects.all(): | ||
if library.repository: | ||
log.info("entity.import_libraries.processing", library=library) | ||
try: | ||
entity = Entity.objects.create( | ||
name=library.name, | ||
owner=library.owner, | ||
description=library.description, | ||
kind=Kind.COMPONENT, | ||
type="library", | ||
source=library.repository, | ||
tags=library.tags, | ||
library=library, | ||
) | ||
|
||
if library.docs_url: | ||
Link.objects.create( | ||
name="Documentation", | ||
url=library.docs_url, | ||
entity=entity, | ||
) | ||
|
||
if library.slack_channel: | ||
Link.objects.create( | ||
name="Discussion", | ||
url=f"https://app.slack.com/client/T024Z3H2Y/{library.slack_channel}", | ||
entity=entity, | ||
) | ||
|
||
if library.library_url: | ||
Link.objects.create( | ||
name="Library URL", | ||
url=library.library_url, | ||
entity=entity, | ||
) | ||
except Exception as err: | ||
exceptions.write( | ||
f"{getattr(library, 'name', '')};{getattr(library, 'owner', '')};{getattr(library, 'repository', '')};{repr((err))}\n" | ||
) | ||
else: | ||
exceptions.write( | ||
f"{getattr(library, 'name', '')};{getattr(library, 'owner', '')};;Missing repository for library\n" | ||
) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Generated by Django 2.2.19 on 2021-10-13 09:52 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("entities", "0002_allow_null_product_owner_on_group"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="entity", | ||
name="group", | ||
field=models.OneToOneField( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="entities.Group", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters