Skip to content

Port the Maintainer Merge Wrapper to a Repository-Neutral Python Program #2195

Closed as not planned

Description

@da2ce7

Goal

Replace contrib/dev-tools/git/merge-pull-request.sh with a Python program beside the vendored engine that performs the same preflight and the same delegation, reads every repository-specific value from Git configuration instead of holding it as a constant, and therefore runs unchanged in any repository that has configured the merge workflow.

Background

The vendored engine contrib/dev-tools/git/github-merge.py bakes in no repository identity. It reads githubmerge.repository (line 543), githubmerge.host (line 544), githubmerge.branch (line 545), githubmerge.merge-author-email (line 546), githubmerge.testcmd (line 547), user.ghtoken (line 548) and user.signingkey (line 549) from Git configuration, and its own help text (lines 513-522) documents them as the configuration surface. Its one Torrust-named constant, SYMLINK_DECLARATION_NAMESPACE (line 240), names the declaration format rather than a repository, which the comment above it and the format documentation both state; every repository adopting the workflow carries the same value. The engine is configuration-driven all the way down.

The wrapper is not. merge-pull-request.sh holds EXPECTED_REPOSITORY="torrust/torrust-tracker" (line 11), TARGET_BRANCH="develop" (line 12) and SYMLINK_DECLARATION=".symlinks.json" (line 13), and require_repository_configuration (lines 38-50) exits unless githubmerge.repository is exactly equal to the first of them. The same string is asserted in the wrapper's own test suite (contrib/dev-tools/git/tests/test-merge-pull-request.sh lines 44, 65, 109, 134, 271), in the sibling engine suite's fixture (contrib/dev-tools/git/tests/test-github-merge-symlinks.py line 30), in contrib/dev-tools/git/README-github-merge.md (lines 4-6) and in .github/skills/dev/git-workflow/merge-pull-request/SKILL.md (lines 21-22, 63, 70).

The consequence is that the preflight is unavailable to every repository except this one. torrust/torrust-index is the concrete case: it has githubmerge.repository configured for its own repository and it carries a symbolic link in its tree, .dockerignore, which is the link that made the declaration mechanism necessary in the first place, but it ships no copy of contrib/dev-tools/git, so a maintainer there invokes this repository's engine directly. Invoking the engine directly loses everything the wrapper adds: the argument shape check, the clean-tree check, the current-branch check, the repository-local signing-key message, the readable-engine check, the terminal guard that keeps an interactive tool from looping forever at end of input, the non-destructive --dry-run, and the --symlinks argument without which the engine performs no declaration processing at all and refuses every symbolic link it meets.

A wrapper whose engine is configuration-driven should not be the component that acquires a repository identity. The wrapper's job is preflight, and a preflight can validate the shape of a configured value without knowing which value is correct: that githubmerge.repository is set and names a repository as <owner>/<repo>, that a signing key is configured, that the working tree is clean, that the checked-out branch is the branch the merge will target. Those checks are exactly as strong for a sibling repository as they are here, and the only thing lost by dropping the constants is the wrapper's ability to refuse a repository that is not this one, which was never a safety property.

The remaining reason the wrapper is a shell script is historical: #2022 vendored the engine and added a small shell entry point around it. That entry point has since grown a terminal guard, a repository-local signing message and a declaration argument, and its test suite has grown a pseudo-terminal harness and a stub interpreter on PATH to observe delegation. It is a program now, written in the language whose argument handling, string comparison and process spawning this repository has had to review most carefully. Writing it in the language the engine and its own test suite already use removes the second language from the workflow and lets the port reuse the conventions the engine suite established.

Scope

In Scope

  • Add contrib/dev-tools/git/merge-pull-request.py, a repository-neutral Python program that performs the preflight the shell wrapper performs today and then delegates to github-merge.py.
  • Read the upstream repository from githubmerge.repository, require it, and validate it against the <owner>/<repo> shape rather than against a value. Report the key and the expected shape; never report an expected repository.
  • Read the target branch from githubmerge.branch, defaulting to develop, and pass it to the engine explicitly as the shell wrapper does today.
  • Read the symbolic-link declaration tree path from githubmerge.symlinks, defaulting to .symlinks.json, validate its shape with the same rule the engine applies to --symlinks, and pass it unconditionally.
  • Preserve every message a test asserts today, except where this specification names a change and gives the reason.
  • Add contrib/dev-tools/git/tests/test-merge-pull-request.py, replacing the bash suite, written with unittest in the conventions of test-github-merge-symlinks.py, and supplying its pseudo-terminal cases from the standard library rather than from script(1).
  • Add repository-neutral coverage the bash suite could not express: a fixture configured for a repository other than this one that passes preflight, and a fixture configured for a target branch other than develop.
  • Remove merge-pull-request.sh and test-merge-pull-request.sh once the port carries every behavior.
  • Update .github/skills/dev/git-workflow/merge-pull-request/SKILL.md, contrib/dev-tools/git/README-github-merge.md and AGENTS.md to the Python entry point and to configuration-key wording.
  • State the Python interpreter version the workflow requires, and check it in the program.
  • Record the static-analysis coverage the port loses and what replaces it.

Out of Scope

  • Any change to the engine's merge semantics. github-merge.py is not edited by this issue: no change to fetching, merging, the symbolic-link check, the tree hash, signing, pushing, or any message it prints.
  • Any new runtime dependency. The program and its tests use the Python standard library and the git the workflow already requires.
  • Any behavior that differs between repositories other than through configuration. The program contains no repository name, no branch name outside a documented default, and no conditional keyed on which repository it is running in.
  • Vendoring or mirroring the port into torrust/torrust-index or any other repository. Adopting it there is separate work in those repositories; this issue only makes it adoptable.
  • Migrating the workflow to Rust. Overhaul: Automation Tools and AI Agent Guardrails #2003 may later select a different automation architecture; this issue keeps the repository-specific integration narrow, which is what that decision asked for.
  • Adding a Python linter to the linter binary. That binary is built from torrust/torrust-linting and cannot be changed from here; this issue records the gap and refers it.
  • Enforcing a declaration file against the tree, or any other new policy. The port moves existing behavior; it adds no check the shell wrapper did not perform.

Specification

The full specification (architectural decisions, behaviour-by-behaviour mapping of the current shell wrapper and its test suite, implementation plan, acceptance criteria, verification plan) is maintained in the repository at docs/issues/open/2195-merge-wrapper-python-port/ISSUE.md and is submitted as a spec-only pull request before implementation starts.

Activity

  1. josecelano commented on Sep 10, 2026

    @josecelano
    Member

    The idea is to migrate everything to Rust not Python. When using Python or Bash we have to explain the reasons we do not choose the default one (Rust).

    At the moment, I do not know if that should be an independent script or should be part of the unified Rust binary to implement the AI harness: #2003.

    I'm planning to write a single Rust binary to:

    • Implement guardrails/sensors deterministic or the ones requiring LLM inference.
    • Perform some regular automatic tasks: update dependencies, clean specs or other batch spec tasks.

    We know that we want to include all checks included in pre-commit and pre-push hooks. This big refactor is postponed until we release version 4.0.0

  2. da2ce7 commented on Sep 10, 2026

    @da2ce7
    ContributorAuthor

    Deferred. The repository's automation direction is Rust, and the merge-workflow wrapper is a candidate for the unified Rust binary planned under #2003 once v4.0.0 has shipped, so a Python port now would be a second rewrite of the same preflight. Until then, sibling repositories that need the merge tool invoke the engine directly, github-merge.py --symlinks .symlinks.json <n> develop, accepting that this skips the wrapper's preflight (signing-key check, terminal guard, dry-run).

    The specification on PR #2196 keeps its value for whichever port happens later: the behaviour-by-behaviour mapping of the shell wrapper and its test suite, and the configuration design (repository validated by shape, branch and declaration path from githubmerge.* keys), are independent of the implementation language. The branch stays on the fork for reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions