mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-24 13:54:57 +00:00
refactor: address code review feedback - improve error handling and remove unsafe assertions
Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
@@ -7,7 +7,13 @@ import { Octokit } from 'octokit'
|
||||
export type GitHubClient = Octokit
|
||||
|
||||
export function createGitHubClient(token?: string): GitHubClient {
|
||||
const authToken = token || process.env.GITHUB_TOKEN
|
||||
|
||||
if (!authToken) {
|
||||
throw new Error('GitHub token is required. Provide a token parameter or set GITHUB_TOKEN environment variable.')
|
||||
}
|
||||
|
||||
return new Octokit({
|
||||
auth: token || process.env.GITHUB_TOKEN,
|
||||
auth: authToken,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -49,10 +49,13 @@ export async function fetchWorkflowRunLogs(
|
||||
// Parse arguments
|
||||
let opts: FetchWorkflowRunLogsOptions
|
||||
if (typeof ownerOrOptions === 'string') {
|
||||
if (!repo || !runId) {
|
||||
throw new Error('repo and runId are required when using positional arguments')
|
||||
}
|
||||
opts = {
|
||||
owner: ownerOrOptions,
|
||||
repo: repo!,
|
||||
runId: runId!,
|
||||
repo,
|
||||
runId,
|
||||
tailLines: options?.tailLines,
|
||||
failedOnly: options?.failedOnly,
|
||||
}
|
||||
|
||||
@@ -277,7 +277,7 @@ function evaluateSimpleExpression(expr: string, context: RenderContext): JsonVal
|
||||
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
||||
value = (value as Record<string, JsonValue>)[part]
|
||||
} else {
|
||||
return value
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ export function loadSchemaRegistry(path?: string): SchemaRegistry {
|
||||
schemaRegistry.packages = packages
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Failed to load schema registry:', error)
|
||||
console.warn(`Failed to load schema registry from ${schemaPath}:`, error instanceof Error ? error.message : String(error))
|
||||
}
|
||||
|
||||
return schemaRegistry
|
||||
@@ -60,7 +60,7 @@ export function saveSchemaRegistry(registry: SchemaRegistry, path?: string): voi
|
||||
}
|
||||
writeFileSync(schemaPath, JSON.stringify(data, null, 2))
|
||||
} catch (error) {
|
||||
console.error('Failed to save schema registry:', error)
|
||||
console.error(`Failed to save schema registry to ${schemaPath}:`, error instanceof Error ? error.message : String(error))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user