From 9e26549b7f30c79f9327afb8c6ffd5d931abc16d Mon Sep 17 00:00:00 2001 From: Ash Date: Mon, 7 Sep 2026 11:05:29 +0100 Subject: [PATCH] Fix detect_repo() picking upstream over origin in fork setups gh repo view resolves the "current" repo from all configured remotes, and when a fork also has an upstream remote pointing at the parent repo, gh can silently pick upstream instead of origin -- causing the skill to operate on the wrong repo entirely (wrong PR numbers, wrong comment/issue targets). Read the origin remote's URL directly instead, falling back to gh repo view only if origin is missing or not GitHub. --- skills/babysit-prs/open_comments.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/skills/babysit-prs/open_comments.py b/skills/babysit-prs/open_comments.py index 352c11e..4881d86 100755 --- a/skills/babysit-prs/open_comments.py +++ b/skills/babysit-prs/open_comments.py @@ -52,6 +52,7 @@ """ import argparse import json +import re import subprocess import sys @@ -66,6 +67,25 @@ def gh(args): def detect_repo(): + """Resolve owner/repo for the CWD's git checkout. + + Prefer the `origin` remote's URL directly. `gh repo view` resolves the + "current" repo from ALL configured remotes, and when a fork also has an + `upstream` remote pointing at the parent repo, gh can pick `upstream` + instead of `origin` - silently operating on the wrong repo (wrong PR + numbers, wrong issue/comment targets). Reading `origin` explicitly avoids + that ambiguity; only fall back to `gh repo view` if there's no `origin` + remote or it isn't a GitHub URL. + """ + p = subprocess.run( + ["git", "remote", "get-url", "origin"], capture_output=True, text=True + ) + if p.returncode == 0: + m = re.search( + r"github\.com[:/]([^/]+)/(.+?)(?:\.git)?/?$", p.stdout.strip() + ) + if m: + return f"{m.group(1)}/{m.group(2)}" return json.loads(gh(["repo", "view", "--json", "nameWithOwner"]))["nameWithOwner"]