@@ -239,39 +239,53 @@ def tf_output_or_none(tf_output, output_prop):
239239
240240
241241def extract_git_vars (path = None , github_url = None ):
242- if path is None :
243- path = get_git_root ("." )
244- github_repo = Repo (path )
245- if github_url is None :
246- github_url = github_repo .remotes [0 ].config_reader .get ("url" )
247- if "/" in github_url [- 1 :]:
248- github_url = github_url [:- 1 ]
249- if "http" in github_url :
250- github_org_name = github_url .split ("/" )[- 2 ]
251- github_repo_name = github_url .split ("/" )[- 1 ].split ("." )[0 ]
252- else :
253- github_url = github_url .replace (".git" , "" )
254- github_org_name = github_url .split (":" )[1 ].split ("/" )[0 ]
255- github_repo_name = github_url .split (":" )[1 ].split ("/" )[1 ]
256- github_sha = github_repo .head .object .hexsha
242+ github_org_name = None
243+ github_repo_name = None
244+ github_sha = None
245+ github_actor = None
257246 github_branch = None
258- github_branch_detached = False
247+ github_branch_detached = None
259248 try :
260- github_branch = github_repo .active_branch
261- except TypeError as e :
262- logging .warning (
263- "Unable to detected github_branch. caught the following error: {}" .format (
264- e .__str__ ()
249+ if path is None :
250+ path = get_git_root ("." )
251+ github_repo = Repo (path )
252+ if github_url is None :
253+ github_url = github_repo .remotes [0 ].config_reader .get ("url" )
254+ if "/" in github_url [- 1 :]:
255+ github_url = github_url [:- 1 ]
256+ if "http" in github_url :
257+ github_org_name = github_url .split ("/" )[- 2 ]
258+ github_repo_name = github_url .split ("/" )[- 1 ].split ("." )[0 ]
259+ else :
260+ github_url = github_url .replace (".git" , "" )
261+ github_org_name = github_url .split (":" )[1 ].split ("/" )[0 ]
262+ github_repo_name = github_url .split (":" )[1 ].split ("/" )[1 ]
263+ github_sha = github_repo .head .object .hexsha
264+ github_branch = None
265+ github_branch_detached = False
266+ try :
267+ github_branch = github_repo .active_branch
268+ except TypeError as e :
269+ logging .warning (
270+ "Unable to detected github_branch. caught the following error: {}" .format (
271+ e .__str__ ()
272+ )
265273 )
266- )
267- github_branch_detached = True
274+ github_branch_detached = True
268275
269- github_actor = None
270- try :
271- github_actor = github_repo .config_reader ().get_value ("user" , "name" )
272- except configparser .NoSectionError as e :
276+ github_actor = None
277+ try :
278+ github_actor = github_repo .config_reader ().get_value ("user" , "name" )
279+ except configparser .NoSectionError as e :
280+ logging .warning (
281+ "Unable to detected github_actor. caught the following error: {}" .format (
282+ e .__str__ ()
283+ )
284+ )
285+ github_branch_detached = True
286+ except git .exc .InvalidGitRepositoryError as e :
273287 logging .warning (
274- "Unable to detected github_actor . caught the following error: {}" .format (
288+ "Unable to fill git vars . caught the following error: {}" .format (
275289 e .__str__ ()
276290 )
277291 )
0 commit comments