Skip to content

Commit

Permalink
Add GitHub Pydantic Schemas (#321)
Browse files Browse the repository at this point in the history
Add Pydantic schemas for Github objects (PRs, Users, Branches, etc.)
  • Loading branch information
toddbirchard authored Feb 5, 2024
1 parent 67a1fad commit 38d975b
Show file tree
Hide file tree
Showing 42 changed files with 1,302 additions and 682 deletions.
1 change: 1 addition & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Initialize API."""

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

Expand Down
1 change: 1 addition & 0 deletions app/accounts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""User account management & functionality."""

from fastapi import APIRouter, HTTPException

from config import settings
Expand Down
1 change: 1 addition & 0 deletions app/analytics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Fetch site traffic & search query analytics."""

from fastapi import APIRouter

from app.analytics.plausible import top_visited_pages_by_timeframe
Expand Down
3 changes: 2 additions & 1 deletion app/analytics/algolia.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Helper functions to fetch search query activity from Algolia."""

from typing import Any, Dict, List, Optional

import requests
Expand Down Expand Up @@ -32,7 +33,7 @@ def persist_algolia_searches(time_period: str) -> List[Optional[dict]]:
"direction": "desc",
"startDate": get_start_date_range(time_period),
}
resp = requests.get(settings.ALGOLIA_SEARCHES_ENDPOINT, headers=headers, params=params)
resp = requests.get(settings.ALGOLIA_SEARCHES_ENDPOINT, headers=headers, params=params, timeout=30)
if resp.status_code == 200 and resp.json().get("searches") is not None:
search_queries = resp.json().get("searches")
search_queries = filter_search_queries(search_queries)
Expand Down
3 changes: 2 additions & 1 deletion app/analytics/migrate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Import site analytics from data warehouse to application."""

from typing import Any, Dict, List

from clients import gbq
Expand All @@ -14,7 +15,7 @@ def import_site_analytics(timeframe: str) -> Dict[str, List[Any]]:
:returns: Dict[str, List[Any]]
"""
sql_query = open(f"{settings.BASE_DIR}/database/queries/analytics/{timeframe}.sql").read()
sql_query = open(f"{settings.BASE_DIR}/database/queries/analytics/{timeframe}.sql", encoding="utf-8").read()
sql_table = f"{timeframe}_stats"
query_job = gbq.query(sql_query)
result = query_job.result()
Expand Down
1 change: 1 addition & 0 deletions app/analytics/plausible.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Fetch site analytics via Plausible API."""

from typing import List, Optional

import requests
Expand Down
1 change: 1 addition & 0 deletions app/analytics/tests/test_plausible_urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test Plausible API's integration to associate views per page"""

from app.analytics.plausible import enrich_url_with_post_data, fetch_top_visited_pages


Expand Down
3 changes: 2 additions & 1 deletion app/authors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Author management."""

from fastapi import APIRouter, HTTPException
from fastapi.responses import JSONResponse

Expand Down Expand Up @@ -55,7 +56,7 @@ async def author_post_created(post_update: PostUpdate) -> JSONResponse:
msg = f"{author_name} just created a post: `{title}`."
sms.send_message(msg)
return JSONResponse(content=msg, status_code=200)
elif primary_author_id == settings.GHOST_ADMIN_USER_ID and len(authors) > 1:
if primary_author_id == settings.GHOST_ADMIN_USER_ID and len(authors) > 1:
msg = f"{author_name} just updated one of your posts: `{title}`."
sms.send_message(msg)
return JSONResponse(content=msg, status_code=200)
Expand Down
1 change: 1 addition & 0 deletions app/donations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Accept and persist `BuyMeACoffee` donations."""

from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session

Expand Down
1 change: 1 addition & 0 deletions app/donations/parse.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Parse Donation into JSON response."""

from database.models import Donation


Expand Down
1 change: 1 addition & 0 deletions app/github/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Notify upon Github activity."""

from fastapi import APIRouter, Request
from fastapi.responses import JSONResponse

Expand Down
1 change: 1 addition & 0 deletions app/images/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Generate optimized images to be served from Google Cloud CDN."""

from typing import Optional

from fastapi import APIRouter, Query
Expand Down
1 change: 1 addition & 0 deletions app/moment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Calculate situational time or dates."""

from datetime import datetime, timedelta

import pytz
Expand Down
1 change: 1 addition & 0 deletions app/newsletter/mixpanel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Mixpanel user analytics."""

from typing import Optional

from mixpanel import Mixpanel, MixpanelException
Expand Down
1 change: 1 addition & 0 deletions app/newsletter/newsletter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Welcome newsletter subscribers ."""

from typing import Optional

from clients import mailgun
Expand Down
1 change: 1 addition & 0 deletions app/posts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Enrich post metadata."""

from datetime import datetime, timedelta
from time import sleep

Expand Down
1 change: 1 addition & 0 deletions app/posts/metadata.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Execute SQL to ensure posts have properly optimized metadata."""

from typing import Tuple

from app.posts.update import bulk_update_post_metadata
Expand Down
1 change: 1 addition & 0 deletions app/posts/test_posts/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Set up integration tests for Ghost post modifications directly via SQL."""

import pytest

from config import settings
Expand Down
1 change: 1 addition & 0 deletions app/posts/test_posts/test_read.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test reading data directly form SQL databases."""

from database.read_sql import collect_sql_queries, fetch_sql_files, parse_sql_batch
from database.sql_db import Database
from log import LOGGER
Expand Down
1 change: 1 addition & 0 deletions app/posts/update.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Methods for updating Ghost post content or metadata."""

from typing import List, Optional, Tuple

from fastapi import HTTPException
Expand Down
1 change: 1 addition & 0 deletions app/tags/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Enrich tag metadata."""

from fastapi import APIRouter
from fastapi.responses import JSONResponse

Expand Down
1 change: 1 addition & 0 deletions asgi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Application entry point."""

from app import create_app

api = create_app()
1 change: 1 addition & 0 deletions clients/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Initialize clients and third-party SDKs."""

from github import Github
from google.cloud import bigquery

Expand Down
1 change: 1 addition & 0 deletions clients/gcs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Google Cloud Storage client and image transformer."""

import re
from typing import Iterator, Tuple

Expand Down
1 change: 1 addition & 0 deletions clients/ghost.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Ghost admin client."""

from datetime import datetime as date
from typing import List, Optional, Tuple

Expand Down
1 change: 1 addition & 0 deletions clients/img.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Image transformer for remote images on GCS."""

from io import BytesIO
from typing import List, Optional

Expand Down
1 change: 1 addition & 0 deletions clients/mail.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Create Mailgun client."""

from typing import List

import requests
Expand Down
1 change: 1 addition & 0 deletions clients/sms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Create Twilio SMS client."""

from twilio.rest import Client
from twilio.rest.api.v2010.account.message import MessageInstance

Expand Down
1 change: 1 addition & 0 deletions clients/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Pytest fixtures for clients."""

import pytest
from google.cloud.bigquery import Client as gbqClient

Expand Down
1 change: 1 addition & 0 deletions clients/tests/test_bigquery.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test BigQuery client."""

from google.cloud import bigquery
from google.cloud.bigquery.table import RowIterator

Expand Down
1 change: 1 addition & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""FastAPI configuration."""

import datetime
from os import getenv, path

Expand Down
1 change: 1 addition & 0 deletions database/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Initialize custom Database clients for direct read/write access."""

from config import Settings

from .sql_db import Database
Expand Down
1 change: 1 addition & 0 deletions database/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Data models."""

from sqlalchemy import Column, DateTime, Integer, String, Text
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.sql import func
Expand Down
1 change: 1 addition & 0 deletions database/orm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Initialize database session."""

from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
Expand Down
1 change: 1 addition & 0 deletions database/read_sql.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Read analytics from local SQL files."""

from os import listdir
from os.path import isfile, join
from typing import List, Optional
Expand Down
Loading

0 comments on commit 38d975b

Please sign in to comment.