Files
moko-platform/cli/dev_branch_reset.php
T
Jonathan Miller e5d6936a94
Platform: moko-platform CI / Gate 2: Unit Tests (8.1) (push) Blocked by required conditions
Platform: moko-platform CI / Gate 2: Unit Tests (8.2) (push) Blocked by required conditions
Platform: moko-platform CI / Gate 2: Unit Tests (8.3) (push) Blocked by required conditions
Platform: moko-platform CI / Gate 3: Self-Health Check (push) Blocked by required conditions
Platform: moko-platform CI / Gate 4: Governance (push) Blocked by required conditions
Platform: moko-platform CI / Gate 5: Template Integrity (push) Blocked by required conditions
Platform: moko-platform CI / CI Summary (push) Blocked by required conditions
Generic: Repo Health / Release configuration (push) Blocked by required conditions
Generic: Repo Health / Scripts governance (push) Blocked by required conditions
Generic: Repo Health / Repository health (push) Blocked by required conditions
Generic: Repo Health / Site Health (push) Has been skipped
Generic: Repo Health / Access control (push) Successful in 1s
Universal: Auto Version Bump / Version Bump (push) Failing after 2s
Platform: moko-platform CI / Gate 1: Code Quality (push) Failing after 48s
refactor: rename secrets GA_TOKEN→MOKOGITEA_TOKEN, GH_TOKEN→GITHUB_TOKEN
- Renamed secret references across all 14 workflows and 13 CLI tools
- Replaced hardcoded jmiller: auth with x-access-token: pattern
- Consolidated git config + remote set-url into single early step in
  auto-release.yml, removed duplicate config blocks
- Renamed local shell variable GA_TOKEN→GITEA_TOKEN for consistency
- No backwards compatibility shims — clean break

Authored-by: Moko Consulting

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-28 14:22:47 -05:00

98 lines
3.0 KiB
PHP

#!/usr/bin/env php
<?php
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* FILE INFORMATION
* DEFGROUP: moko-platform.CLI
* INGROUP: moko-platform
* REPO: https://git.mokoconsulting.tech/MokoConsulting/moko-platform
* PATH: /cli/dev_branch_reset.php
* BRIEF: Delete and recreate dev branch from main via Gitea API
*
* Usage:
* php dev_branch_reset.php --token TOKEN --api-base URL
* php dev_branch_reset.php --token TOKEN --api-base URL --branch dev --from main
*
* Options:
* --token Gitea API token (required)
* --api-base Gitea API base URL (required)
* --branch Branch to reset (default: dev)
* --from Source branch (default: main)
* --output-summary Write to $GITHUB_STEP_SUMMARY
*/
declare(strict_types=1);
$token = null;
$apiBase = null;
$branch = 'dev';
$from = 'main';
$outputSummary = false;
foreach ($argv as $i => $arg) {
if ($arg === '--token' && isset($argv[$i + 1])) $token = $argv[$i + 1];
if ($arg === '--api-base' && isset($argv[$i + 1])) $apiBase = $argv[$i + 1];
if ($arg === '--branch' && isset($argv[$i + 1])) $branch = $argv[$i + 1];
if ($arg === '--from' && isset($argv[$i + 1])) $from = $argv[$i + 1];
if ($arg === '--output-summary') $outputSummary = true;
}
if ($token === null) $token = getenv('MOKOGITEA_TOKEN') ?: getenv('GITEA_TOKEN') ?: null;
if ($token === null || $apiBase === null) {
fwrite(STDERR, "Usage: dev_branch_reset.php --token TOKEN --api-base URL [--branch dev] [--from main]\n");
exit(1);
}
// Delete branch (tolerate 404)
$ch = curl_init("{$apiBase}/branches/{$branch}");
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'DELETE',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: token {$token}"],
CURLOPT_TIMEOUT => 30,
]);
curl_exec($ch);
$delCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($delCode === 204 || $delCode === 200) {
echo "Deleted branch '{$branch}'\n";
} elseif ($delCode === 404) {
echo "Branch '{$branch}' did not exist (skipped delete)\n";
} else {
fwrite(STDERR, "WARNING: Delete branch returned HTTP {$delCode}\n");
}
// Create branch from source
$payload = json_encode(['new_branch_name' => $branch, 'old_branch_name' => $from]);
$ch = curl_init("{$apiBase}/branches");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: token {$token}", "Content-Type: application/json"],
CURLOPT_POSTFIELDS => $payload,
CURLOPT_TIMEOUT => 30,
]);
$response = curl_exec($ch);
$createCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($createCode === 201) {
echo "Recreated '{$branch}' from '{$from}'\n";
} else {
fwrite(STDERR, "Failed to create branch '{$branch}' from '{$from}' (HTTP {$createCode})\n");
exit(1);
}
if ($outputSummary) {
$summaryFile = getenv('GITHUB_STEP_SUMMARY');
if ($summaryFile) {
file_put_contents($summaryFile, "Dev branch reset: '{$branch}' recreated from '{$from}'\n", FILE_APPEND);
}
}
exit(0);