From 380ccd30b4a586f88c3c1a5bc8d47840225161b6 Mon Sep 17 00:00:00 2001 From: nuno maduro Date: Sat, 2 May 2026 18:03:25 +0100 Subject: [PATCH] wip --- src/Plugins/Tia/BaselineSync.php | 54 ++++++++++++++------------------ 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/src/Plugins/Tia/BaselineSync.php b/src/Plugins/Tia/BaselineSync.php index 4a3fefe8..694f2e82 100644 --- a/src/Plugins/Tia/BaselineSync.php +++ b/src/Plugins/Tia/BaselineSync.php @@ -651,44 +651,36 @@ YAML; return ['kind' => 'unknown', 'message' => 'unknown error']; } - if (preg_match('/(could not resolve host|connection refused|connection reset|temporary failure in name resolution|network is unreachable|no route to host|i\/o timeout|tls handshake|getaddrinfo)/i', $output) === 1) { - return [ - 'kind' => 'network', + $diagnoses = [ + 'network' => [ + 'pattern' => '/could not resolve host|connection refused|connection reset|temporary failure in name resolution|network is unreachable|no route to host|i\/o timeout|tls handshake|getaddrinfo/i', 'message' => 'network error (offline or DNS unreachable). Try again when connected.', - ]; - } - - if (preg_match('/(authentication failed|not logged in|requires authentication|bad credentials|401)/i', $output) === 1) { - return [ - 'kind' => 'gh-auth', + ], + 'gh-auth' => [ + 'pattern' => '/authentication failed|not logged in|requires authentication|bad credentials|401/i', 'message' => 'authentication failed — run `gh auth login` and retry.', - ]; - } - - if (preg_match('/(rate limit|too many requests|secondary rate limit)/i', $output) === 1) { - return [ - 'kind' => 'rate-limit', + ], + 'rate-limit' => [ + 'pattern' => '/rate limit|too many requests|secondary rate limit/i', 'message' => 'GitHub API rate limit hit — try again later.', - ]; - } - - if (preg_match('/(404|not found|repository not found)/i', $output) === 1) { - return [ - 'kind' => 'not-found', + ], + 'not-found' => [ + 'pattern' => '/404|not found|repository not found/i', 'message' => 'workflow or artifact not found in repo.', - ]; - } - - if (preg_match('/(403|forbidden|access denied)/i', $output) === 1) { - return [ - 'kind' => 'forbidden', + ], + 'forbidden' => [ + 'pattern' => '/403|forbidden|access denied/i', 'message' => 'access denied — check that your `gh` token has repo + actions read scope.', - ]; + ], + ]; + + foreach ($diagnoses as $kind => $diagnosis) { + if (preg_match($diagnosis['pattern'], $output) === 1) { + return ['kind' => $kind, 'message' => $diagnosis['message']]; + } } - $message = trim(strtok($output, "\n")); - - return ['kind' => 'unknown', 'message' => $message]; + return ['kind' => 'unknown', 'message' => trim(strtok($output, "\n"))]; } private function commandExists(string $cmd): bool