Skip to content

Commit

Permalink
feat: add pre commit step to force schema update when router changes
Browse files Browse the repository at this point in the history
  • Loading branch information
drbh committed Jul 2, 2024
1 parent 0759ec4 commit 7b34ba3
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 86 deletions.
37 changes: 37 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,40 @@ repos:
- id: fmt
- id: cargo-check
- id: clippy
- repo: local
hooks:
- id: check-openapi-update
name: check openapi spec update
entry: python
language: system
pass_filenames: false
always_run: true
args:
- -c
- |
import os
import sys
import subprocess
def get_changed_files():
result = subprocess.run(['git', 'diff', '--name-only'], capture_output=True, text=True)
return result.stdout.splitlines()
changed_files = get_changed_files()
router_files = [f for f in changed_files if f.startswith('router/')]
if not router_files:
print("No router files changed. Skipping OpenAPI spec check.")
sys.exit(0)
openapi_file = 'docs/openapi.json'
if not os.path.exists(openapi_file):
print(f"Error: {openapi_file} does not exist.")
sys.exit(1)
if openapi_file not in changed_files:
print(f"Error: Router files were updated, but {openapi_file} was not updated.")
sys.exit(1)
else:
print(f"{openapi_file} has been updated along with router changes.")
sys.exit(0)
Loading

0 comments on commit 7b34ba3

Please sign in to comment.