Skip to content

Commit 0292612

Browse files
fix(#1818): CI: Update docs when API changes
We should check for changes on the public API and require changes to the docs Signed-off-by: chenzeyan54-commits <chenzeyan54-commits@users.noreply.github.com>
1 parent b893232 commit 0292612

1 file changed

Lines changed: 54 additions & 33 deletions

File tree

‎.github/hooks/scripts/README.md‎

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,72 @@
1-
# Copilot Agent Hooks Scripts
1+
#!/usr/bin/env python3
2+
"""
3+
check_api_changes.py - Detects changes to the public API and enforces documentation updates.
24
3-
This directory contains Python scripts used by agent hooks to automate workflow validation.
5+
This script is invoked by the pre-commit hook to ensure that any modifications
6+
to public API files are accompanied by corresponding documentation changes.
7+
"""
48

5-
## Scripts
9+
import subprocess
10+
import sys
611

7-
### session_start.py
812

9-
Runs at session start to inject project context:
13+
# Files that define the public API surface
14+
PUBLIC_API_FILES = [
15+
"src/extension.ts",
16+
"src/api.ts",
17+
]
1018

11-
- Current git branch and commit
12-
- Uncommitted changes count
13-
- Open issues (if gh CLI available)
14-
- Snapshot health summary (if available)
15-
- Available skills reminder
19+
# Documentation files that must be updated when the API changes
20+
DOCS_FILES = [
21+
"README.md",
22+
"docs/api.md",
23+
"CHANGELOG.md",
24+
]
1625

17-
### post_tool_use.py
1826

19-
Runs after file edit tools to provide immediate feedback:
27+
def get_staged_files():
28+
"""Return list of files staged for the current commit."""
29+
result = subprocess.run(
30+
["git", "diff", "--cached", "--name-only"],
31+
capture_output=True,
32+
text=True,
33+
)
34+
if result.returncode != 0:
35+
return []
36+
return [f for f in result.stdout.strip().split("\n") if f]
2037

21-
- Runs ESLint on changed TypeScript files
22-
- Reports lint errors back to the model
2338

24-
### stop_hook.py
39+
def has_api_changes(staged_files):
40+
"""Check whether any public API files are staged."""
41+
return any(f in PUBLIC_API_FILES for f in staged_files)
2542

26-
Runs before session ends to enforce workflow:
2743

28-
- Checks for uncommitted TypeScript changes
29-
- Reminds about pre-commit checks
30-
- Blocks completion if staged changes aren't committed
44+
def has_doc_changes(staged_files):
45+
"""Check whether any documentation files are staged."""
46+
return any(f in DOCS_FILES for f in staged_files)
3147

32-
### subagent_stop.py
3348

34-
Runs when subagents complete:
49+
def main():
50+
"""Enforce that API changes are documented."""
51+
staged_files = get_staged_files()
3552

36-
- Currently a passthrough for logging
37-
- Can be extended to validate reviewer output
53+
if not has_api_changes(staged_files):
54+
sys.exit(0)
3855

39-
## Requirements
56+
if has_doc_changes(staged_files):
57+
print("API changes detected with documentation updates.")
58+
sys.exit(0)
4059

41-
These scripts use Python 3.9+ with no external dependencies (beyond what's already in the repo).
60+
print("WARNING: Public API changes detected without documentation updates.")
61+
print("Modified API files:")
62+
for f in PUBLIC_API_FILES:
63+
if f in staged_files:
64+
print(f" - {f}")
65+
print("Please update one or more of these documentation files:")
66+
for f in DOCS_FILES:
67+
print(f" - {f}")
68+
sys.exit(1)
4269

43-
They expect:
4470

45-
- `git` CLI available
46-
- `gh` CLI available (optional, for issue context)
47-
- `npx` available for running ESLint
48-
49-
## Hook Configuration
50-
51-
See `.github/hooks/maintainer-hooks.json` for the hook configuration that loads these scripts.
71+
if __name__ == "__main__":
72+
main()

0 commit comments

Comments
 (0)