#!/usr/bin/env python3
"""Merge a Gitea pull request — DISABLED (#16).

Direct CLI merge is a fail-closed no-op. LLM automations in this project were
using this script as an ungated merge bypass, so it no longer performs a merge.
Merge is only available through the gated `gitea_merge_pr` MCP workflow (#16),
which enforces identity/profile/eligibility, explicit confirmation, expected
head SHA checking, and self-merge protection.

Usage (fails closed):
    merge_pr.py --pr-number 84 --do squash --remote dadeschools
"""
import os
import sys
import json
import argparse

# Auto-execute using the project's local virtual environment Python
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
venv_python = os.path.join(PROJECT_ROOT, "venv", "bin", "python3")
if os.path.exists(venv_python) and sys.executable != venv_python:
    os.execv(venv_python, [venv_python] + sys.argv)

from gitea_auth import get_auth_header, resolve_remote, add_remote_args, api_request, repo_api_url


def main(argv=None):
    parser = argparse.ArgumentParser(description="Merge a Gitea pull request.")
    add_remote_args(parser)
    parser.add_argument("--pr-number", type=int, required=True, help="PR number/index to merge.")
    parser.add_argument("--do", choices=["merge", "squash", "rebase"], default="merge",
                        help="Merge method/style (default: merge).")
    parser.add_argument("--title", help="Optional merge title.")
    parser.add_argument("--message", help="Optional merge message.")
    parser.add_argument("--force", action="store_true", help="Force merge, ignoring status checks.")
    args = parser.parse_args(argv)

    # Fail closed: direct CLI merge is disabled (#16). No credentials are read
    # and no merge API call is made. Merge is only available through the gated
    # `gitea_merge_pr` MCP workflow, which enforces identity/profile/eligibility,
    # explicit confirmation, expected head SHA checking, and self-merge
    # protection.
    print(
        f"Direct CLI merge is disabled (#16). PR #{args.pr_number} was NOT "
        "merged. Merge is only available through the gated workflow (MCP tool "
        "'gitea_merge_pr'), which enforces identity/profile/eligibility, "
        "explicit confirmation, expected head SHA checking, and self-merge "
        "protection.",
        file=sys.stderr,
    )
    return 2


if __name__ == "__main__":
    sys.exit(main())
