Compare commits

..

11 Commits

Author SHA1 Message Date
cal
aac4bf50d5 Merge pull request 'chore: switch CI to tag-triggered builds' (#107) from chore/tag-triggered-ci into main
Reviewed-on: #107
2026-04-06 16:59:02 +00:00
Cal Corum
4ad445b0da chore: switch CI to tag-triggered builds
Match the discord bot's CI pattern — trigger on CalVer tag push
instead of branch push/PR. Removes auto-CalVer generation and
simplifies to a single build step.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 16:58:45 +00:00
cal
8d9bbdd7a0 Merge pull request 'fix: increase get_games limit to 1000' (#106) from fix/increase-get-game-limit into main
All checks were successful
Build Docker Image / build (push) Successful in 1m6s
Reviewed-on: #106
2026-04-06 15:30:47 +00:00
cal
c95459fa5d Update app/routers_v3/stratgame.py
All checks were successful
Build Docker Image / build (pull_request) Successful in 4m51s
2026-04-06 14:58:36 +00:00
cal
d809590f0e Merge pull request 'fix: correct column references in season pitching stats SQL' (#105) from fix/pitching-stats-column-name into main
All checks were successful
Build Docker Image / build (push) Successful in 2m11s
2026-04-02 16:57:30 +00:00
cal
0d8e666a75 Merge pull request 'fix: let HTTPException pass through @handle_db_errors' (#104) from fix/handle-db-errors-passthrough-http into main
Some checks failed
Build Docker Image / build (push) Has been cancelled
2026-04-02 16:57:12 +00:00
Cal Corum
bd19b7d913 fix: correct column references in season pitching stats view
All checks were successful
Build Docker Image / build (pull_request) Successful in 2m4s
sp.on_first/on_second/on_third don't exist — the actual columns are
on_first_id/on_second_id/on_third_id. This caused failures when
updating season pitching stats after games.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 11:54:56 -05:00
Cal Corum
c49f91cc19 test: update test_get_nonexistent_play to expect 404 after HTTPException fix
All checks were successful
Build Docker Image / build (pull_request) Successful in 1m3s
After handle_db_errors no longer catches HTTPException, GET /plays/999999999
correctly returns 404 instead of 500. Update the assertion and docstring
to reflect the fixed behavior.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-02 09:30:39 -05:00
Cal Corum
215085b326 fix: let HTTPException pass through @handle_db_errors unchanged
All checks were successful
Build Docker Image / build (pull_request) Successful in 2m34s
The decorator was catching all exceptions including intentional
HTTPException (401, 404, etc.) and re-wrapping them as 500 "Database
error". This masked auth failures and other deliberate HTTP errors.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 08:30:22 -05:00
cal
c063f5c4ef Merge pull request 'hotfix: remove output caps from GET /players' (#103) from hotfix/remove-players-output-caps into main
All checks were successful
Build Docker Image / build (push) Successful in 1m3s
2026-04-02 01:19:51 +00:00
Cal Corum
d92f571960 hotfix: remove output caps from GET /players endpoint
All checks were successful
Build Docker Image / build (pull_request) Successful in 2m29s
The MAX_LIMIT/DEFAULT_LIMIT caps added in 16f3f8d are too restrictive
for the /players endpoint — bot and website consumers need full player
lists without pagination. Reverts limit param to Optional[int] with no
ceiling while keeping caps on all other endpoints.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 20:14:35 -05:00
6 changed files with 57 additions and 83 deletions

View File

@ -1,20 +1,18 @@
# Gitea Actions: Docker Build, Push, and Notify # Gitea Actions: Docker Build, Push, and Notify
# #
# CI/CD pipeline for Major Domo Database API: # CI/CD pipeline for Major Domo Database API:
# - Builds Docker images on every push/PR # - Triggered by pushing a CalVer tag (e.g., 2026.4.5)
# - Auto-generates CalVer version (YYYY.MM.BUILD) on main branch merges # - Builds Docker image and pushes to Docker Hub with version + latest tags
# - Pushes to Docker Hub and creates git tag on main
# - Sends Discord notifications on success/failure # - Sends Discord notifications on success/failure
#
# To release: git tag -a 2026.4.5 -m "description" && git push origin 2026.4.5
name: Build Docker Image name: Build Docker Image
on: on:
push: push:
branches: tags:
- main - '20*' # matches CalVer tags like 2026.4.5
pull_request:
branches:
- main
jobs: jobs:
build: build:
@ -24,7 +22,16 @@ jobs:
- name: Checkout code - name: Checkout code
uses: https://github.com/actions/checkout@v4 uses: https://github.com/actions/checkout@v4
with: with:
fetch-depth: 0 # Full history for tag counting fetch-depth: 0
- name: Extract version from tag
id: version
run: |
VERSION=${GITHUB_REF#refs/tags/}
SHA_SHORT=$(git rev-parse --short HEAD)
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "sha_short=$SHA_SHORT" >> $GITHUB_OUTPUT
echo "timestamp=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: https://github.com/docker/setup-buildx-action@v3 uses: https://github.com/docker/setup-buildx-action@v3
@ -35,80 +42,47 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }} username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }} password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Generate CalVer version - name: Build and push Docker image
id: calver
uses: cal/gitea-actions/calver@main
# Dev build: push with dev + dev-SHA tags (PR/feature branches)
- name: Build Docker image (dev)
if: github.ref != 'refs/heads/main'
uses: https://github.com/docker/build-push-action@v5
with:
context: .
push: true
tags: |
manticorum67/major-domo-database:dev
manticorum67/major-domo-database:dev-${{ steps.calver.outputs.sha_short }}
cache-from: type=registry,ref=manticorum67/major-domo-database:buildcache
cache-to: type=registry,ref=manticorum67/major-domo-database:buildcache,mode=max
# Production build: push with latest + CalVer tags (main only)
- name: Build Docker image (production)
if: github.ref == 'refs/heads/main'
uses: https://github.com/docker/build-push-action@v5 uses: https://github.com/docker/build-push-action@v5
with: with:
context: . context: .
push: true push: true
tags: | tags: |
manticorum67/major-domo-database:${{ steps.version.outputs.version }}
manticorum67/major-domo-database:latest manticorum67/major-domo-database:latest
manticorum67/major-domo-database:${{ steps.calver.outputs.version }}
manticorum67/major-domo-database:${{ steps.calver.outputs.version_sha }}
cache-from: type=registry,ref=manticorum67/major-domo-database:buildcache cache-from: type=registry,ref=manticorum67/major-domo-database:buildcache
cache-to: type=registry,ref=manticorum67/major-domo-database:buildcache,mode=max cache-to: type=registry,ref=manticorum67/major-domo-database:buildcache,mode=max
- name: Tag release
if: success() && github.ref == 'refs/heads/main'
uses: cal/gitea-actions/gitea-tag@main
with:
version: ${{ steps.calver.outputs.version }}
token: ${{ github.token }}
- name: Build Summary - name: Build Summary
run: | run: |
echo "## Docker Build Successful" >> $GITHUB_STEP_SUMMARY echo "## Docker Build Successful" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** \`${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Image Tags:**" >> $GITHUB_STEP_SUMMARY echo "**Image Tags:**" >> $GITHUB_STEP_SUMMARY
echo "- \`manticorum67/major-domo-database:${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
echo "- \`manticorum67/major-domo-database:latest\`" >> $GITHUB_STEP_SUMMARY echo "- \`manticorum67/major-domo-database:latest\`" >> $GITHUB_STEP_SUMMARY
echo "- \`manticorum67/major-domo-database:${{ steps.calver.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
echo "- \`manticorum67/major-domo-database:${{ steps.calver.outputs.version_sha }}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY
echo "**Build Details:**" >> $GITHUB_STEP_SUMMARY echo "**Build Details:**" >> $GITHUB_STEP_SUMMARY
echo "- Branch: \`${{ steps.calver.outputs.branch }}\`" >> $GITHUB_STEP_SUMMARY echo "- Commit: \`${{ steps.version.outputs.sha_short }}\`" >> $GITHUB_STEP_SUMMARY
echo "- Commit: \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY echo "- Timestamp: \`${{ steps.version.outputs.timestamp }}\`" >> $GITHUB_STEP_SUMMARY
echo "- Timestamp: \`${{ steps.calver.outputs.timestamp }}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ github.ref }}" == "refs/heads/main" ]; then echo "Pull with: \`docker pull manticorum67/major-domo-database:${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
echo "Pushed to Docker Hub!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Pull with: \`docker pull manticorum67/major-domo-database:latest\`" >> $GITHUB_STEP_SUMMARY
else
echo "_PR build - image not pushed to Docker Hub_" >> $GITHUB_STEP_SUMMARY
fi
- name: Discord Notification - Success - name: Discord Notification - Success
if: success() && github.ref == 'refs/heads/main' if: success()
uses: cal/gitea-actions/discord-notify@main uses: cal/gitea-actions/discord-notify@main
with: with:
webhook_url: ${{ secrets.DISCORD_WEBHOOK }} webhook_url: ${{ secrets.DISCORD_WEBHOOK }}
title: "Major Domo Database" title: "Major Domo Database"
status: success status: success
version: ${{ steps.calver.outputs.version }} version: ${{ steps.version.outputs.version }}
image_tag: ${{ steps.calver.outputs.version_sha }} image_tag: ${{ steps.version.outputs.version }}
commit_sha: ${{ steps.calver.outputs.sha_short }} commit_sha: ${{ steps.version.outputs.sha_short }}
timestamp: ${{ steps.calver.outputs.timestamp }} timestamp: ${{ steps.version.outputs.timestamp }}
- name: Discord Notification - Failure - name: Discord Notification - Failure
if: failure() && github.ref == 'refs/heads/main' if: failure()
uses: cal/gitea-actions/discord-notify@main uses: cal/gitea-actions/discord-notify@main
with: with:
webhook_url: ${{ secrets.DISCORD_WEBHOOK }} webhook_url: ${{ secrets.DISCORD_WEBHOOK }}

View File

@ -40,7 +40,7 @@ python migrations.py # Run migrations (SQL files in migrat
- **Bot container**: `dev_sba_postgres` (PostgreSQL) + `dev_sba_db_api` (API) — check with `docker ps` - **Bot container**: `dev_sba_postgres` (PostgreSQL) + `dev_sba_db_api` (API) — check with `docker ps`
- **Image**: `manticorum67/major-domo-database:dev` (Docker Hub) - **Image**: `manticorum67/major-domo-database:dev` (Docker Hub)
- **CI/CD**: Gitea Actions on PR to `main` — builds Docker image, auto-generates CalVer version (`YYYY.MM.BUILD`) on merge - **CI/CD**: Gitea Actions — tag-triggered Docker builds. Push a CalVer tag to release: `git tag -a 2026.4.5 -m "description" && git push origin 2026.4.5`
## Important ## Important

View File

@ -379,14 +379,14 @@ def update_season_pitching_stats(player_ids, season, db_connection):
-- RBI allowed (excluding HR) per runner opportunity -- RBI allowed (excluding HR) per runner opportunity
CASE CASE
WHEN (SUM(CASE WHEN sp.on_first IS NOT NULL THEN 1 ELSE 0 END) + WHEN (SUM(CASE WHEN sp.on_first_id IS NOT NULL THEN 1 ELSE 0 END) +
SUM(CASE WHEN sp.on_second IS NOT NULL THEN 1 ELSE 0 END) + SUM(CASE WHEN sp.on_second_id IS NOT NULL THEN 1 ELSE 0 END) +
SUM(CASE WHEN sp.on_third IS NOT NULL THEN 1 ELSE 0 END)) > 0 SUM(CASE WHEN sp.on_third_id IS NOT NULL THEN 1 ELSE 0 END)) > 0
THEN ROUND( THEN ROUND(
(SUM(sp.rbi) - SUM(sp.homerun))::DECIMAL / (SUM(sp.rbi) - SUM(sp.homerun))::DECIMAL /
(SUM(CASE WHEN sp.on_first IS NOT NULL THEN 1 ELSE 0 END) + (SUM(CASE WHEN sp.on_first_id IS NOT NULL THEN 1 ELSE 0 END) +
SUM(CASE WHEN sp.on_second IS NOT NULL THEN 1 ELSE 0 END) + SUM(CASE WHEN sp.on_second_id IS NOT NULL THEN 1 ELSE 0 END) +
SUM(CASE WHEN sp.on_third IS NOT NULL THEN 1 ELSE 0 END)), SUM(CASE WHEN sp.on_third_id IS NOT NULL THEN 1 ELSE 0 END)),
3 3
) )
ELSE 0.000 ELSE 0.000
@ -807,6 +807,10 @@ def handle_db_errors(func):
return result return result
except HTTPException:
# Let intentional HTTP errors (401, 404, etc.) pass through unchanged
raise
except Exception as e: except Exception as e:
elapsed_time = time.time() - start_time elapsed_time = time.time() - start_time
error_trace = traceback.format_exc() error_trace = traceback.format_exc()

View File

@ -10,8 +10,6 @@ from ..dependencies import (
oauth2_scheme, oauth2_scheme,
cache_result, cache_result,
handle_db_errors, handle_db_errors,
MAX_LIMIT,
DEFAULT_LIMIT,
) )
from ..services.base import BaseService from ..services.base import BaseService
from ..services.player_service import PlayerService from ..services.player_service import PlayerService
@ -30,7 +28,7 @@ async def get_players(
strat_code: list = Query(default=None), strat_code: list = Query(default=None),
is_injured: Optional[bool] = None, is_injured: Optional[bool] = None,
sort: Optional[str] = None, sort: Optional[str] = None,
limit: int = Query(default=DEFAULT_LIMIT, ge=1, le=MAX_LIMIT), limit: Optional[int] = Query(default=None, ge=1),
offset: Optional[int] = Query( offset: Optional[int] = Query(
default=None, ge=0, description="Number of results to skip for pagination" default=None, ge=0, description="Number of results to skip for pagination"
), ),

View File

@ -13,7 +13,6 @@ from ..dependencies import (
PRIVATE_IN_SCHEMA, PRIVATE_IN_SCHEMA,
handle_db_errors, handle_db_errors,
update_season_batting_stats, update_season_batting_stats,
MAX_LIMIT,
DEFAULT_LIMIT, DEFAULT_LIMIT,
) )
@ -61,7 +60,7 @@ async def get_games(
division_id: Optional[int] = None, division_id: Optional[int] = None,
short_output: Optional[bool] = False, short_output: Optional[bool] = False,
sort: Optional[str] = None, sort: Optional[str] = None,
limit: int = Query(default=DEFAULT_LIMIT, ge=1, le=MAX_LIMIT), limit: int = Query(default=DEFAULT_LIMIT, ge=1, le=1000),
offset: int = Query(default=0, ge=0), offset: int = Query(default=0, ge=0),
) -> Any: ) -> Any:
all_games = StratGame.select() all_games = StratGame.select()

View File

@ -81,9 +81,9 @@ class TestRouteRegistration:
for route, methods in EXPECTED_PLAY_ROUTES.items(): for route, methods in EXPECTED_PLAY_ROUTES.items():
assert route in paths, f"Route {route} missing from OpenAPI schema" assert route in paths, f"Route {route} missing from OpenAPI schema"
for method in methods: for method in methods:
assert ( assert method in paths[route], (
method in paths[route] f"Method {method.upper()} missing for {route}"
), f"Method {method.upper()} missing for {route}" )
def test_play_routes_have_plays_tag(self, api): def test_play_routes_have_plays_tag(self, api):
"""All play routes should be tagged with 'plays'.""" """All play routes should be tagged with 'plays'."""
@ -96,9 +96,9 @@ class TestRouteRegistration:
for method, spec in paths[route].items(): for method, spec in paths[route].items():
if method in ("get", "post", "patch", "delete"): if method in ("get", "post", "patch", "delete"):
tags = spec.get("tags", []) tags = spec.get("tags", [])
assert ( assert "plays" in tags, (
"plays" in tags f"{method.upper()} {route} missing 'plays' tag, has {tags}"
), f"{method.upper()} {route} missing 'plays' tag, has {tags}" )
@pytest.mark.post_deploy @pytest.mark.post_deploy
@pytest.mark.skip( @pytest.mark.skip(
@ -124,9 +124,9 @@ class TestRouteRegistration:
]: ]:
params = paths[route]["get"].get("parameters", []) params = paths[route]["get"].get("parameters", [])
param_names = [p["name"] for p in params] param_names = [p["name"] for p in params]
assert ( assert "sbaplayer_id" in param_names, (
"sbaplayer_id" in param_names f"sbaplayer_id parameter missing from {route}"
), f"sbaplayer_id parameter missing from {route}" )
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
@ -493,10 +493,9 @@ class TestPlayCrud:
assert result["id"] == play_id assert result["id"] == play_id
def test_get_nonexistent_play(self, api): def test_get_nonexistent_play(self, api):
"""GET /plays/999999999 returns an error (wrapped by handle_db_errors).""" """GET /plays/999999999 returns 404 Not Found."""
r = requests.get(f"{api}/api/v3/plays/999999999", timeout=10) r = requests.get(f"{api}/api/v3/plays/999999999", timeout=10)
# handle_db_errors wraps HTTPException as 500 with detail message assert r.status_code == 404
assert r.status_code == 500
assert "not found" in r.json().get("detail", "").lower() assert "not found" in r.json().get("detail", "").lower()
@ -575,9 +574,9 @@ class TestGroupBySbaPlayer:
) )
assert r_seasons.status_code == 200 assert r_seasons.status_code == 200
season_pas = [s["pa"] for s in r_seasons.json()["stats"]] season_pas = [s["pa"] for s in r_seasons.json()["stats"]]
assert career_pa >= max( assert career_pa >= max(season_pas), (
season_pas f"Career PA ({career_pa}) should be >= max season PA ({max(season_pas)})"
), f"Career PA ({career_pa}) should be >= max season PA ({max(season_pas)})" )
@pytest.mark.post_deploy @pytest.mark.post_deploy
def test_batting_sbaplayer_short_output(self, api): def test_batting_sbaplayer_short_output(self, api):