Skip to content

Commit 33fac1f

Browse files
committed
tools/mpy-triage: Add database layer and GitHub API wrapper.
Implements db.py (SQLite connection, schema init, sync state, sqlite-vec loading) and gh.py (gh CLI wrapper with pagination multiparse, rate-limit backoff, search, and diff fetching). Includes tests for both modules. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
1 parent 8ebcf8e commit 33fac1f

16 files changed

Lines changed: 837 additions & 0 deletions

File tree

tools/mpy-triage/data/schema.sql

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
-- MicroPython Issue Triage Database Schema
2+
3+
-- Issues and PRs
4+
CREATE TABLE IF NOT EXISTS items (
5+
id INTEGER PRIMARY KEY,
6+
number INTEGER NOT NULL,
7+
repo TEXT NOT NULL DEFAULT 'micropython/micropython',
8+
type TEXT NOT NULL, -- 'issue' or 'pr'
9+
title TEXT,
10+
body TEXT,
11+
author TEXT,
12+
state TEXT, -- open, closed
13+
labels TEXT, -- JSON array of label names
14+
created_at TEXT,
15+
closed_at TEXT,
16+
updated_at TEXT,
17+
UNIQUE(repo, number)
18+
);
19+
20+
-- Sync state for incremental updates
21+
CREATE TABLE IF NOT EXISTS sync_state (
22+
key TEXT PRIMARY KEY,
23+
value TEXT
24+
);
25+
26+
-- Indexes
27+
CREATE INDEX IF NOT EXISTS idx_items_repo ON items(repo);
28+
CREATE INDEX IF NOT EXISTS idx_items_type ON items(type);
29+
CREATE INDEX IF NOT EXISTS idx_items_state ON items(state);
30+
CREATE INDEX IF NOT EXISTS idx_items_created ON items(created_at);
31+
CREATE INDEX IF NOT EXISTS idx_items_repo_number ON items(repo, number);

tools/mpy-triage/pyproject.toml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[build-system]
2+
requires = ["setuptools>=61.0", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "mpy-triage"
7+
version = "0.1.0"
8+
description = "CLI tool for detecting duplicate/related MicroPython issues and PRs"
9+
requires-python = ">=3.10"
10+
license = {text = "MIT"}
11+
12+
dependencies = [
13+
"sqlite-vec>=0.1.6",
14+
]
15+
16+
[project.optional-dependencies]
17+
dev = [
18+
"pytest>=7.0.0",
19+
"ruff>=0.4.0",
20+
]
21+
22+
[project.scripts]
23+
mpy-triage = "mpy_triage.cli:main"
24+
25+
[tool.setuptools.packages.find]
26+
where = ["src"]
27+
28+
[tool.ruff]
29+
line-length = 99
30+
31+
[tool.pytest.ini_options]
32+
testpaths = ["tests"]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Metadata-Version: 2.4
2+
Name: mpy-triage
3+
Version: 0.1.0
4+
Summary: CLI tool for detecting duplicate/related MicroPython issues and PRs
5+
License: MIT
6+
Requires-Python: >=3.10
7+
Requires-Dist: sqlite-vec>=0.1.6
8+
Provides-Extra: dev
9+
Requires-Dist: pytest>=7.0.0; extra == "dev"
10+
Requires-Dist: ruff>=0.4.0; extra == "dev"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
pyproject.toml
2+
src/mpy_triage/__init__.py
3+
src/mpy_triage/cli.py
4+
src/mpy_triage/db.py
5+
src/mpy_triage/gh.py
6+
src/mpy_triage.egg-info/PKG-INFO
7+
src/mpy_triage.egg-info/SOURCES.txt
8+
src/mpy_triage.egg-info/dependency_links.txt
9+
src/mpy_triage.egg-info/entry_points.txt
10+
src/mpy_triage.egg-info/requires.txt
11+
src/mpy_triage.egg-info/top_level.txt
12+
tests/test_db.py
13+
tests/test_gh.py
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[console_scripts]
2+
mpy-triage = mpy_triage.cli:main
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sqlite-vec>=0.1.6
2+
3+
[dev]
4+
pytest>=7.0.0
5+
ruff>=0.4.0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mpy_triage

tools/mpy-triage/src/mpy_triage/__init__.py

Whitespace-only changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""CLI entry point for mpy-triage."""
2+
3+
import argparse
4+
import logging
5+
6+
7+
def main() -> None:
8+
"""Main entry point for the mpy-triage CLI."""
9+
parser = argparse.ArgumentParser(
10+
prog="mpy-triage",
11+
description="Detect duplicate and related MicroPython issues/PRs using semantic search.",
12+
)
13+
parser.add_argument("-v", "--verbose", action="store_true", help="Enable verbose logging.")
14+
parser.add_argument(
15+
"--db",
16+
default="data/triage.db",
17+
help="Path to the SQLite database (default: data/triage.db).",
18+
)
19+
20+
_args = parser.parse_args()
21+
22+
logging.basicConfig(
23+
level=logging.DEBUG if _args.verbose else logging.INFO,
24+
format="%(levelname)s: %(message)s",
25+
)
26+
27+
28+
if __name__ == "__main__":
29+
main()

0 commit comments

Comments
 (0)