Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
52a965a
Add read-only leaderboard support with URL handling and view key vali…
cak Dec 3, 2026
def8e2e
Enhance leaderboard functionality: support fetching via URL and impro…
cak Dec 3, 2026
40c672f
Refactor CI workflow for documentation release and add versioning script
cak Dec 3, 2026
63e1f27
Update CHANGELOG for version 1.2.3: add new features, fixes, and secu…
cak Dec 3, 2026
b5865b5
Add DoctorReport, DoctorCheck, and CheckStatus to leaderboard referen…
cak Dec 3, 2026
0fb3989
Bump version to 1.2.3 in pyproject.toml
cak Dec 3, 2026
c431c23
Add Member, StarCompletion, and SubmissionStatus to public API
cak Dec 3, 2026
2eb7894
Enhance documentation for CheckStatus, DoctorCheck, and DoctorReport …
cak Dec 3, 2026
25066fc
Add docstrings for Guess, CachedGuessCheck, UnlockStatus, and OpenKin…
cak Dec 3, 2026
07e8b4f
Bump version of elf package to 1.2.3 in uv.lock
cak Dec 3, 2026
357a930
Add docstrings to AocResponseParser methods and AocMessageType class
cak Dec 3, 2026
9f96787
Add docstrings for version_callback and main functions in CLI
cak Dec 3, 2026
82c3a3c
Add SubmissionStatus and OpenKind to reference section in great-docs.yml
cak Dec 3, 2026
ca814b3
Add support for passing leaderboard URL as a positional argument
cak Dec 3, 2026
2339101
Enhance get_private_leaderboard documentation for read-only access an…
cak Dec 3, 2026
86f0aa4
Update README.md to include read-only key and leaderboard URL options
cak Dec 3, 2026
9f2b600
Refactor great-docs.yml to reorganize reference sections and ensure p…
cak Dec 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 36 additions & 65 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,104 +1,75 @@
name: CI Docs
name: Release docs

on:
push:
branches:
- main
pull_request:
workflow_dispatch:
workflow_run:
workflows: [Publish]
types: [completed]

permissions:
contents: read

jobs:
build-docs:
name: "Build Docs"
if: >-
github.event.workflow_run.event == 'release' &&
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_repository.full_name == github.repository
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0 # Full history for accurate page timestamps
ref: ${{ github.event.workflow_run.head_sha }}
fetch-depth: 0
persist-credentials: false

- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
python-version: "3.11"

- name: Install package and dependencies
run: |
python -m pip install uv
uv sync --locked --no-default-groups --group docs

- name: Set up Quarto
uses: quarto-dev/quarto-actions/setup@8a96df13519ee81fd526f2dfca5962811136661b # v2
with:
version: "1.11.9"

- name: Lint docs
run: uv run --locked --no-default-groups --group docs great-docs lint

- name: Build docs
run: uv run --locked --no-default-groups --group docs great-docs build
- name: Lint and build release docs
env:
RELEASE_TAG: ${{ github.event.workflow_run.head_branch }}
run: |
uv sync --locked --no-default-groups --group docs
source .venv/bin/activate
great-docs lint
great-docs build
grep -F 'class="version-badge"' great-docs/_site/index.html | grep -Fq ">$RELEASE_TAG</span>"

- name: Save docs artifact
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5
with:
name: docs-html
path: great-docs/_site
include-hidden-files: true

- name: How to preview this build locally
if: github.event_name == 'pull_request'
run: uv run --locked --no-default-groups --group docs great-docs ci notice --run ${{ github.run_id }} --pr ${{ github.event.number }}

- name: Upload build timings
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: build-timings
path: great-docs/_site/build-timings.json

publish-docs:
name: "Publish Docs"
needs: build-docs
runs-on: ubuntu-latest
needs: "build-docs"
if: github.ref == 'refs/heads/main'
concurrency:
group: release-docs-pages
cancel-in-progress: false
permissions:
contents: read
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7
with:
name: docs-html
path: great-docs/_site

- name: Upload Pages artifact
uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5
with:
path: great-docs/_site
include-hidden-files: true
- name: Identify latest stable release before deployment
id: latest
env:
GH_TOKEN: ${{ github.token }}
run: |
tag=$(gh api "repos/$GITHUB_REPOSITORY/releases/latest" --jq .tag_name)
echo "tag=$tag" >> "$GITHUB_OUTPUT"

- name: Deploy to GitHub Pages
if: steps.latest.outputs.tag == github.event.workflow_run.head_branch
id: deployment
uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5

preview-docs:
name: "Preview Docs"
runs-on: ubuntu-latest
needs: "build-docs"
if: github.event_name == 'pull_request'
permissions:
pull-requests: write
steps:
# Post (and keep updated) a sticky PR comment with the local-preview
# command, pinned to this run so it reproduces the build under review.
# Runs the released great-docs via pipx (no install step needed); kept as
# its own minimal job so the docs build never holds a pull-requests:write
# token. continue-on-error so fork PRs (read-only token) don't fail the run.
- name: Post preview instructions to the PR
continue-on-error: true
run: pipx run --spec great-docs==0.17.0 great-docs ci pr-comment --run ${{ github.run_id }} --pr ${{ github.event.number }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

Notable user-facing changes to elf are documented here.

## 1.2.3 (unreleased)

### Added

- `elf leaderboard --url URL` and `get_private_leaderboard(url=...)` accept official HTML and JSON private leaderboard links. Elf extracts the year, board ID, and optional read-only view key.
- GitHub Actions examples show how to export multiple boards with independent secrets and how to use an existing session cookie.

### Fixed

- The documentation version badge now uses the package version in the checkout. Production documentation builds from the release commit after a successful stable PyPI publication.

### Security

- Leaderboard requests send one credential to the official JSON endpoint. Redirects, malformed share links, and conflicting keys fail without retrying with another credential.
- HTTP diagnostics omit keyed leaderboard URLs. Cached payloads and exports redact credential fields and keys embedded in links. Equivalent URL and numeric requests reuse the existing 15-minute cache for the same event, board, and credential.

## 1.2.2

### Added
Expand Down
46 changes: 38 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,25 +258,40 @@ Time (UTC) Guess Status

### `elf leaderboard`

Fetch private leaderboards. Provide a view key for read-only access or a session cookie for authenticated access. A view key is the read-only share token you can generate on your AoC leaderboard page.
Fetch a private leaderboard by year and board ID, or pass the read-only link from the board owner. Elf extracts the event year, board ID, and view key from either official URL form.

```text
https://adventofcode.com/YEAR/leaderboard/private/view/BOARD_ID?view_key=KEY
https://adventofcode.com/YEAR/leaderboard/private/view/BOARD_ID.json?view_key=KEY
```

```sh
Usage: elf leaderboard YEAR BOARD_ID
elf leaderboard URL
elf leaderboard --url URL

Options:
--view-key TEXT
--session TEXT
--format table|csv|json|model
--view-key TEXT Read-only key for this board
--session, -s AoC session cookie (env: AOC_SESSION)
--format, -f table|csv|json|model
--url TEXT Official HTML or JSON leaderboard URL
```

Supports:

- **table:** pretty Rich table
- **csv:** one summary row per member
- **json:** raw JSON
- **json:** upstream JSON with credential fields and share keys redacted
- **model:** structured Pydantic model

With a view key, elf sends the key alone, even when a session cookie is configured. The upstream API takes the key in the query string, so keep HTTP client request logs private.
Each board can have its own link or key. These commands use shell variables populated by your secret manager.

```sh
elf leaderboard --url "$TEAM_BOARD_URL" --format csv > team.csv
elf leaderboard 2025 654321 --view-key "$CLUB_VIEW_KEY" --format json > club.json
```

A URL key or explicit `--view-key` takes precedence over `--session` and `AOC_SESSION`. Elf sends only the selected credential. An authentication failure ends the request. A URL without a key uses the usual session configuration. Puzzle inputs, submissions, and personal status require a session cookie.

Leaderboard JSON is cached for 15 minutes, matching Advent of Code's minimum request interval. Cache entries are isolated by event, leaderboard ID, and a one-way fingerprint of the session cookie or view key.

Expand Down Expand Up @@ -454,7 +469,7 @@ print(members[0].name, members[0].stars)

### Exporting Leaderboard Data

CSV provides one summary row per member for tabular analysis. JSON preserves the complete Advent of Code response, including individual star completions. The Python model remains available for more advanced processing, and all formats work with any tool that understands standard CSV or JSON.
CSV provides one summary row per member for tabular analysis. JSON preserves upstream fields, including individual star completions. Elf masks session and view-key fields and credential-bearing links before caching or formatting the data.

```sh
elf leaderboard 2025 123456 --format csv > leaderboard.csv
Expand All @@ -469,6 +484,19 @@ csv_data = get_private_leaderboard(2025, board_id=123456, fmt=OutputFormat.CSV)
json_data = get_private_leaderboard(2025, board_id=123456, fmt=OutputFormat.JSON)
```

Python can read each board’s link or key from the environment.

```python
import os

from elf import get_private_leaderboard

team = get_private_leaderboard(url=os.environ["TEAM_BOARD_URL"])
club = get_private_leaderboard(2025, 654321, view_key=os.environ["CLUB_VIEW_KEY"])
```

The [command-line guide](user_guide/command-line.qmd#github-actions) includes a GitHub Actions example for multiple private boards.

### Status Example

```sh
Expand Down Expand Up @@ -551,7 +579,9 @@ Edit the guides in `user_guide/` and the API reference in the public Python docs

### Hosting and releases

The docs workflow deploys to GitHub Pages from `typeerror/elf`. To serve it at `https://typeerror.com/elf/`, configure `typeerror.com` on the account’s Pages site. In the `elf` repository’s Pages settings, select **GitHub Actions** as the source and leave the project-level custom domain blank so the project inherits the account domain. [GitHub Pages custom domains](https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site/about-custom-domains-and-github-pages)
Publishing a stable GitHub release runs the quality checks and publishes the package to PyPI. After PyPI succeeds, the docs workflow builds that same commit and checks the rendered version badge against the release tag. Only the latest stable release deploys to GitHub Pages. Use the local preview above for unreleased changes.

In the repository’s Pages settings, select **GitHub Actions** as the source. The docs workflow runs from the default branch and checks out the publish run’s commit, so the `github-pages` environment can keep its `main` branch restriction. The project inherits `typeerror.com` from the account’s Pages site. [GitHub Pages custom domains](https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site/about-custom-domains-and-github-pages)

The release workflow uses PyPI Trusted Publishing. Configure the `elf` project on PyPI with owner `typeerror`, repository `elf`, workflow `publish.yml`, and environment `pypi`. [PyPI Trusted Publishing setup](https://docs.pypi.org/trusted-publishers/adding-a-publisher/)

Expand Down
7 changes: 7 additions & 0 deletions elf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- get_puzzle_input(year, day, session=None) -> str
- submit_puzzle_answer(year, day, part, answer, session=None) -> SubmissionResult
- get_private_leaderboard(year, board_id, session=None, view_key=None, fmt=OutputFormat.MODEL)
- get_private_leaderboard(url=leaderboard_url, fmt=OutputFormat.MODEL)
- get_user_status(year, session=None, fmt=OutputFormat.MODEL)

The session token can be passed explicitly or via the AOC_SESSION environment variable.
Expand All @@ -24,16 +25,22 @@
from .models import (
DayStatus,
Leaderboard,
Member,
OutputFormat,
StarCompletion,
SubmissionResult,
SubmissionStatus,
YearStatus,
)

__all__ = [
"DayStatus",
"Leaderboard",
"Member",
"OutputFormat",
"StarCompletion",
"SubmissionResult",
"SubmissionStatus",
"YearStatus",
"get_private_leaderboard",
"get_puzzle_input",
Expand Down
7 changes: 7 additions & 0 deletions elf/answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,28 @@ def __init__(self) -> None:
self.content: list[str] = []

def handle_starttag(self, tag: str, attrs: list[tuple[str, str | None]]) -> None:
"""Start collecting text when an article element begins."""
if tag == "article":
self.in_article = True

def handle_endtag(self, tag: str) -> None:
"""Stop collecting text when the article element closes."""
if tag == "article":
self.in_article = False

def handle_data(self, data: str) -> None:
"""Append text from inside the article element."""
if self.in_article:
self.content.append(data)

def text(self) -> str:
"""Return the collected article text."""
return "".join(self.content).strip()


class AocMessageType(Enum):
"""Categories recognized in an Advent of Code answer response."""

EMPTY = auto()
CORRECT = auto()
TOO_HIGH = auto()
Expand All @@ -83,6 +89,7 @@ class AocMessageType(Enum):


def classify_message(content: str) -> AocMessageType:
"""Classify an Advent of Code response message by its meaning."""
if not content:
return AocMessageType.EMPTY

Expand Down
Loading