Skip to content

Conversation

@mattkur
Copy link
Contributor

@mattkur mattkur commented Feb 5, 2026

gh repo clone sets up remotes in a way that don't work with this script, by default.
Also, I keep forgetting to fetch, so have the script do that by default, also.

@mattkur mattkur requested a review from a team as a code owner February 5, 2026 00:03
Copilot AI review requested due to automatic review settings February 5, 2026 00:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the relabel_backported.py script to automatically detect the correct upstream Git remote and fetch from it before scanning for backported PRs. Previously, the script hardcoded "origin" as the remote name, which doesn't work when using gh repo clone which may set up remotes differently (e.g., naming the upstream repo as "upstream" instead).

Changes:

  • Added automatic detection of upstream repository using gh CLI
  • Added automatic detection of the correct Git remote pointing to upstream
  • Added automatic fetching from the detected remote (with --no-fetch flag to disable)
  • Added --remote argument to manually specify the remote if auto-detection fails

Comment on lines +56 to +63
for line in remotes:
parts = line.split()
if len(parts) >= 2:
remote_name = parts[0]
remote_url = parts[1]
for pattern in patterns:
if pattern in remote_url:
return remote_name
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

The remote detection logic may return the first matching remote rather than a deterministic choice when multiple remotes point to the same upstream repository. This could lead to inconsistent behavior depending on the order of remotes in git config.

Consider adding logic to prefer specific remote names (e.g., "upstream" over "origin") or document this behavior. If multiple remotes exist, you might want to either warn the user or select based on a priority order.

Copilot uses AI. Check for mistakes.
Comment on lines +61 to +62
for pattern in patterns:
if pattern in remote_url:
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

The remote detection pattern matching using substring 'in' operator could lead to false positives. For example, if a repository named "microsoft/openvmm-fork" exists and someone has a remote to it, it would match the pattern for "microsoft/openvmm" since "github.com/microsoft/openvmm" is a substring of "github.com/microsoft/openvmm-fork".

Consider using more precise matching, such as ensuring the repository name is followed by ".git", a query parameter, or end of string. You could use regex patterns like: r'github\.com[:/]' + re.escape(upstream_repo) + r'(\.git)?(\s|$)'

Copilot uses AI. Check for mistakes.
Comment on lines +103 to +104
except subprocess.CalledProcessError as e:
print(f"Error: Failed to fetch from {remote}: {e}", file=sys.stderr)
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

The fetch operation at line 102 uses subprocess.check_call() which will raise CalledProcessError on non-zero exit, but this is caught and handled properly. However, the error message at line 104 includes the exception object 'e' which will show the full exception representation. Consider using str(e) or e.returncode for a cleaner error message, or just omit it since the git error output will already be visible to the user.

Suggested change
except subprocess.CalledProcessError as e:
print(f"Error: Failed to fetch from {remote}: {e}", file=sys.stderr)
except subprocess.CalledProcessError:
print(f"Error: Failed to fetch from {remote}.", file=sys.stderr)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant