zithub 0.2.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {zithub-0.2.0 → zithub-0.3.0}/PKG-INFO +21 -3
- {zithub-0.2.0 → zithub-0.3.0}/README.md +20 -2
- {zithub-0.2.0 → zithub-0.3.0}/pyproject.toml +1 -1
- {zithub-0.2.0 → zithub-0.3.0}/pyproject.toml.orig +1 -1
- zithub-0.3.0/src/zithub/board.py +241 -0
- {zithub-0.2.0 → zithub-0.3.0}/src/zithub/cli.py +525 -9
- {zithub-0.2.0 → zithub-0.3.0}/src/zithub/gh.py +345 -16
- zithub-0.3.0/src/zithub/plan.py +168 -0
- {zithub-0.2.0 → zithub-0.3.0}/src/zithub/skills/zithub/SKILL.md +45 -6
- {zithub-0.2.0 → zithub-0.3.0}/src/zithub/__init__.py +0 -0
- {zithub-0.2.0 → zithub-0.3.0}/src/zithub/registry.py +0 -0
- {zithub-0.2.0 → zithub-0.3.0}/src/zithub/skills.py +0 -0
- {zithub-0.2.0 → zithub-0.3.0}/src/zithub/ticket.py +0 -0
- {zithub-0.2.0 → zithub-0.3.0}/src/zithub/versioning.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: zithub
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: What's up with this repo, right now, plus batched gh PR/release actions: status, CI, merge preflight, review-thread reply/resolve, and more
|
|
5
5
|
Keywords: git,github,cli,pull-request,ci,gh
|
|
6
6
|
Author: Ville Vainio
|
|
@@ -46,20 +46,38 @@ authenticated (`gh auth login`).
|
|
|
46
46
|
## Commands
|
|
47
47
|
|
|
48
48
|
```
|
|
49
|
-
zh #
|
|
49
|
+
zh # prints help (bare zh does nothing)
|
|
50
|
+
zh status # repo, branch, local, PR, and CI status in one shot
|
|
50
51
|
# (also recent branches/worktrees on the default branch)
|
|
51
52
|
zh ci # just the CI status for the current branch/PR
|
|
52
53
|
zh pr # current branch's PR: status, checks, and review comment
|
|
53
54
|
# threads (unresolved by default; --all also shows resolved)
|
|
54
|
-
zh my # your open PRs
|
|
55
|
+
zh my # your open PRs across all repos, plus recent closed/merged
|
|
56
|
+
zh my --this # ...just for the current repo
|
|
57
|
+
zh stats # most active repos by recent PR+issue activity (--owner, --days, --limit)
|
|
55
58
|
zh review # PRs awaiting your review, updated in the last 7 days
|
|
56
59
|
zh issues # your open issues in this repo, or recent activity outside one
|
|
60
|
+
zh gh <args...> # gh <args...> as this repo owner's gh account (GH_TOKEN; no global switch)
|
|
61
|
+
zh git <args...> # git <args...>; over https, as this repo owner's gh account (same)
|
|
62
|
+
|
|
63
|
+
zh board sync # fetch your open PRs + activity (CI, review, comments) into a local sqlite db
|
|
64
|
+
# (incremental: only new/updated PRs or unsettled CI; --full refetches all)
|
|
65
|
+
zh board # list synced PRs per repo (biggest first), oldest activity first (--stale-days N)
|
|
66
|
+
zh board focus # grouped: fix CI, needs your reply, ready to merge, waiting on others
|
|
67
|
+
# (each grouped per repo; bot comments never count as "needs your reply")
|
|
68
|
+
zh board bots [add|rm X] # extra logins treated as bots on this host, e.g. a CI service account
|
|
69
|
+
zh board query "<SQL>" # ad hoc read-only SQL against the synced db
|
|
70
|
+
# (one board per GitHub site: $GH_HOST, else origin's host, else github.com)
|
|
57
71
|
|
|
58
72
|
zh pr threads # list review-comment threads (with the ids below)
|
|
59
73
|
zh pr reply # reply to a review-comment thread, optionally --resolve
|
|
60
74
|
zh pr resolve # mark thread(s) resolved, by id or --all
|
|
61
75
|
zh pr unresolve # reopen thread(s)
|
|
62
76
|
|
|
77
|
+
zh plan # draft reply/resolve/merge actions into ONE reviewable file
|
|
78
|
+
# (context as comments, all actions commented out): zh plan > plan.md
|
|
79
|
+
zh plan --apply plan.md [--dry-run] # validate everything, then run it in order
|
|
80
|
+
|
|
63
81
|
zh pr check # target branch, and whether the PR references a ticket
|
|
64
82
|
|
|
65
83
|
zh pr merge # merge a PR
|
|
@@ -21,20 +21,38 @@ authenticated (`gh auth login`).
|
|
|
21
21
|
## Commands
|
|
22
22
|
|
|
23
23
|
```
|
|
24
|
-
zh #
|
|
24
|
+
zh # prints help (bare zh does nothing)
|
|
25
|
+
zh status # repo, branch, local, PR, and CI status in one shot
|
|
25
26
|
# (also recent branches/worktrees on the default branch)
|
|
26
27
|
zh ci # just the CI status for the current branch/PR
|
|
27
28
|
zh pr # current branch's PR: status, checks, and review comment
|
|
28
29
|
# threads (unresolved by default; --all also shows resolved)
|
|
29
|
-
zh my # your open PRs
|
|
30
|
+
zh my # your open PRs across all repos, plus recent closed/merged
|
|
31
|
+
zh my --this # ...just for the current repo
|
|
32
|
+
zh stats # most active repos by recent PR+issue activity (--owner, --days, --limit)
|
|
30
33
|
zh review # PRs awaiting your review, updated in the last 7 days
|
|
31
34
|
zh issues # your open issues in this repo, or recent activity outside one
|
|
35
|
+
zh gh <args...> # gh <args...> as this repo owner's gh account (GH_TOKEN; no global switch)
|
|
36
|
+
zh git <args...> # git <args...>; over https, as this repo owner's gh account (same)
|
|
37
|
+
|
|
38
|
+
zh board sync # fetch your open PRs + activity (CI, review, comments) into a local sqlite db
|
|
39
|
+
# (incremental: only new/updated PRs or unsettled CI; --full refetches all)
|
|
40
|
+
zh board # list synced PRs per repo (biggest first), oldest activity first (--stale-days N)
|
|
41
|
+
zh board focus # grouped: fix CI, needs your reply, ready to merge, waiting on others
|
|
42
|
+
# (each grouped per repo; bot comments never count as "needs your reply")
|
|
43
|
+
zh board bots [add|rm X] # extra logins treated as bots on this host, e.g. a CI service account
|
|
44
|
+
zh board query "<SQL>" # ad hoc read-only SQL against the synced db
|
|
45
|
+
# (one board per GitHub site: $GH_HOST, else origin's host, else github.com)
|
|
32
46
|
|
|
33
47
|
zh pr threads # list review-comment threads (with the ids below)
|
|
34
48
|
zh pr reply # reply to a review-comment thread, optionally --resolve
|
|
35
49
|
zh pr resolve # mark thread(s) resolved, by id or --all
|
|
36
50
|
zh pr unresolve # reopen thread(s)
|
|
37
51
|
|
|
52
|
+
zh plan # draft reply/resolve/merge actions into ONE reviewable file
|
|
53
|
+
# (context as comments, all actions commented out): zh plan > plan.md
|
|
54
|
+
zh plan --apply plan.md [--dry-run] # validate everything, then run it in order
|
|
55
|
+
|
|
38
56
|
zh pr check # target branch, and whether the PR references a ticket
|
|
39
57
|
|
|
40
58
|
zh pr merge # merge a PR
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"""Local sqlite cache of your open PRs, synced from GitHub by `zh board
|
|
2
|
+
sync` and read by `zh board` / `zh board query`.
|
|
3
|
+
|
|
4
|
+
A cache rather than a live view: `gh` round trips (one `gh pr view` per
|
|
5
|
+
open PR) are too slow to do on every `zh board` invocation, so sync is a
|
|
6
|
+
separate, explicit step, and stagnation ("no activity in N days") is
|
|
7
|
+
computed against whatever was last synced, not against live data.
|
|
8
|
+
|
|
9
|
+
Kept as an actual sqlite file (not zithub's usual JSONL registry format)
|
|
10
|
+
specifically so it can be queried directly — `zh board query "<SQL>"`,
|
|
11
|
+
or any other sqlite client pointed at the file — rather than only through
|
|
12
|
+
whatever views this module thinks to expose.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import os
|
|
18
|
+
import sqlite3
|
|
19
|
+
from dataclasses import dataclass
|
|
20
|
+
|
|
21
|
+
from . import gh
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class BoardError(Exception):
|
|
25
|
+
"""Raised for bad input to this module (e.g. a non-SELECT query)."""
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _data_dir() -> str:
|
|
29
|
+
base = os.environ.get("XDG_DATA_HOME") or os.path.expanduser("~/.local/share")
|
|
30
|
+
return os.path.join(base, "zithub")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def db_path(host: str) -> str:
|
|
34
|
+
"""One db per GitHub site (github.com, a GHES host, ...), since "your
|
|
35
|
+
open PRs" — and which login is "you" — differ per site."""
|
|
36
|
+
return os.path.join(_data_dir(), "boards", f"{host}.sqlite")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
_SCHEMA = """
|
|
40
|
+
CREATE TABLE IF NOT EXISTS prs (
|
|
41
|
+
repo TEXT NOT NULL,
|
|
42
|
+
number INTEGER NOT NULL,
|
|
43
|
+
title TEXT NOT NULL,
|
|
44
|
+
url TEXT NOT NULL,
|
|
45
|
+
is_draft INTEGER NOT NULL,
|
|
46
|
+
review_decision TEXT NOT NULL,
|
|
47
|
+
ci_state TEXT NOT NULL,
|
|
48
|
+
created_at TEXT NOT NULL,
|
|
49
|
+
updated_at TEXT NOT NULL,
|
|
50
|
+
comment_count INTEGER NOT NULL,
|
|
51
|
+
last_comment_at TEXT,
|
|
52
|
+
last_comment_author TEXT,
|
|
53
|
+
last_activity_at TEXT NOT NULL,
|
|
54
|
+
synced_at TEXT NOT NULL,
|
|
55
|
+
PRIMARY KEY (repo, number)
|
|
56
|
+
);
|
|
57
|
+
CREATE TABLE IF NOT EXISTS meta (
|
|
58
|
+
key TEXT PRIMARY KEY,
|
|
59
|
+
value TEXT NOT NULL
|
|
60
|
+
);
|
|
61
|
+
CREATE TABLE IF NOT EXISTS bots (
|
|
62
|
+
login TEXT PRIMARY KEY
|
|
63
|
+
);
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
# Bump when what a synced row *means* changes (not just its columns), so
|
|
68
|
+
# rows cached under the old meaning get dropped and refetched by the next
|
|
69
|
+
# (otherwise incremental) sync. 1: last_comment_* skip bot comments and
|
|
70
|
+
# titles are HTML-unescaped.
|
|
71
|
+
_CACHE_VERSION = 1
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _connect(host: str) -> sqlite3.Connection:
|
|
75
|
+
path = db_path(host)
|
|
76
|
+
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
77
|
+
conn = sqlite3.connect(path)
|
|
78
|
+
conn.row_factory = sqlite3.Row
|
|
79
|
+
conn.executescript(_SCHEMA)
|
|
80
|
+
if conn.execute("PRAGMA user_version").fetchone()[0] < _CACHE_VERSION:
|
|
81
|
+
with conn:
|
|
82
|
+
conn.execute("DELETE FROM prs")
|
|
83
|
+
conn.execute(f"PRAGMA user_version = {_CACHE_VERSION}")
|
|
84
|
+
return conn
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def sync(
|
|
88
|
+
host: str, prs: list[gh.BoardPr], synced_at: str, login: str | None = None
|
|
89
|
+
) -> None:
|
|
90
|
+
"""Replace the table's contents with exactly `prs` — the scope is
|
|
91
|
+
"your currently-open PRs", so a PR merged/closed since the last sync
|
|
92
|
+
should simply disappear rather than linger as a stale row."""
|
|
93
|
+
prune(host, {(p.repo, p.number) for p in prs})
|
|
94
|
+
upsert(host, prs, synced_at)
|
|
95
|
+
if login:
|
|
96
|
+
set_login(host, login)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def cached_versions(host: str) -> dict[tuple[str, int], tuple[str, str]]:
|
|
100
|
+
"""(repo, number) -> (updated_at, ci_state) for every cached PR — what
|
|
101
|
+
`zh board sync` compares against to skip PRs that haven't changed."""
|
|
102
|
+
with _connect(host) as conn:
|
|
103
|
+
return {
|
|
104
|
+
(r["repo"], r["number"]): (r["updated_at"], r["ci_state"])
|
|
105
|
+
for r in conn.execute("SELECT repo, number, updated_at, ci_state FROM prs")
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def prune(host: str, keep: set[tuple[str, int]]) -> None:
|
|
110
|
+
"""Drop every cached PR not in `keep` (i.e. merged/closed since the
|
|
111
|
+
last sync)."""
|
|
112
|
+
with _connect(host) as conn:
|
|
113
|
+
stale = [
|
|
114
|
+
(r["repo"], r["number"])
|
|
115
|
+
for r in conn.execute("SELECT repo, number FROM prs")
|
|
116
|
+
if (r["repo"], r["number"]) not in keep
|
|
117
|
+
]
|
|
118
|
+
conn.executemany("DELETE FROM prs WHERE repo = ? AND number = ?", stale)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def upsert(host: str, prs: list[gh.BoardPr], synced_at: str) -> None:
|
|
122
|
+
"""Insert or refresh `prs` — committed per call, so a sync that fails
|
|
123
|
+
partway keeps every batch it already fetched."""
|
|
124
|
+
rows = [
|
|
125
|
+
(
|
|
126
|
+
p.repo,
|
|
127
|
+
p.number,
|
|
128
|
+
p.title,
|
|
129
|
+
p.url,
|
|
130
|
+
int(p.is_draft),
|
|
131
|
+
p.review_decision,
|
|
132
|
+
p.ci_state,
|
|
133
|
+
p.created_at,
|
|
134
|
+
p.updated_at,
|
|
135
|
+
p.comment_count,
|
|
136
|
+
p.last_comment_at,
|
|
137
|
+
p.last_comment_author,
|
|
138
|
+
max(p.updated_at, p.last_comment_at or ""),
|
|
139
|
+
synced_at,
|
|
140
|
+
)
|
|
141
|
+
for p in prs
|
|
142
|
+
]
|
|
143
|
+
with _connect(host) as conn:
|
|
144
|
+
conn.executemany("INSERT OR REPLACE INTO prs VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)", rows)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def set_login(host: str, login: str) -> None:
|
|
148
|
+
"""Stash your active gh login so `zh board focus` can tell "you last
|
|
149
|
+
commented" from "someone else did" without its own gh call."""
|
|
150
|
+
with _connect(host) as conn:
|
|
151
|
+
conn.execute(
|
|
152
|
+
"INSERT INTO meta VALUES ('login', ?) ON CONFLICT(key) DO UPDATE SET value=excluded.value",
|
|
153
|
+
(login,),
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def get_login(host: str) -> str | None:
|
|
158
|
+
with _connect(host) as conn:
|
|
159
|
+
row = conn.execute("SELECT value FROM meta WHERE key = 'login'").fetchone()
|
|
160
|
+
return row["value"] if row else None
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def bot_logins(host: str) -> set[str]:
|
|
164
|
+
"""Logins (lowercase) `zh board sync` treats as bots on this host, on
|
|
165
|
+
top of gh's built-in list — org machine users like a CI account."""
|
|
166
|
+
with _connect(host) as conn:
|
|
167
|
+
return {r["login"] for r in conn.execute("SELECT login FROM bots")}
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def add_bots(host: str, logins: list[str]) -> None:
|
|
171
|
+
with _connect(host) as conn:
|
|
172
|
+
conn.executemany("INSERT OR IGNORE INTO bots VALUES (?)", [(login.lower(),) for login in logins])
|
|
173
|
+
_mark_all_for_refetch(conn)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def remove_bots(host: str, logins: list[str]) -> None:
|
|
177
|
+
with _connect(host) as conn:
|
|
178
|
+
conn.executemany("DELETE FROM bots WHERE login = ?", [(login.lower(),) for login in logins])
|
|
179
|
+
_mark_all_for_refetch(conn)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def _mark_all_for_refetch(conn: sqlite3.Connection) -> None:
|
|
183
|
+
"""Each row's last-comment fields were picked with the old bot list, so
|
|
184
|
+
blank the updated_at that cached_versions() hands to sync — every row
|
|
185
|
+
then looks changed and gets refetched, while still showing meanwhile."""
|
|
186
|
+
conn.execute("UPDATE prs SET updated_at = ''")
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
@dataclass
|
|
190
|
+
class BoardRow:
|
|
191
|
+
repo: str
|
|
192
|
+
number: int
|
|
193
|
+
title: str
|
|
194
|
+
url: str
|
|
195
|
+
is_draft: bool
|
|
196
|
+
review_decision: str
|
|
197
|
+
ci_state: str
|
|
198
|
+
last_activity_at: str
|
|
199
|
+
comment_count: int
|
|
200
|
+
last_comment_author: str | None
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def list_board(host: str) -> list[BoardRow]:
|
|
204
|
+
"""Every synced PR, oldest activity first — so a stagnated PR sorts to
|
|
205
|
+
the top without needing a separate "stale" query."""
|
|
206
|
+
with _connect(host) as conn:
|
|
207
|
+
cur = conn.execute(
|
|
208
|
+
"SELECT repo, number, title, url, is_draft, review_decision, ci_state, "
|
|
209
|
+
"last_activity_at, comment_count, last_comment_author "
|
|
210
|
+
"FROM prs ORDER BY last_activity_at ASC"
|
|
211
|
+
)
|
|
212
|
+
return [
|
|
213
|
+
BoardRow(
|
|
214
|
+
repo=r["repo"],
|
|
215
|
+
number=r["number"],
|
|
216
|
+
title=r["title"],
|
|
217
|
+
url=r["url"],
|
|
218
|
+
is_draft=bool(r["is_draft"]),
|
|
219
|
+
review_decision=r["review_decision"],
|
|
220
|
+
ci_state=r["ci_state"],
|
|
221
|
+
last_activity_at=r["last_activity_at"],
|
|
222
|
+
comment_count=r["comment_count"],
|
|
223
|
+
last_comment_author=r["last_comment_author"],
|
|
224
|
+
)
|
|
225
|
+
for r in cur.fetchall()
|
|
226
|
+
]
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def run_query(host: str, sql: str) -> tuple[list[str], list[tuple]]:
|
|
230
|
+
"""Runs a read-only `SELECT`/`WITH` query against the board db and
|
|
231
|
+
returns (column names, rows). Anything else (INSERT/UPDATE/DELETE/etc,
|
|
232
|
+
including via a stacked statement) is rejected — this is meant for ad
|
|
233
|
+
hoc lookups against the synced snapshot, not for editing it."""
|
|
234
|
+
stripped = sql.strip()
|
|
235
|
+
if not stripped or not stripped.lstrip().upper().startswith(("SELECT", "WITH")):
|
|
236
|
+
raise BoardError("only SELECT/WITH queries are allowed")
|
|
237
|
+
with _connect(host) as conn:
|
|
238
|
+
conn.execute("PRAGMA query_only = ON")
|
|
239
|
+
cur = conn.execute(stripped)
|
|
240
|
+
columns = [d[0] for d in cur.description] if cur.description else []
|
|
241
|
+
return columns, cur.fetchall()
|