Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 19 additions & 6 deletions .github/scripts/shadow_mirror/mirror.py

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 No scheduled pickup for pending backfills

If replay returns baseline pending, no mirror PR exists for scheduled discovery to find. Backfills outside the default window then need another manual run.

(Refers to this code)

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Missing issue-closing reference

The PR body lacks the Fixes #… reference required by the PR description rules.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,21 @@ def is_dependency_pr(pr, files):
)


def recently_merged(pr, now=None):
if not pr.get("merged_at"):
def within_lookback(timestamp, now=None):
if not timestamp:
return False
merged = datetime.datetime.fromisoformat(pr["merged_at"].replace("Z", "+00:00"))
moment = datetime.datetime.fromisoformat(timestamp.replace("Z", "+00:00"))
now = now or datetime.datetime.now(datetime.timezone.utc)
return now - merged <= datetime.timedelta(days=LOOKBACK_DAYS)
return now - moment <= datetime.timedelta(days=LOOKBACK_DAYS)


def recently_merged(pr, now=None, history=None):
if not pr.get("merged_at"):
return False
return within_lookback(pr["merged_at"], now) or any(
mirror["state"] == "open" and within_lookback(mirror.get("created_at"), now)
for mirror in (history or {}).values()
)


def scrub_title(title):
Expand Down Expand Up @@ -208,14 +217,15 @@ def sync(self, number):
path = f"pulls/{number}"
try:
pr = api.call(SOURCE, path)
if pr["state"] == "open" or recently_merged(pr):
live = pr["state"] == "open" or recently_merged(pr, history=history)
if live:
files = list(api.pages(SOURCE, f"{path}/files"))
current = api.call(SOURCE, path)
except APIError as error:
if error.status != 404:
raise
return {"status": "skipped", "reason": "upstream PR not found"}
if pr["state"] != "open" and not recently_merged(pr):
if not live:
return self.close(history, "source closed")
if any(current[key] != pr[key] for key in ("state", "changed_files")) or any(
current[key]["sha"] != pr[key]["sha"] for key in ("base", "head")
Expand Down Expand Up @@ -409,11 +419,14 @@ def commit(self, tree, parents, message):
)["sha"]

def main():
global LOOKBACK_DAYS
parser = argparse.ArgumentParser()
sync = parser.add_subparsers(dest="command", required=True).add_parser("sync")
sync.add_argument("--pr", type=int, action="append")
sync.add_argument("--dry-run", action="store_true")
sync.add_argument("--lookback-days", type=int, default=LOOKBACK_DAYS)
args = parser.parse_args()
LOOKBACK_DAYS = args.lookback_days
token = os.environ.get("SHADOW_MIRROR_TOKEN") or os.environ.get("GH_TOKEN")
if not token:
parser.error("Set SHADOW_MIRROR_TOKEN or GH_TOKEN")
Expand Down
11 changes: 11 additions & 0 deletions .github/scripts/shadow_mirror/test_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ def test_recently_merged_uses_lookback(self):
self.assertFalse(recently_merged({"merged_at": "2026-11-16T00:00:00Z"}, now))
self.assertFalse(recently_merged({"merged_at": None}, now))

def test_open_backfilled_mirror_stays_in_window(self):
now = datetime.datetime(2026, 11, 27, tzinfo=datetime.timezone.utc)
pr = {"merged_at": "2026-10-16T00:00:00Z"}
fresh = {1: {"state": "open", "created_at": "2026-11-26T00:00:00Z"}}
stale = {1: {"state": "open", "created_at": "2026-11-10T00:00:00Z"}}
closed = {1: {"state": "closed", "created_at": "2026-11-26T00:00:00Z"}}
self.assertTrue(recently_merged(pr, now, fresh))
self.assertFalse(recently_merged(pr, now, stale))
self.assertFalse(recently_merged(pr, now, closed))
self.assertFalse(recently_merged({"merged_at": None}, now, fresh))
Comment on lines +76 to +85

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Custom lookback lacks test coverage

The new test uses the ten-day default. It does not exercise --lookback-days through both discovery and eligibility.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.


def test_candidates_cover_open_and_recently_merged_bot_changes(self):
api = API("unused", True)

Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/garnet-shadow-mirror.yml

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Testing checklist in PR description

The test and actionlint checkbox conflicts with the PR description rules, which prohibit testing checklists.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ on:
description: Optional space-separated change numbers
required: false
type: string
lookback_days:
description: Days of merged dependency changes to replay
required: false
default: '10'
type: string
Comment on lines +16 to +20

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Short replays also close existing mirrors

A one-day dispatch sends existing open mirrors through sync, not just newly discovered changes. It closes mirrors when both the upstream merge and mirror creation are older than one day.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

permissions: {}
concurrency:
group: shadow-dependency-mirror
Expand All @@ -39,6 +44,7 @@ jobs:
contents: read
env:
PRS: ${{ inputs.prs }}
LOOKBACK_DAYS: ${{ inputs.lookback_days || '10' }}
steps:
- name: Check authentication
id: auth
Expand All @@ -64,7 +70,8 @@ jobs:
shell: bash
run: |
set -euo pipefail
args=()
[[ "$LOOKBACK_DAYS" =~ ^[0-9]+$ ]] || { echo 'Invalid lookback'; exit 1; }
args=(--lookback-days "$LOOKBACK_DAYS")
for pr in $PRS; do
[[ "$pr" =~ ^[0-9]+$ ]] || { echo 'Invalid change number'; exit 1; }
args+=(--pr "$pr")
Expand Down
Loading