mirror of
https://github.com/ShayManor/github-readme-stats.git
synced 2026-12-02 11:53:48 +05:30
db: add github_id and github_avatar_url columns + set_github_profile
This commit is contained in:
+16
-1
@@ -27,7 +27,9 @@ CREATE TABLE IF NOT EXISTS users (
|
|||||||
last_fetcher_payload_hash TEXT,
|
last_fetcher_payload_hash TEXT,
|
||||||
manual_refresh_used INTEGER DEFAULT 0,
|
manual_refresh_used INTEGER DEFAULT 0,
|
||||||
last_requested_at TEXT NOT NULL,
|
last_requested_at TEXT NOT NULL,
|
||||||
edit_token_hash TEXT
|
edit_token_hash TEXT,
|
||||||
|
github_id INTEGER,
|
||||||
|
github_avatar_url TEXT
|
||||||
);
|
);
|
||||||
CREATE TABLE IF NOT EXISTS enrollments_daily (
|
CREATE TABLE IF NOT EXISTS enrollments_daily (
|
||||||
day TEXT PRIMARY KEY,
|
day TEXT PRIMARY KEY,
|
||||||
@@ -116,6 +118,10 @@ def init_dbs() -> None:
|
|||||||
cols = {r["name"] for r in c.execute("PRAGMA table_info(users)").fetchall()}
|
cols = {r["name"] for r in c.execute("PRAGMA table_info(users)").fetchall()}
|
||||||
if "edit_token_hash" not in cols:
|
if "edit_token_hash" not in cols:
|
||||||
c.execute("ALTER TABLE users ADD COLUMN edit_token_hash TEXT")
|
c.execute("ALTER TABLE users ADD COLUMN edit_token_hash TEXT")
|
||||||
|
if "github_id" not in cols:
|
||||||
|
c.execute("ALTER TABLE users ADD COLUMN github_id INTEGER")
|
||||||
|
if "github_avatar_url" not in cols:
|
||||||
|
c.execute("ALTER TABLE users ADD COLUMN github_avatar_url TEXT")
|
||||||
c.commit()
|
c.commit()
|
||||||
with _widgets_conn() as c:
|
with _widgets_conn() as c:
|
||||||
c.executescript(_WIDGETS_SCHEMA)
|
c.executescript(_WIDGETS_SCHEMA)
|
||||||
@@ -264,6 +270,15 @@ def set_last_fetcher_hash(username: str, h: str) -> None:
|
|||||||
c.commit()
|
c.commit()
|
||||||
|
|
||||||
|
|
||||||
|
def set_github_profile(username: str, github_id: int, github_avatar_url: str) -> None:
|
||||||
|
with _settings_conn() as c:
|
||||||
|
c.execute(
|
||||||
|
"UPDATE users SET github_id=?, github_avatar_url=? WHERE username=?",
|
||||||
|
(github_id, github_avatar_url, username),
|
||||||
|
)
|
||||||
|
c.commit()
|
||||||
|
|
||||||
|
|
||||||
# ---- jobs ----
|
# ---- jobs ----
|
||||||
|
|
||||||
def enqueue_build(username: str) -> int:
|
def enqueue_build(username: str) -> int:
|
||||||
|
|||||||
@@ -100,3 +100,12 @@ def test_reclaim_stuck_running_jobs(tmp_dbs):
|
|||||||
dbmod.reclaim_stuck_jobs(older_than_minutes=10)
|
dbmod.reclaim_stuck_jobs(older_than_minutes=10)
|
||||||
job = dbmod.claim_next_job()
|
job = dbmod.claim_next_job()
|
||||||
assert job["id"] == jid
|
assert job["id"] == jid
|
||||||
|
|
||||||
|
|
||||||
|
def test_set_github_profile_round_trip(tmp_dbs):
|
||||||
|
dbmod.enroll("alice", {"theme": "dark"})
|
||||||
|
dbmod.set_github_profile("alice", github_id=42, github_avatar_url="https://example.com/a.png")
|
||||||
|
with dbmod._settings_conn() as c:
|
||||||
|
row = c.execute("SELECT github_id, github_avatar_url FROM users WHERE username='alice'").fetchone()
|
||||||
|
assert row["github_id"] == 42
|
||||||
|
assert row["github_avatar_url"] == "https://example.com/a.png"
|
||||||
|
|||||||
Reference in New Issue
Block a user