Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions gateway/actions.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
import base64
import logging
import secrets

from django.conf import settings
from django.core.exceptions import ValidationError
from django.core.validators import validate_slug

from . import github, rap_api
from .models import Job, Project, Run, User


logger = logging.getLogger(__name__)


def create_or_update_projects():
for record in github.get_repo_metadata(settings.GITHUB_ORG):
try:
validate_slug(record["name"])
except ValidationError:
logger.warning(
"Ignoring GitHub repo with invalid slug name: %s", record["name"]
)
continue
Project.objects.update_or_create(
id=record["id"],
defaults={
Expand Down
21 changes: 21 additions & 0 deletions tests/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,27 @@ def test_create_or_update_projects():
assert p3.description == "Description"


def test_create_or_update_projects_ignores_invalid_slug_repos(caplog):
github_data = [
{"id": 123, "name": ".github", "description": "Ignored"},
{"id": 124, "name": "my.repo", "description": "Ignored"},
{"id": 456, "name": "test-2", "description": "Description"},
]

with mocked_responses(get_data=github_data):
create_or_update_projects()

assert Project.objects.count() == 1
assert not Project.objects.filter(name=".github").exists()
assert not Project.objects.filter(name="my.repo").exists()
assert "Ignoring GitHub repo with invalid slug name: .github" in caplog.text
assert "Ignoring GitHub repo with invalid slug name: my.repo" in caplog.text

project = Project.objects.get(pk=456)
assert project.name == "test-2"
assert project.description == "Description"


def test_create_or_update_users():
User = get_user_model()
github_data_1 = [
Expand Down