From a7214ed4ca91952a1276ff62eeb96b0b3c4930ea Mon Sep 17 00:00:00 2001 From: patrick Date: Sun, 3 May 2026 09:39:44 -0700 Subject: [PATCH 1/2] =?UTF-8?q?feat(system):=20fix(drone):=20dynamic=20for?= =?UTF-8?q?k=20recovery=20message=20with=20actual=20repo/user=20info=20?= =?UTF-8?q?=E2=80=94=20closes=20#329?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: @devpulse --- .../drone/apps/handlers/git/pr_handler.py | 35 +++++++++++++++---- .../apps/plugins/devpulse_ops/pr_plugin.py | 4 +-- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/aipass/drone/apps/handlers/git/pr_handler.py b/src/aipass/drone/apps/handlers/git/pr_handler.py index f9c486ef..9631e609 100644 --- a/src/aipass/drone/apps/handlers/git/pr_handler.py +++ b/src/aipass/drone/apps/handlers/git/pr_handler.py @@ -36,14 +36,37 @@ def _is_permission_error(stderr: str) -> bool: return any(ind.lower() in lower for ind in indicators) -_FORK_RECOVERY = """ -Push failed due to insufficient permissions. You may be working on a fork. +def _fork_recovery_message(branch: str, repo_root: str = ".") -> str: + """Build a dynamic fork recovery message with actual repo/user info.""" + origin = "AIOSAI/AIPass" + try: + r = subprocess.run( + ["gh", "repo", "view", "--json", "nameWithOwner", "-q", ".nameWithOwner"], + capture_output=True, text=True, cwd=repo_root, + ) + if r.returncode == 0 and r.stdout.strip(): + origin = r.stdout.strip() + except OSError as exc: + logger.info("Could not detect origin repo: %s", exc) + + gh_user = "" + try: + r = subprocess.run( + ["gh", "api", "user", "-q", ".login"], + capture_output=True, text=True, + ) + if r.returncode == 0 and r.stdout.strip(): + gh_user = r.stdout.strip() + except OSError as exc: + logger.info("Could not detect gh user: %s", exc) + + return f"""Push failed due to insufficient permissions. You may be working on a fork. To contribute from a fork: - 1. Create a fork: gh repo fork AIOSAI/AIPass --remote=false --clone=false - 2. Add fork as remote: git remote add fork + 1. Create a fork: gh repo fork {origin} --remote=false --clone=false + 2. Add fork as remote: git remote add fork https://github.com/{gh_user}/{origin.split('/')[-1]}.git 3. Push to your fork: git push -u fork {branch} - 4. Open cross-repo PR: gh pr create -R AIOSAI/AIPass -H :{branch} -B main + 4. Open cross-repo PR: gh pr create -R {origin} -H {gh_user}:{branch} -B main """ @@ -193,7 +216,7 @@ def create_pr(branch_name: str, description: str, branch_dir: Path) -> dict: if push.returncode != 0: stderr = push.stderr.strip() if _is_permission_error(stderr): - result["message"] = _FORK_RECOVERY.format(branch=feature_branch) + result["message"] = _fork_recovery_message(feature_branch, str(repo_root)) else: result["message"] = f"Push failed: {stderr}" logger.error(result["message"]) diff --git a/src/aipass/drone/apps/plugins/devpulse_ops/pr_plugin.py b/src/aipass/drone/apps/plugins/devpulse_ops/pr_plugin.py index 85e87d70..60d87824 100644 --- a/src/aipass/drone/apps/plugins/devpulse_ops/pr_plugin.py +++ b/src/aipass/drone/apps/plugins/devpulse_ops/pr_plugin.py @@ -34,7 +34,7 @@ from aipass.drone.apps.handlers.git.lock_handler import ( ) from aipass.drone.apps.handlers.git.pr_handler import ( _is_permission_error, - _FORK_RECOVERY, + _fork_recovery_message, ) @@ -218,7 +218,7 @@ def create_system_pr(description: str, caller: str) -> dict: if push.returncode != 0: stderr = push.stderr.strip() if _is_permission_error(stderr): - result["message"] = _FORK_RECOVERY.format(branch=feature_branch) + result["message"] = _fork_recovery_message(feature_branch, str(repo_root)) else: result["message"] = f"Push failed: {stderr}" logger.error(result["message"]) From 26c83b3f07a5d50fda195cad65f6d80b23c5e9c5 Mon Sep 17 00:00:00 2001 From: patrick Date: Sun, 3 May 2026 09:41:44 -0700 Subject: [PATCH 2/2] feat(system): style(drone): fix ruff format on pr_handler.py fork recovery Co-Authored-By: @devpulse --- src/aipass/drone/apps/handlers/git/pr_handler.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/aipass/drone/apps/handlers/git/pr_handler.py b/src/aipass/drone/apps/handlers/git/pr_handler.py index 9631e609..ed8b75c8 100644 --- a/src/aipass/drone/apps/handlers/git/pr_handler.py +++ b/src/aipass/drone/apps/handlers/git/pr_handler.py @@ -42,7 +42,9 @@ def _fork_recovery_message(branch: str, repo_root: str = ".") -> str: try: r = subprocess.run( ["gh", "repo", "view", "--json", "nameWithOwner", "-q", ".nameWithOwner"], - capture_output=True, text=True, cwd=repo_root, + capture_output=True, + text=True, + cwd=repo_root, ) if r.returncode == 0 and r.stdout.strip(): origin = r.stdout.strip() @@ -53,7 +55,8 @@ def _fork_recovery_message(branch: str, repo_root: str = ".") -> str: try: r = subprocess.run( ["gh", "api", "user", "-q", ".login"], - capture_output=True, text=True, + capture_output=True, + text=True, ) if r.returncode == 0 and r.stdout.strip(): gh_user = r.stdout.strip() @@ -64,7 +67,7 @@ def _fork_recovery_message(branch: str, repo_root: str = ".") -> str: To contribute from a fork: 1. Create a fork: gh repo fork {origin} --remote=false --clone=false - 2. Add fork as remote: git remote add fork https://github.com/{gh_user}/{origin.split('/')[-1]}.git + 2. Add fork as remote: git remote add fork https://github.com/{gh_user}/{origin.split("/")[-1]}.git 3. Push to your fork: git push -u fork {branch} 4. Open cross-repo PR: gh pr create -R {origin} -H {gh_user}:{branch} -B main """