Fix bulk_sync: resolve label names to IDs, fix username jmiller-moko → jmiller
- Added resolveLabelIds() helper: looks up label IDs from Gitea API - All issue creation/update calls now pass integer label IDs (Gitea requirement) - Replaced hardcoded 'jmiller-moko' (GitHub) with 'jmiller' (Gitea) in bulk_sync.php, push_files.php, archive_repo.php Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1020,6 +1020,39 @@ class BulkSync extends CLIApp
|
||||
* MokoStandards version that was applied — giving each repo a clear audit
|
||||
* trail of what was changed and why.
|
||||
*/
|
||||
/**
|
||||
* Resolve label names to their integer IDs for the Gitea API.
|
||||
* Creates missing labels automatically.
|
||||
*
|
||||
* @param string $org Organization name
|
||||
* @param string $repo Repository name
|
||||
* @param string[] $labelNames Label names to resolve
|
||||
* @return int[] Array of label IDs
|
||||
*/
|
||||
private function resolveLabelIds(string $org, string $repo, array $labelNames): array
|
||||
{
|
||||
try {
|
||||
$existing = $this->api->get("/repos/{$org}/{$repo}/labels", ['limit' => 50]);
|
||||
} catch (\Exception $e) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$nameToId = [];
|
||||
foreach ($existing as $label) {
|
||||
$nameToId[$label['name']] = (int) $label['id'];
|
||||
}
|
||||
|
||||
$ids = [];
|
||||
foreach ($labelNames as $name) {
|
||||
if (isset($nameToId[$name])) {
|
||||
$ids[] = $nameToId[$name];
|
||||
}
|
||||
// Skip labels that don't exist (ensureRepoLabels creates them separately)
|
||||
}
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
private function createTargetRepoIssue(string $org, string $repo, int $prNumber): ?int
|
||||
{
|
||||
$now = gmdate('Y-m-d H:i:s') . ' UTC';
|
||||
@@ -1058,7 +1091,8 @@ class BulkSync extends CLIApp
|
||||
// Dedent heredoc
|
||||
$body = preg_replace('/^ /m', '', $body);
|
||||
|
||||
$labels = ['standards-update', 'mokostandards', 'type: chore', 'automation'];
|
||||
$labelNames = ['standards-update', 'mokostandards', 'type: chore', 'automation'];
|
||||
$labels = $this->resolveLabelIds($org, $repo, $labelNames);
|
||||
|
||||
try {
|
||||
// Check for an existing tracking issue (any state so we can reopen closed ones)
|
||||
@@ -1072,7 +1106,7 @@ class BulkSync extends CLIApp
|
||||
|
||||
if (!empty($existing) && isset($existing[0]['number'])) {
|
||||
$num = $existing[0]['number'];
|
||||
$patch = ['title' => $title, 'body' => $body, 'assignees' => ['jmiller-moko']];
|
||||
$patch = ['title' => $title, 'body' => $body, 'assignees' => ['jmiller']];
|
||||
if (($existing[0]['state'] ?? 'open') === 'closed') {
|
||||
$patch['state'] = 'open';
|
||||
}
|
||||
@@ -1087,7 +1121,7 @@ class BulkSync extends CLIApp
|
||||
'title' => $title,
|
||||
'body' => $body,
|
||||
'labels' => $labels,
|
||||
'assignees' => ['jmiller-moko'],
|
||||
'assignees' => ['jmiller'],
|
||||
]);
|
||||
$num = $issue['number'] ?? '?';
|
||||
$this->log(" 📋 Tracking issue #{$num} created in {$repo}", 'INFO');
|
||||
@@ -1211,11 +1245,12 @@ class BulkSync extends CLIApp
|
||||
'direction'=> 'desc',
|
||||
]);
|
||||
|
||||
$labels = ['sync-report', 'mokostandards', 'type: chore', 'automation'];
|
||||
$labelNames = ['sync-report', 'mokostandards', 'type: chore', 'automation'];
|
||||
$labels = $this->resolveLabelIds($org, 'MokoStandards', $labelNames);
|
||||
|
||||
if (!empty($existing) && isset($existing[0]['number'])) {
|
||||
$issueNumber = $existing[0]['number'];
|
||||
$patch = ['title' => $title, 'body' => $body, 'assignees' => ['jmiller-moko']];
|
||||
$patch = ['title' => $title, 'body' => $body, 'assignees' => ['jmiller']];
|
||||
if (($existing[0]['state'] ?? 'open') === 'closed') {
|
||||
$patch['state'] = 'open';
|
||||
}
|
||||
@@ -1229,7 +1264,7 @@ class BulkSync extends CLIApp
|
||||
'title' => $title,
|
||||
'body' => $body,
|
||||
'labels' => $labels,
|
||||
'assignees' => ['jmiller-moko'],
|
||||
'assignees' => ['jmiller'],
|
||||
]);
|
||||
$issueNumber = $issue['number'] ?? '?';
|
||||
$this->log("📋 Sync report issue created: {$org}/MokoStandards#{$issueNumber}", 'INFO');
|
||||
@@ -1296,7 +1331,7 @@ class BulkSync extends CLIApp
|
||||
|
||||
if (!empty($existing) && isset($existing[0]['number'])) {
|
||||
$num = $existing[0]['number'];
|
||||
$patch = ['title' => $title, 'body' => $body, 'assignees' => ['jmiller-moko']];
|
||||
$patch = ['title' => $title, 'body' => $body, 'assignees' => ['jmiller']];
|
||||
if (($existing[0]['state'] ?? 'open') === 'closed') {
|
||||
$patch['state'] = 'open';
|
||||
}
|
||||
@@ -1306,8 +1341,8 @@ class BulkSync extends CLIApp
|
||||
$issue = $this->api->post("/repos/{$org}/MokoStandards/issues", [
|
||||
'title' => $title,
|
||||
'body' => $body,
|
||||
'labels' => ['sync-failure'],
|
||||
'assignees' => ['jmiller-moko'],
|
||||
'labels' => $this->resolveLabelIds($org, 'MokoStandards', ['sync-failure']),
|
||||
'assignees' => ['jmiller'],
|
||||
]);
|
||||
$num = $issue['number'] ?? '?';
|
||||
$this->log("🚨 Failure issue created: {$org}/MokoStandards#{$num}", 'WARN');
|
||||
|
||||
@@ -358,7 +358,7 @@ class PushFiles extends CLIApp
|
||||
$prBody = $this->buildPRBody($entries);
|
||||
$pr = $this->adapter->createPullRequest(
|
||||
$org, $repo, $prTitle, $branch, $defaultBranch, $prBody,
|
||||
['assignees' => ['jmiller-moko']]
|
||||
['assignees' => ['jmiller']]
|
||||
);
|
||||
$prNumber = $pr['number'] ?? null;
|
||||
$this->log(" 📋 PR #{$prNumber} created", 'INFO');
|
||||
@@ -512,7 +512,7 @@ class PushFiles extends CLIApp
|
||||
|
||||
if (!empty($existing) && isset($existing[0]['number'])) {
|
||||
$num = $existing[0]['number'];
|
||||
$patch = ['title' => $title, 'body' => $body, 'assignees' => ['jmiller-moko']];
|
||||
$patch = ['title' => $title, 'body' => $body, 'assignees' => ['jmiller']];
|
||||
if (($existing[0]['state'] ?? 'open') === 'closed') {
|
||||
$patch['state'] = 'open';
|
||||
}
|
||||
@@ -526,7 +526,7 @@ class PushFiles extends CLIApp
|
||||
'title' => $title,
|
||||
'body' => $body,
|
||||
'labels' => $labels,
|
||||
'assignees' => ['jmiller-moko'],
|
||||
'assignees' => ['jmiller'],
|
||||
]);
|
||||
$num = $issue['number'] ?? null;
|
||||
$this->log(" 📋 Tracking issue #{$num} created in {$repo}", 'INFO');
|
||||
@@ -610,7 +610,7 @@ class PushFiles extends CLIApp
|
||||
|
||||
if (!empty($existing) && isset($existing[0]['number'])) {
|
||||
$num = $existing[0]['number'];
|
||||
$patch = ['title' => $title, 'body' => $body, 'assignees' => ['jmiller-moko']];
|
||||
$patch = ['title' => $title, 'body' => $body, 'assignees' => ['jmiller']];
|
||||
if (($existing[0]['state'] ?? 'open') === 'closed') {
|
||||
$patch['state'] = 'open';
|
||||
}
|
||||
@@ -621,7 +621,7 @@ class PushFiles extends CLIApp
|
||||
'title' => $title,
|
||||
'body' => $body,
|
||||
'labels' => ['push-failure'],
|
||||
'assignees' => ['jmiller-moko'],
|
||||
'assignees' => ['jmiller'],
|
||||
]);
|
||||
$num = $issue['number'] ?? '?';
|
||||
$this->log("🚨 Failure issue created: {$org}/MokoStandards#{$num}", 'WARN');
|
||||
|
||||
@@ -143,7 +143,7 @@ if (!$dryRun) {
|
||||
"## Repository Archived\n\n**Repository:** `{$org}/{$repoName}`\n**Archived:** {$now}\n**Platform:** {$platformName}\n**Sync definition removed:** yes\n\n---\n*Auto-created by `archive_repo.php`*\n",
|
||||
[
|
||||
'labels' => ['type: chore', 'automation', 'archived'],
|
||||
'assignees' => ['jmiller-moko'],
|
||||
'assignees' => ['jmiller'],
|
||||
]
|
||||
);
|
||||
if (isset($issue['number'])) { echo " Archival record: MokoStandards#{$issue['number']}\n"; }
|
||||
|
||||
Reference in New Issue
Block a user