Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Apache Kafka Get Json GitHub API

From Leeroopedia


Knowledge Sources
Domains Development_Workflow, Version_Control
Last Updated 2026-02-09 12:00 GMT

Overview

Concrete tool for fetching JSON data from the GitHub REST API provided by the kafka-merge-pr script.

Description

The get_json function sends HTTP GET requests to the GitHub API using urllib.request. It supports optional OAuth authentication via the GITHUB_OAUTH_KEY environment variable. On HTTP errors, it prints the error and exits the process.

Usage

Called internally by the merge script to fetch PR metadata and PR events. Not typically invoked directly by users.

Code Reference

Source Location

  • Repository: Apache Kafka
  • File: committer-tools/kafka-merge-pr.py
  • Lines: L77-90

Signature

def get_json(url):
    """
    Fetches JSON from the specified URL.
    Uses GITHUB_OAUTH_KEY env var for authentication if available.
    Exits with -1 on HTTP errors.
    """

Import

# Internal function in kafka-merge-pr.py
import urllib.request
import json

I/O Contract

Inputs

Name Type Required Description
url str Yes GitHub API URL to fetch
GITHUB_OAUTH_KEY env No OAuth token for authenticated requests

Outputs

Name Type Description
return dict Parsed JSON response from GitHub API

Usage Examples

Fetch PR Metadata

GITHUB_API_BASE = "https://api.github.com/repos/apache/kafka"

pr_num = "12345"
pr = get_json(f"{GITHUB_API_BASE}/pulls/{pr_num}")
print(f"Title: {pr['title']}")
print(f"Base: {pr['base']['ref']}")
print(f"Author: {pr['user']['login']}")

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment