Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced direct use of Repo code with Service code #505

Merged
merged 5 commits into from
Aug 9, 2024
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
15 changes: 6 additions & 9 deletions backend/analytics_server/mhq/api/deployment_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
DeploymentFrequencyMetrics,
DeploymentType,
)
from mhq.store.repos.code import CodeRepoService


app = Blueprint("deployment_analytics", __name__)

Expand Down Expand Up @@ -62,14 +60,10 @@ def get_team_deployment_analytics(
pr_filter: PRFilter = apply_pr_filter(
pr_filter, EntityType.TEAM, team_id, [SettingType.EXCLUDED_PRS_SETTING]
)
code_repo_service = CodeRepoService()

team_repos: List[TeamRepos] = code_repo_service.get_active_team_repos_by_team_id(
team_id
)
org_repos: List[OrgRepo] = code_repo_service.get_active_org_repos_by_ids(
[str(team_repo.org_repo_id) for team_repo in team_repos]
)
pr_analytics_service = get_pr_analytics_service()

org_repos: List[OrgRepo] = pr_analytics_service.get_team_repos(team_id)

deployments_analytics_service = get_deployment_analytics_service()

Expand Down Expand Up @@ -127,6 +121,9 @@ def get_prs_included_in_deployment(deployment_id: str):

repo: OrgRepo = pr_analytics_service.get_repo_by_id(deployment.repo_id)

if not repo:
raise NotFound(f"Repo with {deployment.repo_id} not found")

prs: List[PullRequest] = (
deployments_service.get_pull_requests_related_to_deployment(deployment)
)
Expand Down
6 changes: 3 additions & 3 deletions backend/analytics_server/mhq/service/code/pr_analytics.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from mhq.store.models.code import OrgRepo, PullRequest
from mhq.store.repos.code import CodeRepoService

from typing import List
from typing import List, Optional


class PullRequestAnalyticsService:
Expand All @@ -14,8 +14,8 @@ def get_prs_by_ids(self, pr_ids: List[str]) -> List[PullRequest]:
def get_team_repos(self, team_id: str) -> List[OrgRepo]:
return self.code_repo_service.get_team_repos(team_id)

def get_repo_by_id(self, team_id: str) -> List[OrgRepo]:
return self.code_repo_service.get_repo_by_id(team_id)
def get_repo_by_id(self, repo_id: str) -> Optional[OrgRepo]:
return self.code_repo_service.get_repo_by_id(repo_id)


def get_pr_analytics_service():
Expand Down
Loading