Skip to content

Commit

Permalink
Convert PolicyResult & OriginInfo into a typed NamedTuple
Browse files Browse the repository at this point in the history
  • Loading branch information
dcermak committed Jun 21, 2023
1 parent 7f72c52 commit aa35b9d
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions osclib/origin.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,19 @@
'!maintenance_incident',
],
}

OriginInfo = namedtuple('OriginInfo', ['project', 'pending'])
PendingRequestInfo = namedtuple('PendingRequestInfo', ['identifier', 'reviews_remaining'])
PolicyResult = namedtuple('PolicyResult', ['wait', 'accept', 'reviews', 'comments'])


class OriginInfo(NamedTuple):
project: str
pending: PendingRequestInfo


class PolicyResult(NamedTuple):
wait: bool
accept: bool
reviews: Dict[str, str]
comments: List[str]


def origin_info_str(self):
Expand Down Expand Up @@ -241,7 +250,7 @@ def origin_workaround_strip(origin: str) -> str:

@memoize(session=True)
def origin_find(apiurl, target_project, package, source_hash=None, current=False,
pending_allow=True, fallback=True):
pending_allow=True, fallback=True) -> Optional[OriginInfo]:
config = config_load(apiurl, target_project)

if not source_hash:
Expand Down Expand Up @@ -291,7 +300,7 @@ def project_source_contain(apiurl, project, package, source_hash):
return False


def project_source_pending(apiurl, project, package, source_hash):
def project_source_pending(apiurl, project, package, source_hash) -> Union[PendingRequestInfo, Literal[False]]:
apiurl_remote, project_remote = project_remote_apiurl(apiurl, project)
request_actions = request_action_list_source(apiurl_remote, project_remote, package,
states=['new', 'review'], include_release=True)
Expand Down Expand Up @@ -410,7 +419,7 @@ def origin_find_highest(apiurl, project, package):

def policy_evaluate(apiurl, project, package,
origin_info_new, origin_info_old,
source_hash_new, source_hash_old):
source_hash_new, source_hash_old) -> PolicyResult:
if origin_info_new is None:
config = config_load(apiurl, project)
origins = config_origin_list(config, apiurl, project, package, True)
Expand Down Expand Up @@ -511,7 +520,7 @@ def policy_input_calculate(apiurl, project, package,
return inputs


def policy_input_evaluate(policy, inputs):
def policy_input_evaluate(policy, inputs) -> PolicyResult:
result = PolicyResult(False, True, {}, [])

if inputs['new_package']:
Expand Down

0 comments on commit aa35b9d

Please sign in to comment.