fix: correct Gitee API paths for issue ops, add --json to api command
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)
This commit is contained in:
parent
dd5963466e
commit
8820577d8d
@ -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<unknown>(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);
|
||||
|
||||
@ -86,10 +86,12 @@ export function registerIssueCommands(program: Command): void {
|
||||
const [owner, repo] = repoName.split('/');
|
||||
|
||||
try {
|
||||
const created = await apiRequest<GiteeIssue>(`/repos/${owner}/${repo}/issues`, {
|
||||
// Gitee API: POST /repos/{owner}/issues (repo is a body param, NOT in path)
|
||||
const created = await apiRequest<GiteeIssue>(`/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<GiteeIssue>(`/repos/${owner}/${repo}/issues/${number}`, { token });
|
||||
// Gitee API: GET /repos/{owner}/issues/{number} (repo is NOT in path)
|
||||
const iss = await apiRequest<GiteeIssue>(`/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<GiteeIssue>(`/repos/${owner}/${repo}/issues/${number}`, {
|
||||
// Gitee API: PATCH /repos/{owner}/issues/{number} (repo is NOT in path)
|
||||
const updated = await apiRequest<GiteeIssue>(`/repos/${owner}/issues/${number}`, {
|
||||
method: 'PATCH',
|
||||
token,
|
||||
body: { state: 'closed', repo },
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user