diff --git a/src/commands/api.ts b/src/commands/api.ts index c84e4cd..a30361d 100644 --- a/src/commands/api.ts +++ b/src/commands/api.ts @@ -16,11 +16,13 @@ export function registerApiCommand(program: Command): void { }, [] as string[]) .option('--no-auth', 'Skip authentication token') .option('--paginate', 'Fetch all pages and combine results') + .option('--json', 'Output compact JSON (default is pretty-printed)') .action(async (method: string, path: string, opts: { field: string[]; query: string[]; auth: boolean; paginate?: boolean; + json?: boolean; }) => { const token = opts.auth !== false ? getToken() : undefined; @@ -83,14 +85,14 @@ export function registerApiCommand(program: Command): void { if (result.length < 100) break; page++; } else { - console.log(JSON.stringify(result, null, 2)); + console.log(opts.json ? JSON.stringify(result) : JSON.stringify(result, null, 2)); return; } } - console.log(JSON.stringify(allResults, null, 2)); + console.log(opts.json ? JSON.stringify(allResults) : JSON.stringify(allResults, null, 2)); } else { const result = await apiRequest(apiPath, requestOpts); - console.log(JSON.stringify(result, null, 2)); + console.log(opts.json ? JSON.stringify(result) : JSON.stringify(result, null, 2)); } } catch (err) { handleError(err); diff --git a/src/commands/issue.ts b/src/commands/issue.ts index 565a01f..459ff5e 100644 --- a/src/commands/issue.ts +++ b/src/commands/issue.ts @@ -86,10 +86,12 @@ export function registerIssueCommands(program: Command): void { const [owner, repo] = repoName.split('/'); try { - const created = await apiRequest(`/repos/${owner}/${repo}/issues`, { + // Gitee API: POST /repos/{owner}/issues (repo is a body param, NOT in path) + const created = await apiRequest(`/repos/${owner}/issues`, { method: 'POST', token, body: { + repo, title: opts.title, body: opts.body || '', assignee: opts.assignee, @@ -119,7 +121,8 @@ export function registerIssueCommands(program: Command): void { const [owner, repo] = repoName.split('/'); try { - const iss = await apiRequest(`/repos/${owner}/${repo}/issues/${number}`, { token }); + // Gitee API: GET /repos/{owner}/issues/{number} (repo is NOT in path) + const iss = await apiRequest(`/repos/${owner}/issues/${number}`, { token }); if (opts.json) { console.log(JSON.stringify(iss, null, 2)); @@ -159,7 +162,8 @@ export function registerIssueCommands(program: Command): void { const [owner, repo] = repoName.split('/'); try { - const updated = await apiRequest(`/repos/${owner}/${repo}/issues/${number}`, { + // Gitee API: PATCH /repos/{owner}/issues/{number} (repo is NOT in path) + const updated = await apiRequest(`/repos/${owner}/issues/${number}`, { method: 'PATCH', token, body: { state: 'closed', repo },