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[])
|
}, [] as string[])
|
||||||
.option('--no-auth', 'Skip authentication token')
|
.option('--no-auth', 'Skip authentication token')
|
||||||
.option('--paginate', 'Fetch all pages and combine results')
|
.option('--paginate', 'Fetch all pages and combine results')
|
||||||
|
.option('--json', 'Output compact JSON (default is pretty-printed)')
|
||||||
.action(async (method: string, path: string, opts: {
|
.action(async (method: string, path: string, opts: {
|
||||||
field: string[];
|
field: string[];
|
||||||
query: string[];
|
query: string[];
|
||||||
auth: boolean;
|
auth: boolean;
|
||||||
paginate?: boolean;
|
paginate?: boolean;
|
||||||
|
json?: boolean;
|
||||||
}) => {
|
}) => {
|
||||||
const token = opts.auth !== false ? getToken() : undefined;
|
const token = opts.auth !== false ? getToken() : undefined;
|
||||||
|
|
||||||
@ -83,14 +85,14 @@ export function registerApiCommand(program: Command): void {
|
|||||||
if (result.length < 100) break;
|
if (result.length < 100) break;
|
||||||
page++;
|
page++;
|
||||||
} else {
|
} else {
|
||||||
console.log(JSON.stringify(result, null, 2));
|
console.log(opts.json ? JSON.stringify(result) : JSON.stringify(result, null, 2));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(JSON.stringify(allResults, null, 2));
|
console.log(opts.json ? JSON.stringify(allResults) : JSON.stringify(allResults, null, 2));
|
||||||
} else {
|
} else {
|
||||||
const result = await apiRequest<unknown>(apiPath, requestOpts);
|
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) {
|
} catch (err) {
|
||||||
handleError(err);
|
handleError(err);
|
||||||
|
|||||||
@ -86,10 +86,12 @@ export function registerIssueCommands(program: Command): void {
|
|||||||
const [owner, repo] = repoName.split('/');
|
const [owner, repo] = repoName.split('/');
|
||||||
|
|
||||||
try {
|
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',
|
method: 'POST',
|
||||||
token,
|
token,
|
||||||
body: {
|
body: {
|
||||||
|
repo,
|
||||||
title: opts.title,
|
title: opts.title,
|
||||||
body: opts.body || '',
|
body: opts.body || '',
|
||||||
assignee: opts.assignee,
|
assignee: opts.assignee,
|
||||||
@ -119,7 +121,8 @@ export function registerIssueCommands(program: Command): void {
|
|||||||
const [owner, repo] = repoName.split('/');
|
const [owner, repo] = repoName.split('/');
|
||||||
|
|
||||||
try {
|
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) {
|
if (opts.json) {
|
||||||
console.log(JSON.stringify(iss, null, 2));
|
console.log(JSON.stringify(iss, null, 2));
|
||||||
@ -159,7 +162,8 @@ export function registerIssueCommands(program: Command): void {
|
|||||||
const [owner, repo] = repoName.split('/');
|
const [owner, repo] = repoName.split('/');
|
||||||
|
|
||||||
try {
|
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',
|
method: 'PATCH',
|
||||||
token,
|
token,
|
||||||
body: { state: 'closed', repo },
|
body: { state: 'closed', repo },
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user