Skip to content

Commit b4e4b88

Browse files
committed
Support full issues resync from cutoff date
1 parent a140a2e commit b4e4b88

3 files changed

Lines changed: 30 additions & 8 deletions

File tree

.github/workflows/download_issues.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ name: Sync issues
22

33
on:
44
workflow_dispatch:
5+
inputs:
6+
since:
7+
description: Cutoff date
8+
required: false
9+
default: detect
510
schedule:
611
- cron: 20 */4 * * *
712

@@ -27,6 +32,7 @@ jobs:
2732

2833
- name: Fetch issues
2934
run: |
30-
uv run fetch
35+
uv run fetch --since "$CHECK_SINCE"
3136
env:
3237
GH_ACCESS_TOKEN: ${{ secrets.CUSTOM_GITHUB_PAT }}
38+
CHECK_SINCE: ${{ inputs.since || 'detect' }}

src/mypy_issues/__init__.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import logging
66
import os
77
import sys
8+
from datetime import datetime
89

910
from .apply import (
1011
LOG as APPLY_LOGGER,
@@ -27,7 +28,7 @@ def fetch_issues() -> None:
2728
token = _get_gh_token()
2829

2930
ISSUES_LOGGER.setLevel(logging.DEBUG if args.verbose else logging.INFO)
30-
asyncio.run(download_snippets(token, limit=args.limit))
31+
asyncio.run(download_snippets(token, limit=args.limit, since=args.since))
3132

3233

3334
def run_mypy() -> None:
@@ -69,6 +70,14 @@ def run_diff() -> None:
6970

7071

7172
def _make_fetch_parser() -> argparse.ArgumentParser:
73+
def parse_datetime_or_detect(val: str) -> datetime | None:
74+
if val == "detect":
75+
return None
76+
try:
77+
return datetime.fromisoformat(val)
78+
except ValueError:
79+
parser.error(f"Invalid datetime value: {val!r}")
80+
7281
parser = argparse.ArgumentParser()
7382
parser.add_argument(
7483
"-v", "--verbose", action="store_true", dest="verbose", help="Print more output"
@@ -79,6 +88,12 @@ def _make_fetch_parser() -> argparse.ArgumentParser:
7988
default=None,
8089
help="Max amount of valid snippets to generate",
8190
)
91+
parser.add_argument(
92+
"--since",
93+
type=parse_datetime_or_detect,
94+
default=None,
95+
help="Force synchronization after this cutoff date, YYYY-MM-DD, or 'detect' to only update since last fetch.",
96+
)
8297
return parser
8398

8499

src/mypy_issues/issues.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@
4444
T_co = TypeVar("T_co", covariant=True)
4545

4646

47-
async def download_snippets(
47+
async def download_snippets( # noqa: C901
4848
token: str,
4949
*,
5050
limit: int | None = None,
5151
org: str = "python",
5252
repo: str = "mypy",
53+
since: datetime | None = None,
5354
) -> None:
5455
SNIPPETS_ROOT.mkdir(exist_ok=True)
5556

@@ -59,15 +60,15 @@ async def download_snippets(
5960
inventory: list[InventoryItem] = []
6061
issues: dict[int, IssueWithComments] = {}
6162
seen: set[str] = set()
62-
since = None
6363
removed_count = 0
6464
if INVENTORY_FILE.is_file() and ISSUES_FILE.is_file():
6565
inventory = load_inventory()
6666
issues = load_issues()
67-
since = max(
68-
(iss.issue.created_at for iss in issues.values()),
69-
default=datetime.fromtimestamp(0, tz=UTC),
70-
)
67+
if since is None:
68+
since = max(
69+
(iss.issue.created_at for iss in issues.values()),
70+
default=datetime.fromtimestamp(0, tz=UTC),
71+
)
7172
removed = {iss.number async for iss in _get_closed_issues(gh, org, repo, since)}
7273
removed_count = sum(n in issues for n in removed)
7374
comments = await _get_comments(gh, org, repo, since)

0 commit comments

Comments
 (0)