Feat: Add GitHub2Gerrit awareness to merge command#202
Merged
Conversation
Copilot started reviewing on behalf of
ModeSevenIndustrialSolutions
March 12, 2026 13:00
View session
There was a problem hiding this comment.
Pull request overview
This PR adds GitHub2Gerrit integration to the merge command, detecting PRs that have corresponding Gerrit changes and handling them appropriately (submit in Gerrit, skip, or ignore) instead of merging directly in GitHub.
Changes:
- New
github2gerrit_detector.pymodule for parsing GitHub2Gerrit mapping comments from PR issue comments - Extended
AsyncMergeManagerwith Gerrit detection, submission, and PR closure logic, plus host resolution - Added three mutually exclusive CLI flags (
--submit-gerrit-changes,--skip-gerrit-changes,--ignore-github2gerrit) with validation
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/dependamerge/github2gerrit_detector.py | New module for detecting and parsing GitHub2Gerrit mapping comments |
| src/dependamerge/merge_manager.py | Added GitHub2Gerrit detection, Gerrit submission, PR closure, and host resolution methods |
| src/dependamerge/cli.py | Added three mutually exclusive CLI flags and wired them into merge manager |
| tests/test_github2gerrit_detector.py | Comprehensive tests for detection, parsing, CLI flags, and merge manager integration |
| tests/test_fix_verification.py | Updated existing test to pass new GitHub2Gerrit parameters |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
24f7bee to
3e64d18
Compare
Copilot started reviewing on behalf of
ModeSevenIndustrialSolutions
March 12, 2026 13:09
View session
3e64d18 to
e4592ef
Compare
Copilot started reviewing on behalf of
ModeSevenIndustrialSolutions
March 12, 2026 13:15
View session
e4592ef to
0ab73d0
Compare
Copilot started reviewing on behalf of
ModeSevenIndustrialSolutions
March 12, 2026 13:20
View session
0ab73d0 to
5d3a399
Compare
Copilot started reviewing on behalf of
ModeSevenIndustrialSolutions
March 12, 2026 13:23
View session
5d3a399 to
33dadaf
Compare
Copilot started reviewing on behalf of
ModeSevenIndustrialSolutions
March 12, 2026 13:26
View session
tykeal
reviewed
Mar 12, 2026
Detect GitHub pull requests that have corresponding Gerrit changes created by the GitHub2Gerrit workflow, and handle them appropriately instead of blindly merging them in GitHub (which would leave orphaned Gerrit changes). New CLI flags (mutually exclusive): - --submit-gerrit-changes (default): detect GitHub2Gerrit mapping comments on PRs, look up the corresponding Gerrit change by Change-ID, apply +2 Code-Review, submit it, then close the GitHub PR with a comment following GitHub2Gerrit conventions. - --skip-gerrit-changes: detect GitHub2Gerrit PRs and skip them without merging or submitting anything. - --ignore-github2gerrit: preserve existing behaviour; do not check for GitHub2Gerrit comments and attempt normal GitHub merge. New module github2gerrit_detector.py: - Parses structured HTML-marker mapping comments posted by github2gerrit-action - Falls back to heuristic detection for older comment formats - Extracts Change-IDs, topic names, submission mode, and PR metadata - Provides helper functions for building Gerrit URLs and PR closure comments consistent with GitHub2Gerrit conventions Merge manager changes: - Adds GitHub2Gerrit detection as the first step in _merge_single_pr() - In submit mode: resolves Gerrit credentials (via .netrc or env vars), queries the Gerrit REST API for the open change by Change-ID, submits it, posts a closure comment on the GitHub PR, and closes the PR - In skip mode: reports the PR as skipped with GitHub2Gerrit metadata - In ignore mode: bypasses all GitHub2Gerrit detection - Gerrit host resolution supports GERRIT_HOST/GERRIT_URL env vars, extraction from comment body URLs, and well-known LF infrastructure Copilot review fixes: - Removed unused github2gerrit_detector imports from cli.py - Updated language from integration to awareness in submission comment text - Removed unused GitReviewInfo import from merge_manager.py - Moved os and re imports from local scope to module level for consistency - Added repo_owner fallback for well-known LF host resolution when pr_url is empty - Moved import base64 from local scope to module level in github2gerrit_detector.py Human review fixes (tykeal): - Clarified --submit-gerrit-changes help text to explain it is the implicit default and the flag exists for explicitness, not as a required option Includes 106 new tests covering: - Mapping parsing (marker-based and heuristic) - Detection pipeline (marker priority, fallback, edge cases) - CLI flag mutual exclusivity validation - Merge manager awareness for all three modes - Gerrit submission (success, auth failure, no matching change, REST errors) - PR closure after Gerrit submit (comment posting, close, preview mode) - Gerrit host resolution from env vars, comment URLs, and well-known hosts Co-authored-by: Claude <noreply@anthropic.com> Signed-off-by: Matthew Watkins <mwatkins@linuxfoundation.org>
33dadaf to
3523cf1
Compare
Copilot started reviewing on behalf of
ModeSevenIndustrialSolutions
March 12, 2026 15:40
View session
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tykeal
approved these changes
Mar 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Detect GitHub pull requests that have corresponding Gerrit changes created by the GitHub2Gerrit workflow, and handle them appropriately instead of blindly merging them in GitHub (which would leave orphaned Gerrit changes).
Problem
When dependamerge processes a GitHub org, some repositories (e.g.
releng-gerrit_to_platformin thelfitorg) have GitHub2Gerrit configured. This means GitHub is a read-only mirror of a Gerrit project, and dependabot PRs in GitHub have corresponding Gerrit changes created by the GitHub2Gerrit workflow.If dependamerge merges/closes the GitHub PR directly, the Gerrit change is left orphaned — or a GitHub2Gerrit cleanup job closes it because there's no corresponding open PR. Either way, the automation update is never actually applied to the codebase.
Solution
Two complementary solutions implemented:
1. Default: Submit in Gerrit (
--submit-gerrit-changes)When a PR has GitHub2Gerrit mapping comments, dependamerge:
.gitreview(highest priority), env vars, or heuristics.netrcor env vars)2. Skip mode (
--skip-gerrit-changes)PRs with GitHub2Gerrit comments are detected and skipped without any merge or submit action.
3. Ignore mode (
--ignore-github2gerrit)Preserves existing behavior — no GitHub2Gerrit comment detection, normal GitHub merge attempted.
New CLI Flags
--submit-gerrit-changes--skip-gerrit-changes--ignore-github2gerritThese three flags are mutually exclusive.
Gerrit Host Resolution
The Gerrit host is resolved with the following priority (highest first):
.gitreviewfile in the repository (canonical source of truth — fetched via GitHub API)GERRIT_HOST/GERRIT_BASE_PATHenvironment variableslfitorg →gerrit.linuxfoundation.org/infra)GERRIT_URLenvironment variableThe
.gitreviewfile is treated as definitive because every repository using GitHub2Gerrit is required to have one.New Module:
github2gerrit_detector.py.gitreviewfiles (INI-style format:host=,port=,project=).gitreviewfrom GitHub repos via REST API (no local clone needed)Tests
131 new tests covering:
.gitreviewparsing (standard, edge cases, LF host detection).gitreviewfetching via GitHub API (success, 404, errors).gitreview> env > comment > well-known > URL)All 678 tests pass (existing + new).