Skip to content

Feat: Add GitHub2Gerrit awareness to merge command#202

Merged
tykeal merged 1 commit intolfit:mainfrom
modeseven-lfit:feat/github2gerrit-integration
Mar 12, 2026
Merged

Feat: Add GitHub2Gerrit awareness to merge command#202
tykeal merged 1 commit intolfit:mainfrom
modeseven-lfit:feat/github2gerrit-integration

Conversation

@ModeSevenIndustrialSolutions
Copy link
Contributor

@ModeSevenIndustrialSolutions ModeSevenIndustrialSolutions commented Mar 12, 2026

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_platform in the lfit org) 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:

  • Detects the mapping comment (using HTML markers or heuristic fallback)
  • Extracts the Change-ID from the mapping
  • Resolves the Gerrit host using .gitreview (highest priority), env vars, or heuristics
  • Resolves Gerrit credentials (via .netrc or env vars)
  • Queries the Gerrit REST API for the open change
  • Applies +2 Code-Review and submits the change
  • Posts a closure comment on the GitHub PR following GitHub2Gerrit conventions
  • Closes the GitHub PR

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

Flag Description
--submit-gerrit-changes (default) Submit matching Gerrit changes for PRs with GitHub2Gerrit comments
--skip-gerrit-changes Skip PRs with GitHub2Gerrit comments
--ignore-github2gerrit Ignore GitHub2Gerrit comments, merge in GitHub as normal

These three flags are mutually exclusive.

Gerrit Host Resolution

The Gerrit host is resolved with the following priority (highest first):

  1. .gitreview file in the repository (canonical source of truth — fetched via GitHub API)
  2. GERRIT_HOST / GERRIT_BASE_PATH environment variables
  3. Gerrit URL embedded in the GitHub2Gerrit mapping comment body
  4. Well-known host conventions (e.g. lfit org → gerrit.linuxfoundation.org/infra)
  5. GERRIT_URL environment variable

The .gitreview file is treated as definitive because every repository using GitHub2Gerrit is required to have one.

New Module: github2gerrit_detector.py

  • Parses structured HTML-marker mapping comments posted by github2gerrit-action
  • Falls back to heuristic detection for older/variant comment formats
  • Extracts Change-IDs, topic names, submission mode, and PR metadata
  • Provides helper functions for Gerrit URL construction and PR closure comments
  • Parses .gitreview files (INI-style format: host=, port=, project=)
  • Fetches .gitreview from GitHub repos via REST API (no local clone needed)
  • Derives REST API base paths for well-known Gerrit hosts

Tests

131 new tests covering:

  • .gitreview parsing (standard, edge cases, LF host detection)
  • .gitreview fetching via GitHub API (success, 404, errors)
  • Mapping parsing (marker-based and heuristic)
  • Detection pipeline (marker priority, fallback, edge cases)
  • CLI flag mutual exclusivity validation
  • Merge manager integration for all three modes
  • Gerrit host resolution priority (.gitreview > env > comment > well-known > URL)
  • Gerrit submission (success, auth failure, no matching change, REST errors)
  • PR closure after Gerrit submit
  • Gerrit host resolution from env vars, comment URLs, and well-known hosts

All 678 tests pass (existing + new).

Copilot AI review requested due to automatic review settings March 12, 2026 13:00
Copy link

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 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.py module for parsing GitHub2Gerrit mapping comments from PR issue comments
  • Extended AsyncMergeManager with 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.

This comment was marked as outdated.

@ModeSevenIndustrialSolutions ModeSevenIndustrialSolutions changed the title feat: add GitHub2Gerrit integration for merge command Feat: Add GitHub2Gerrit awareness to merge command Mar 12, 2026

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

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>
Copy link

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

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 tykeal merged commit 7598386 into lfit:main Mar 12, 2026
21 checks passed
@ModeSevenIndustrialSolutions ModeSevenIndustrialSolutions deleted the feat/github2gerrit-integration branch March 13, 2026 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants