Gig-Safe-GitHub-Patch-Committer

By (author)sarah siddiqui

Tech stack:
Git
GHA
PY

Commits a human-approved patch to an isolated GitHub branch — never main — and refuses to write if the source file changed since the patch was reviewe...
read more
AI Contributions:2
Published At:August 12, 2026
Files Included:4 file(s)
Updated At:October 23, 2026

Read Me

Safe GitHub Patch Committer

A small reusable GitHub write component extracted from AutoPentest Studio.

It accepts an already-reviewed patch and commits it to a new isolated branch while preventing stale or accidental writes.

Core safeguards

The component:

  1. accepts only standard GitHub HTTPS repository URLs
  2. resolves the current base-branch commit
  3. refuses to use the base branch as the patch branch
  4. creates an isolated branch
  5. validates an existing branch instead of blindly accepting GitHub HTTP 422
  6. reads the current target file from GitHub
  7. verifies the file's SHA-256 against the version used when the patch was generated
  8. refuses to commit if the source changed
  9. writes the patch through GitHub's Contents API
  10. returns the created branch and commit URL

This component does not decide whether a patch is safe or approved. Human approval should happen before calling it.

Requirements

  • Python 3.10+
  • requests
  • a GitHub token with access to the target repository and permission to write repository contents

Install:

pip install -r requirements.txt

Usage

from safe_github_patch_committer import (
    PatchProposal,
    commit_patch_to_isolated_branch,
    sha256_text,
)

original_source = open("app.py", "r", encoding="utf-8").read()

proposal = PatchProposal( title="Security: parameterize SQL query", target_file="app.py", patched_content="...reviewed complete replacement file...", expected_sha256=sha256_text(original_source), )

result = commit_patch_to_isolated_branch( repository_url="https://github.com/example/example-app.git", base_branch="main", token="YOUR_FINE_GRAINED_TOKEN", proposal=proposal, branch_name="security/fix-sqli-001", )

print(result["branch"]) print(result["commit_url"])

Why SHA-256 is checked

A patch may be reviewed against version A of a file. If another developer changes that file to version B before the patch is committed, blindly applying the old replacement could overwrite new code or create an unsafe result.

The expected SHA-256 binds the approved patch to the exact source version that was reviewed.

Branch behavior

This gig intentionally does not commit directly to the base branch.

If the requested patch branch already exists, it is only reusable when it still points to the same untouched base commit. Otherwise the function fails and requires a new branch name.

Limitations

  • Designed for UTF-8 text files.
  • Uses GitHub's Contents API.
  • The caller is responsible for human review/approval before invocation.
  • The caller is responsible for pull-request review, CI, deployment, and runtime re-testing.

Origin

Built during the hackathon as AutoPentest Studio's human-approved GitHub remediation commit capability, then extracted as a standalone reusable code gig.

Dependencies / disclosure

  • GitHub REST API
  • requests
  • No AutoPentest Studio database, scanner, authentication, or UI code is included.

License

Recommended marketplace/repository license: MIT.

Loading

Loading

Loading

More like this View all

AI Interview & Career Recommendation Microservice

Drop-in Python service that runs an AI-powered technical interview and returns a structured profile: Analyzes resume + GitHub Asks/assesses interview questions Extracts skills, strengths/weaknesses,

  • 0

    Ratings

  • 18

    Files

    • PY
    • Git
    • +1

    Tech stack

Structured Generative AI Workout Architect

A robust Python module that uses Google's Gemini to generate highly personalized workout plans while strictly adhering to a predefined exercise library. It uses structured JSON schemas, advanced promp

  • 0

    Ratings

  • 1

    Files

    • PY

    Tech stack

AI Q&A: Repo-Aware Chat with 3-Tier Fallback

CodeMesh-AIs AI chat endpoint: searches indexed files for context, then tries OpenAI, local Ollama, then a heuristic fallback — so it always answers, even with zero AI providers configured.

  • 0

    Ratings

  • 1

    Files

    • PY

    Tech stack