diff --git a/README.md b/README.md index 62861dd..d06eb85 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,8 @@ Built with [FastMCP](https://github.com/jlowin/fastmcp) and the [MCP Python SDK] - [Project Structure](#project-structure) - [Design Decisions](#design-decisions) - [CI/CD (Gitea Actions)](#cicd-gitea-actions) +- [Development & Testing](#️-development--testing) + - [Git Hooks](#git-hooks) - [Known Strava API Limitations](#known-strava-api-limitations) - [Troubleshooting](#troubleshooting) @@ -226,6 +228,26 @@ docker buildx build --platform linux/amd64,linux/arm64 -t strava-mcp-server:test --- +### 5. Git Hooks + +A `pre-commit` hook is provided to automatically run `ruff check` on staged Python files before every commit, catching linting errors before they enter the history. + +The hook is stored in the repository under `scripts/hooks/` for easy installation. + +**Install the hook:** +```bash +cp scripts/hooks/pre-commit .git/hooks/pre-commit +chmod +x .git/hooks/pre-commit +``` + +**Behaviour:** +- ✅ Commit proceeds if `ruff check` passes on all staged `.py` files. +- ❌ Commit is aborted if any linting errors are found. +- 🔧 Auto-fix lint issues with `uv run ruff check --fix`. +- ⚡ Bypass for emergencies: `git commit --no-verify`. + +--- + ## License MIT diff --git a/scripts/hooks/pre-commit b/scripts/hooks/pre-commit new file mode 100755 index 0000000..a8dc5a0 --- /dev/null +++ b/scripts/hooks/pre-commit @@ -0,0 +1,26 @@ +#!/bin/sh +# pre-commit hook: runs ruff check on staged Python files before every commit +# To bypass: git commit --no-verify + +# Get list of staged Python files +STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.py$') + +if [ -z "$STAGED_FILES" ]; then + exit 0 +fi + +echo "🔍 Running ruff check on staged files..." + +uv run ruff check $STAGED_FILES +exit_code=$? + +if [ $exit_code -ne 0 ]; then + echo "" + echo "❌ ruff check failed. Commit aborted." + echo " Fix the issues above or run: uv run ruff check --fix" + echo " To bypass: git commit --no-verify" + exit 1 +fi + +echo "✅ ruff check passed." +exit 0 diff --git a/src/strava_mcp_server/__init__.py b/src/strava_mcp_server/__init__.py index 3c6f6c8..7e4875f 100644 --- a/src/strava_mcp_server/__init__.py +++ b/src/strava_mcp_server/__init__.py @@ -1,2 +1,3 @@ """Strava MCP Server""" + __version__ = "0.1.0" diff --git a/src/strava_mcp_server/get_token.py b/src/strava_mcp_server/get_token.py index 12a2bf2..5b82478 100644 --- a/src/strava_mcp_server/get_token.py +++ b/src/strava_mcp_server/get_token.py @@ -11,6 +11,7 @@ Required scopes: Usage: uv run get_token.py """ + import os import webbrowser import httpx @@ -25,6 +26,7 @@ CLIENT_SECRET = os.getenv("STRAVA_CLIENT_SECRET") REDIRECT_URI = "http://localhost:8765/callback" SCOPES = "profile:read_all,activity:read_all,activity:read,profile:write" + class CallbackHandler(BaseHTTPRequestHandler): client_id: str = "" client_secret: str = "" @@ -50,14 +52,15 @@ class CallbackHandler(BaseHTTPRequestHandler): ) response.raise_for_status() self.tokens = response.json() - + self.send_response(200) self.send_header("Content-Type", "text/html; charset=utf-8") self.end_headers() - + refresh_token = self.tokens.get("refresh_token") - - self.wfile.write(f""" + + self.wfile.write( + f"""