11import logging
22from dataclasses import dataclass
33
4- from shared .billing import is_pr_billing_plan
54from shared .config import get_config
65from shared .plan .service import PlanService
76from shared .upload .utils import query_monthly_coverage_measurements
8- from sqlalchemy import func
97
108from database .enums import Decoration
119from database .models import Owner
@@ -31,8 +29,8 @@ class DecorationDetails(object):
3129 decoration_type : Decoration
3230 reason : str
3331 should_attempt_author_auto_activation : bool = False
34- activation_org_ownerid : int = None
35- activation_author_ownerid : int = None
32+ activation_org_ownerid : int | None = None
33+ activation_author_ownerid : int | None = None
3634
3735
3836def _is_bot_account (author : Owner ) -> bool :
@@ -50,7 +48,7 @@ def determine_uploads_used(plan_service: PlanService) -> int:
5048
5149def determine_decoration_details (
5250 enriched_pull : EnrichedPull , empty_upload = None
53- ) -> dict :
51+ ) -> DecorationDetails :
5452 """
5553 Determine the decoration details from pull information. We also check if the pull author needs to be activated
5654
@@ -85,7 +83,7 @@ def determine_decoration_details(
8583 )
8684
8785 if db_pull .repository .private is False :
88- # public repo or repo we arent certain is private should be standard
86+ # public repo or repo we aren't certain is private should be standard
8987 return DecorationDetails (
9088 decoration_type = Decoration .standard , reason = "Public repo"
9189 )
@@ -94,19 +92,12 @@ def determine_decoration_details(
9492
9593 db_session = db_pull .get_db_session ()
9694
97- if org .service == "gitlab" and org .parent_service_id :
98- # need to get root group so we can check plan info
99- (gl_root_group ,) = db_session .query (
100- func .public .get_gitlab_root_group (org .ownerid )
101- ).first ()
95+ # do not access plan directly - only through PlanService
96+ org_plan = PlanService (current_org = org )
97+ # use the org that has the plan - for GL this is the root_org rather than the repository.owner org
98+ org = org_plan .current_org
10299
103- org = (
104- db_session .query (Owner )
105- .filter (Owner .ownerid == gl_root_group .get ("ownerid" ))
106- .first ()
107- )
108-
109- if not is_pr_billing_plan (org .plan ):
100+ if not org_plan .is_pr_billing_plan :
110101 return DecorationDetails (
111102 decoration_type = Decoration .standard , reason = "Org not on PR plan"
112103 )
@@ -134,13 +125,12 @@ def determine_decoration_details(
134125 reason = "PR author not found in database" ,
135126 )
136127
137- plan_service = PlanService (current_org = org )
138- monthly_limit = plan_service .monthly_uploads_limit
128+ monthly_limit = org_plan .monthly_uploads_limit
139129 if monthly_limit is not None :
140- uploads_used = determine_uploads_used (plan_service = plan_service )
130+ uploads_used = determine_uploads_used (plan_service = org_plan )
141131
142132 if (
143- uploads_used >= plan_service .monthly_uploads_limit
133+ uploads_used >= org_plan .monthly_uploads_limit
144134 and not requires_license ()
145135 ):
146136 return DecorationDetails (
0 commit comments