Skip to content

Commit

Permalink
Testing for placeholder report generation
Browse files Browse the repository at this point in the history
- Lowercase provided repo_url in dei/repo/add
- The dei/report endpoint now returns an error if the given
  project ID does not exist
- Add mdpdf as dependency for generating report PDFs
- Add kwargs to DatabaseSession
- Add dei badging report markdown template

Signed-off-by: Ulincsys <[email protected]>
  • Loading branch information
Ulincsys committed Jun 20, 2023
1 parent 7ce4c7c commit d2db13e
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 17 deletions.
46 changes: 36 additions & 10 deletions augur/api/routes/dei.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,27 @@
Creates routes for DEI badging functionality
"""

import logging
from flask import request, Response, jsonify
import logging, subprocess, inspect

from flask import request, Response, jsonify, render_template, send_file
from pathlib import Path

from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm.exc import NoResultFound
from augur.application.db.session import DatabaseSession
from augur.tasks.github.util.github_task_session import GithubTaskSession

from augur.api.util import api_key_required, ssl_required
from augur.util.repo_load_controller import RepoLoadController
from augur.api.util import api_key_required
from augur.api.util import ssl_required

from augur.application.db.models import User, ClientApplication, CollectionStatus, Repo, RepoGroup, BadgingDEI
from augur.application.config import get_development_flag
from augur.tasks.init.redis_connection import redis_connection as redis
from augur.tasks.github.util.util import get_repo_weight_by_issue
from augur.application.db.session import DatabaseSession
from augur.application.config import AugurConfig

from augur.tasks.util.collection_util import start_block_of_repos, get_enabled_phase_names_from_config, core_task_success_util
from augur.tasks.start_tasks import prelim_phase, primary_repo_collect_phase
from augur.tasks.github.util.github_task_session import GithubTaskSession
from augur.tasks.init.redis_connection import redis_connection as redis
from augur.tasks.github.util.util import get_repo_weight_by_issue

from ..server import app, engine

logger = logging.getLogger(__name__)
Expand All @@ -37,7 +42,10 @@ def dei_track_repo(application: ClientApplication):
if not (dei_id and level and repo_url):
return jsonify({"status": "Missing argument"}), 400

repo_url = repo_url.lower()

session = DatabaseSession(logger)
session.autocommit = True
repo: Repo = session.query(Repo).filter(Repo.repo_git==repo_url).first()
if repo:
# Making the assumption that only new repos will be added with this endpoint
Expand Down Expand Up @@ -102,6 +110,24 @@ def dei_report(application: ClientApplication):
if not dei_id:
return jsonify({"status": "Missing argument"}), 400

session = DatabaseSession(logger)

project: BadgingDEI = session.query(BadgingDEI).filter(BadgingDEI.badging_id==dei_id).first()

if not project:
return jsonify({"status": "Invalid ID"})

md = render_template("dei-badging-report.j2", project=project)
cachePath = Path.cwd() / "augur" / "static" / "cache"

source = cachePath / f"{project.id}_badging_report.md"
report = cachePath / f"{project.id}_badging_report.pdf"
source.write_text(md)

command = f"mdpdf -o {str(report.resolve())} {str(source.resolve())}"
converter = subprocess.Popen(command.split())
converter.wait()

# TODO what goes in the report?

return jsonify({"status": "Endpoint not implemented"})
return send_file(report.resolve())
7 changes: 4 additions & 3 deletions augur/api/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,11 @@ def wrapper(*args, **kwargs):
session = Session()
try:
kwargs["application"] = session.query(ClientApplication).filter(ClientApplication.api_key == client_token).one()
return fun(*args, **kwargs)
except NoResultFound:
pass
except NoResultFound as e:
return {"status": "Unauthorized client"}

return fun(*args, **kwargs)

return {"status": "Unauthorized client"}

return wrapper
Expand Down
2 changes: 1 addition & 1 deletion augur/application/cli/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def start(disable_collection, development, port):

worker_vmem_cap = config.get_value("Celery", 'worker_process_vmem_cap')

gunicorn_command = f"gunicorn -c {gunicorn_location} -b {host}:{port} augur.api.server:app"
gunicorn_command = f"gunicorn -c {gunicorn_location} -b {host}:{port} augur.api.server:app --log-file gunicorn.log"
server = subprocess.Popen(gunicorn_command.split(" "))

time.sleep(3)
Expand Down
4 changes: 2 additions & 2 deletions augur/application/db/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def remove_null_characters_from_list_of_dicts(data_list, fields):

class DatabaseSession(Session):

def __init__(self, logger, engine=None, from_msg=None):
def __init__(self, logger, engine=None, from_msg=None, **kwargs):

self.logger = logger
self.engine = engine
Expand All @@ -68,7 +68,7 @@ def __init__(self, logger, engine=None, from_msg=None):
else:
logger.debug(f"ENGINE CREATE")

super().__init__(self.engine)
super().__init__(self.engine, **kwargs)

def __enter__(self):
return self
Expand Down
8 changes: 8 additions & 0 deletions augur/templates/dei-badging-report.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# DEI Badging Report

## Project: {{ project.id }}

- Level: {{ project.level }}
- Repo:
- {{ project.repo.repo_id }}
- {{ project.repo.repo_git }}
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
"pylint==2.15.5",
"dnspython==2.2.1",
'Werkzeug~=2.0.0',
"pylint==2.15.5"
"pylint==2.15.5",
"mdpdf==0.0.18"
],
extras_require={
"dev": [
Expand Down

0 comments on commit d2db13e

Please sign in to comment.