2222
2323'''Git utilities'''
2424
25+ from __future__ import annotations
26+
2527import logging
28+ import time
29+ from datetime import datetime
30+ from datetime import timezone
31+ from typing import TypedDict
32+
2633import giteapy
2734from giteapy .rest import ApiException
28- from datetime import datetime , timezone
29- import time
3035
3136import nimp .sys .process
3237
3338
39+ class GitApiContext (TypedDict ):
40+ instance : giteapy .RepositoryApi
41+ repo_owner : str
42+ repo_name : str
43+
44+
3445def get_branch ():
3546 '''Get the current active branch'''
3647 command = 'git branch --contains HEAD'
@@ -96,17 +107,17 @@ def gitea_has_missing_params(env):
96107 return has_missing_params
97108
98109
99- def check_for_gitea_env (env ):
110+ def check_for_gitea_env (env ) -> bool :
100111 if hasattr (env , 'gitea_branches' ) and env .branch in env .gitea_branches :
101112 return True
102113 if hasattr (env , 'gitea_branch' ) and env .branch in env .gitea_branch :
103114 return True
104115 return False
105116
106117
107- def initialize_gitea_api_context (env ):
118+ def initialize_gitea_api_context (env ) -> GitApiContext | None :
108119 if not check_for_gitea_env (env ):
109- return False
120+ return None
110121 if gitea_has_missing_params (env ):
111122 raise ValueError ("You're missing mandatory gitea params in project conf" )
112123
@@ -117,7 +128,7 @@ def initialize_gitea_api_context(env):
117128 return {'instance' : api_instance , 'repo_owner' : env .gitea_repo_owner , 'repo_name' : env .gitea_repo_name }
118129
119130
120- def get_gitea_commit_timestamp (gitea_context , commit_sha ):
131+ def get_gitea_commit_timestamp (gitea_context : GitApiContext , commit_sha ):
121132 if not commit_sha :
122133 return None
123134
0 commit comments