Skip to content

feat: scaffold Python project with shared utilities#6

Open
Keramikus-97 wants to merge 1 commit into
mainfrom
devin/1780753487-refactor-shared-utilities
Open

feat: scaffold Python project with shared utilities#6
Keramikus-97 wants to merge 1 commit into
mainfrom
devin/1780753487-refactor-shared-utilities

Conversation

@Keramikus-97

Copy link
Copy Markdown
Owner

Summary

Adds a full Python package structure where every domain module delegates
common patterns to a shared utils/ package, preventing code duplication
from the start.

Shared utilities (src/opencode_github/utils/)

Module Purpose Consumers
errors Unified OpenCodeErrorConfigError, GitHubAPIError, WebhookValidationError, CommandParseError all modules
env get_required_env(name) / get_optional_env(name, default) — typed env-var loading with validation config
crypto compute_hmac_sha256(secret, payload) / compare_signatures(a, b) — constant-time HMAC helpers webhook_handler
http build_headers(token), parse_json_response(resp), create_http_client(token=, base_url=) github_client
text extract_first_match(pattern, text), sanitize_input(text, max_length=) comment_parser, webhook_handler

Domain modules

  • config.pyConfig.from_env() dataclass, calls utils.env
  • comment_parser.pyparse_command(body) → ParsedCommand | None, calls utils.text
  • github_client.py — async context-manager GitHubClient, calls utils.http
  • webhook_handler.pyverify_signature() + parse_event() → WebhookEvent, calls utils.crypto + utils.text

Tests & tooling

  • 44 tests (pytest + pytest-asyncio), all passing
  • ruff lint configured (E, F, I, N, W, UP), all passing
  • pyproject.toml with [dev] extras, .gitignore

Link to Devin session: https://app.devin.ai/sessions/340db4562f06435694a8a6cb44bbf5e6
Requested by: @Keramikus-97

Add Python package structure with shared utility modules that prevent
code duplication across domain modules:

- utils/errors: unified exception hierarchy
- utils/env: env-var loading & validation
- utils/crypto: HMAC-SHA256 helpers
- utils/http: GitHub API HTTP helpers
- utils/text: regex extraction & input sanitisation

Domain modules (config, comment_parser, github_client, webhook_handler)
delegate common patterns to utils/ instead of reimplementing them.

Includes pyproject.toml, .gitignore, and 44 passing tests.

Co-Authored-By: dominicpape <dominicpape@gmx.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant