Skip to content
Merged
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
20 changes: 20 additions & 0 deletions skills/babysit-prs/open_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"""
import argparse
import json
import re
import subprocess
import sys

Expand All @@ -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"]


Expand Down
Loading