@@ -55,6 +55,15 @@ async def _get_hooks_dir() -> pathlib.Path:
5555 return pathlib .Path (await utils .git ("rev-parse" , "--git-path" , "hooks" ))
5656
5757
58+ def _get_script_resource_path (hook_name : str ) -> str :
59+ """Get the path to a hook script in package resources."""
60+ return str (
61+ importlib .resources .files (__package__ ).joinpath (
62+ f"hooks/scripts/{ hook_name } .sh" ,
63+ ),
64+ )
65+
66+
5867def _get_claude_hooks_dir () -> pathlib .Path :
5968 """Get the global directory for Claude hook scripts."""
6069 return pathlib .Path .home () / ".config" / "mergify-cli" / "claude-hooks"
@@ -165,11 +174,7 @@ def _install_git_hook(
165174
166175 managed_dir = hooks_dir / "mergify-hooks"
167176 script_path = managed_dir / f"{ hook_name } .sh"
168- new_script_file = str (
169- importlib .resources .files (__package__ ).joinpath (
170- f"hooks/scripts/{ hook_name } .sh" ,
171- ),
172- )
177+ new_script_file = _get_script_resource_path (hook_name )
173178 new_wrapper_file = str (
174179 importlib .resources .files (__package__ ).joinpath (
175180 f"hooks/wrappers/{ hook_name } " ,
@@ -340,11 +345,7 @@ async def get_hooks_status() -> dict[str, Any]:
340345 script_needs_update = False
341346
342347 if script_installed :
343- new_script_file = str (
344- importlib .resources .files (__package__ ).joinpath (
345- f"hooks/scripts/{ hook_name } .sh" ,
346- ),
347- )
348+ new_script_file = _get_script_resource_path (hook_name )
348349 script_needs_update = _script_needs_update (script_path , new_script_file )
349350
350351 git_hooks [hook_name ] = {
@@ -388,11 +389,7 @@ async def ensure_hooks_updated() -> None:
388389 if managed_dir .exists ():
389390 for hook_name in _get_git_hook_names ():
390391 script_path = managed_dir / f"{ hook_name } .sh"
391- new_script_file = str (
392- importlib .resources .files (__package__ ).joinpath (
393- f"hooks/scripts/{ hook_name } .sh" ,
394- ),
395- )
392+ new_script_file = _get_script_resource_path (hook_name )
396393
397394 if _script_needs_update (script_path , new_script_file ):
398395 console .log (
0 commit comments