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:
copilot-swe-agent[bot]
2026-01-06 15:18:01 +00:00
parent e44c480fba
commit 7e424a28bb
4 changed files with 15 additions and 6 deletions

View File

@@ -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,
})
}

View File

@@ -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,
}

View File

@@ -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
}
}

View File

@@ -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))
}
}