Implementation:Apache Kafka Merge Pr
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Development_Workflow, Version_Control |
| Last Updated | 2026-02-09 12:00 GMT |
Overview
Concrete tool for performing squash merges of pull requests provided by the kafka-merge-pr script.
Description
The merge_pr function orchestrates the complete squash merge of a GitHub PR. It fetches the PR and target branches, performs git merge --squash, constructs a formatted commit message with attribution, creates the merge commit, and pushes to the remote repository. It returns the first 8 characters of the merge hash for use in cherry-pick operations.
Usage
Called by the interactive merge script after PR metadata is fetched and the commit title is confirmed by the committer.
Code Reference
Source Location
- Repository: Apache Kafka
- File: committer-tools/kafka-merge-pr.py
- Lines: L132-210
Signature
def merge_pr(pr_num, target_ref, title, body, pr_repo_desc):
"""
Squash-merges a PR onto the target branch.
Args:
pr_num: PR number
target_ref: Target branch (e.g., "trunk")
title: Commit title (standardized)
body: PR body/description
pr_repo_desc: Source repo description
Returns:
merge_hash: First 8 chars of the merge commit hash
"""
Import
# Internal function in kafka-merge-pr.py
import subprocess
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| pr_num | str | Yes | GitHub PR number |
| target_ref | str | Yes | Target branch for merge (e.g., "trunk") |
| title | str | Yes | Standardized commit title |
| body | str | Yes | PR description body |
| pr_repo_desc | str | Yes | Source repository description |
Outputs
| Name | Type | Description |
|---|---|---|
| merge_hash | str | First 8 characters of the merge commit hash |
| Squash commit | git commit | Created on target branch with full attribution |
Usage Examples
# Called internally by the merge script
merge_hash = merge_pr(
pr_num="12345",
target_ref="trunk",
title="KAFKA-12345; Fix consumer offset commit",
body="This PR fixes the offset commit race condition...",
pr_repo_desc="contributor/kafka"
)
print(f"Merged with hash: {merge_hash}")
Related Pages
Implements Principle
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment