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
9 changes: 7 additions & 2 deletions apps/worker/services/report/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from shared.reports.resources import Report
from shared.reports.types import TOTALS_MAP
from shared.storage.exceptions import FileNotInStorageError
from shared.torngit.base import TorngitBaseAdapter
from shared.torngit.exceptions import TorngitError
from shared.upload.constants import UploadErrorCode
from shared.utils.sessions import Session, SessionType
Expand Down Expand Up @@ -192,11 +193,15 @@ def create_report_upload(

class ReportService(BaseReportService):
def __init__(
self, current_yaml: UserYaml | dict, gh_app_installation_name: str | None = None
self,
current_yaml: UserYaml | dict,
gh_app_installation_name: str | None = None,
repository_service: TorngitBaseAdapter | None = None,
):
super().__init__(current_yaml)
self.flag_dict: dict[str, RepositoryFlag] | None = None
self.gh_app_installation_name = gh_app_installation_name
self.repository_service = repository_service

def has_initialized_report(self, commit: Commit) -> bool:
"""
Expand Down Expand Up @@ -413,7 +418,7 @@ def _possibly_shift_carryforward_report(
self, carryforward_report: Report, base_commit: Commit, head_commit: Commit
) -> Report:
try:
provider_service = get_repo_provider_service(
provider_service = self.repository_service or get_repo_provider_service(
repository=head_commit.repository,
installation_name_to_use=self.gh_app_installation_name,
)
Expand Down
12 changes: 11 additions & 1 deletion apps/worker/tasks/preprocess_upload.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import logging

from sqlalchemy.orm import joinedload

from app import celery_app
from database.enums import CommitErrorTypes
from database.models import Commit
from database.models.core import Owner, Repository
from helpers.exceptions import RepositoryWithoutValidBotError
from helpers.github_installation import get_installation_name_for_owner_for_task
from helpers.save_commit_error import save_commit_error
Expand Down Expand Up @@ -99,6 +102,11 @@ def process_impl_within_lock(self, db_session, repoid, commitid):
commit = (
db_session.query(Commit)
.filter(Commit.repoid == repoid, Commit.commitid == commitid)
.options(
joinedload(Commit.repository)
.joinedload(Repository.author)
.joinedload(Owner.github_app_installations)
)
.first()
)
assert commit, "Commit not found in database."
Expand All @@ -123,7 +131,9 @@ def process_impl_within_lock(self, db_session, repoid, commitid):
)
commit_yaml = fetch_commit_yaml_and_possibly_store(commit, repository_service)
report_service = ReportService(
commit_yaml, gh_app_installation_name=installation_name_to_use
commit_yaml,
gh_app_installation_name=installation_name_to_use,
repository_service=repository_service,
)
commit_report = report_service.initialize_and_save_report(commit)
# Persist changes from within the lock
Expand Down
Loading