-
Notifications
You must be signed in to change notification settings - Fork 166
repo_support: relabel_backported: detect correct upstream & fetch #2756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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
ghCLI - Added automatic detection of the correct Git remote pointing to upstream
- Added automatic fetching from the detected remote (with
--no-fetchflag to disable) - Added
--remoteargument to manually specify the remote if auto-detection fails
| 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 |
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
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.
| for pattern in patterns: | ||
| if pattern in remote_url: |
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
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|$)'
| except subprocess.CalledProcessError as e: | ||
| print(f"Error: Failed to fetch from {remote}: {e}", file=sys.stderr) |
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
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.
| 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) |
gh repo clonesets 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.