Skip to content

Commit

Permalink
Add github::utils tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arkid15r committed Sep 3, 2024
1 parent bc9c43e commit 6ff79c1
Show file tree
Hide file tree
Showing 9 changed files with 349 additions and 52 deletions.
26 changes: 25 additions & 1 deletion .github/workflows/ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,36 @@ jobs:
with:
category: '/language:python'

run-tests:
name: Run tests
needs:
- pre-commit
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install dependencies
run: |
cd backend
python -m pip install --upgrade poetry
poetry install --no-root --with test
- name: Run tests
run: |
make test
build-docker-images:
environment: staging
name: Build Docker Images
runs-on: ubuntu-latest
needs:
- pre-commit
- run-tests
steps:
- name: Check out repository
uses: actions/checkout@v4
Expand Down
27 changes: 15 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
build:
@docker compose build
@CMD="poetry install" $(MAKE) run-backend-command
@CMD="poetry run python manage.py migrate" $(MAKE) run-backend-command
@CMD="poetry install" $(MAKE) run-backend-local-command
@CMD="poetry run python manage.py migrate" $(MAKE) run-backend-local-command

collect-static:
@CMD="poetry run python manage.py collectstatic --noinput" $(MAKE) run-backend-command
@CMD="poetry run python manage.py collectstatic --noinput" $(MAKE) run-backend-local-command

migrate:
@CMD="poetry run python manage.py migrate" $(MAKE) run-backend-command
@CMD="poetry run python manage.py migrate" $(MAKE) run-backend-local-command

migrations:
@CMD="poetry run python manage.py makemigrations" $(MAKE) run-backend-command
@CMD="poetry run python manage.py makemigrations" $(MAKE) run-backend-local-command

run:
@docker compose up

pre-commit:
@pre-commit run -a

run-backend-command:
@docker compose run --rm backend $(CMD)
run-backend-local-command:
@docker compose run --rm backend-local $(CMD)

shell:
@CMD="/bin/bash" $(MAKE) run-backend-command
@CMD="/bin/bash" $(MAKE) run-backend-local-command

test:
@cd backend && poetry run pytest; cd ..

github-sync-owasp-organization:
@CMD="poetry run python manage.py github_sync_owasp_organization" $(MAKE) run-backend-command
@CMD="poetry run python manage.py github_sync_owasp_organization" $(MAKE) run-backend-local-command

github-sync-related-repositories:
@CMD="poetry run python manage.py github_sync_related_repositories" $(MAKE) run-backend-command
@CMD="poetry run python manage.py github_sync_related_repositories" $(MAKE) run-backend-local-command

owasp-scrape-site-data:
@CMD="poetry run python manage.py owasp_scrape_site_data" $(MAKE) run-backend-command
@CMD="poetry run python manage.py owasp_scrape_site_data" $(MAKE) run-backend-local-command

owasp-update-projects:
@CMD="poetry run python manage.py owasp_update_projects" $(MAKE) run-backend-command
@CMD="poetry run python manage.py owasp_update_projects" $(MAKE) run-backend-local-command
13 changes: 5 additions & 8 deletions backend/apps/github/models/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

from apps.common.models import TimestampedModel
from apps.github.models.common import NodeModel
from apps.github.utils import check_owasp_site_repository
from apps.github.utils import (
check_funding_policy_compliance,
check_owasp_site_repository,
)


class Repository(NodeModel, TimestampedModel):
Expand Down Expand Up @@ -176,13 +179,7 @@ def from_github(
for target in targets if isinstance(targets, list) else [targets]:
if not target:
continue
match platform:
case "github":
is_funding_policy_compliant = target.lower() == "owasp"
case "custom":
is_funding_policy_compliant = "//owasp.org" in target.lower()
case "_":
is_funding_policy_compliant = False
is_funding_policy_compliant = check_funding_policy_compliance(platform, target)

if not is_funding_policy_compliant:
break
Expand Down
12 changes: 12 additions & 0 deletions backend/apps/github/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""GitHub app utils."""

from urllib.parse import urlparse

from apps.github.constants import GITHUB_REPOSITORY_RE


Expand All @@ -15,6 +17,16 @@ def check_owasp_site_repository(key):
)


def check_funding_policy_compliance(platform, target):
"""Check OWASP funding policy compliance."""
if platform == "github":
return target.lower() == "owasp"
if platform == "custom":
return urlparse(target).netloc.lower() == "owasp.org"

return False


def get_node_id(node):
"""Extract node_id."""
return node.raw_data["node_id"]
Expand Down
Loading

0 comments on commit 6ff79c1

Please sign in to comment.