summaryrefslogtreecommitdiffstats
path: root/hooks.py
diff options
context:
space:
mode:
Diffstat (limited to 'hooks.py')
-rw-r--r--hooks.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/hooks.py b/hooks.py
index 82bf7e36..fc31a5ef 100644
--- a/hooks.py
+++ b/hooks.py
@@ -22,6 +22,13 @@ from error import HookError
22from git_refs import HEAD 22from git_refs import HEAD
23 23
24 24
25# The API we've documented to hook authors. Keep in sync with repo-hooks.md.
26_API_ARGS = {
27 "pre-upload": {"project_list", "worktree_list"},
28 "post-sync": {"repo_topdir"},
29}
30
31
25class RepoHook: 32class RepoHook:
26 """A RepoHook contains information about a script to run as a hook. 33 """A RepoHook contains information about a script to run as a hook.
27 34
@@ -56,6 +63,7 @@ class RepoHook:
56 hooks_project, 63 hooks_project,
57 repo_topdir, 64 repo_topdir,
58 manifest_url, 65 manifest_url,
66 bug_url=None,
59 bypass_hooks=False, 67 bypass_hooks=False,
60 allow_all_hooks=False, 68 allow_all_hooks=False,
61 ignore_hooks=False, 69 ignore_hooks=False,
@@ -75,6 +83,7 @@ class RepoHook:
75 run with CWD as this directory. 83 run with CWD as this directory.
76 If you have a manifest, this is manifest.topdir. 84 If you have a manifest, this is manifest.topdir.
77 manifest_url: The URL to the manifest git repo. 85 manifest_url: The URL to the manifest git repo.
86 bug_url: The URL to report issues.
78 bypass_hooks: If True, then 'Do not run the hook'. 87 bypass_hooks: If True, then 'Do not run the hook'.
79 allow_all_hooks: If True, then 'Run the hook without prompting'. 88 allow_all_hooks: If True, then 'Run the hook without prompting'.
80 ignore_hooks: If True, then 'Do not abort action if hooks fail'. 89 ignore_hooks: If True, then 'Do not abort action if hooks fail'.
@@ -85,6 +94,7 @@ class RepoHook:
85 self._hooks_project = hooks_project 94 self._hooks_project = hooks_project
86 self._repo_topdir = repo_topdir 95 self._repo_topdir = repo_topdir
87 self._manifest_url = manifest_url 96 self._manifest_url = manifest_url
97 self._bug_url = bug_url
88 self._bypass_hooks = bypass_hooks 98 self._bypass_hooks = bypass_hooks
89 self._allow_all_hooks = allow_all_hooks 99 self._allow_all_hooks = allow_all_hooks
90 self._ignore_hooks = ignore_hooks 100 self._ignore_hooks = ignore_hooks
@@ -414,6 +424,20 @@ class RepoHook:
414 ignore the result through the option combinations as listed in 424 ignore the result through the option combinations as listed in
415 AddHookOptionGroup(). 425 AddHookOptionGroup().
416 """ 426 """
427 # Make sure our own callers use the documented API.
428 exp_kwargs = _API_ARGS.get(self._hook_type, set())
429 got_kwargs = set(kwargs.keys())
430 if exp_kwargs != got_kwargs:
431 print(
432 "repo internal error: "
433 f"hook '{self._hook_type}' called incorrectly\n"
434 f" got: {sorted(got_kwargs)}\n"
435 f" expected: {sorted(exp_kwargs)}\n"
436 f"Please file a bug: {self._bug_url}",
437 file=sys.stderr,
438 )
439 return False
440
417 # Do not do anything in case bypass_hooks is set, or 441 # Do not do anything in case bypass_hooks is set, or
418 # no-op if there is no hooks project or if hook is disabled. 442 # no-op if there is no hooks project or if hook is disabled.
419 if ( 443 if (
@@ -472,6 +496,7 @@ class RepoHook:
472 "manifest_url": manifest.manifestProject.GetRemote( 496 "manifest_url": manifest.manifestProject.GetRemote(
473 "origin" 497 "origin"
474 ).url, 498 ).url,
499 "bug_url": manifest.contactinfo.bugurl,
475 } 500 }
476 ) 501 )
477 return cls(*args, **kwargs) 502 return cls(*args, **kwargs)