From 8820577d8d735c38c11fe204ae0adaf93557e8f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=A9=98?= Date: Wed, 1 Apr 2026 23:33:07 +0000 Subject: [PATCH] fix: correct Gitee API paths for issue ops, add --json to api command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug 1: Gitee create/update issue API uses /repos/{owner}/issues (no repo in path, unlike GitHub). Fix issue create to POST to /repos/{owner}/issues with repo as body param. Fix issue view and close to use same pattern. Bug 2: gitee api command did not accept --json flag. Add --json option: - without --json: pretty-printed JSON (default) - with --json: compact JSON (pipe-friendly) 小橘 🍊(NEKO Team) --- src/commands/api.ts | 8 +++++--- src/commands/issue.ts | 10 +++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) 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 },