mirror of
https://github.com/jackwener/OpenCLI.git
synced 2026-09-14 18:25:42 +08:00
314bc6f231
1. Remove root-level shim files (errors.ts, logger.ts, registry.ts, types.ts, utils.ts, launcher.ts) — update all ~840 adapter imports to reference src/ directly 2. Consolidate interceptor: reuse shared DISGUISE_FN in tap interceptor instead of reimplementing 3. Unify error classification: single ClassifiedError type with icon/exitCode/hint lookup table, eliminating duplicated pattern matching between resolveExitCode and renderError 4. Simplify cascade probe: replace repetitive switch cases with PROBE_OPTIONS lookup map 12. Clean up synthesize.ts: remove deprecated snake_case field aliases (recommended_args, recommended_columns, recommendedColumnsLegacy) and unnecessary constant aliases Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
80 lines
2.5 KiB
TypeScript
80 lines
2.5 KiB
TypeScript
import { cli, Strategy } from '../../src/registry.js';
|
|
import { CliError } from '../../src/errors.js';
|
|
import { onesFetchInPage } from './common.js';
|
|
import { formatStamp } from './task-helpers.js';
|
|
|
|
/**
|
|
* 工作项详情 — 对应前端路由 …/team/<team>/filter/view/…/task/<uuid>
|
|
* API: GET team/:teamUUID/task/:taskUUIDOrNumber/info
|
|
* @see https://docs.ones.cn/project/open-api-doc/project/task.html
|
|
*/
|
|
cli({
|
|
site: 'ones',
|
|
name: 'task',
|
|
description:
|
|
'ONES — work item detail (GET team/:team/task/:id/info); id is URL segment after …/task/',
|
|
domain: 'ones.cn',
|
|
strategy: Strategy.COOKIE,
|
|
browser: true,
|
|
navigateBefore: false,
|
|
args: [
|
|
{
|
|
name: 'id',
|
|
type: 'str',
|
|
required: true,
|
|
positional: true,
|
|
help: 'Work item UUID (often 16 chars) from …/task/<id>',
|
|
},
|
|
{
|
|
name: 'team',
|
|
type: 'str',
|
|
required: false,
|
|
help: 'Team UUID (8 chars from …/team/<team>/…), or set ONES_TEAM_UUID',
|
|
},
|
|
],
|
|
columns: ['uuid', 'summary', 'number', 'status_uuid', 'assign', 'owner', 'project_uuid', 'updated'],
|
|
|
|
func: async (page, kwargs) => {
|
|
const id = String(kwargs.id ?? '').trim();
|
|
if (!id) {
|
|
throw new CliError('CONFIG', 'task id required', 'Pass the work item uuid from the URL path …/task/<id>');
|
|
}
|
|
|
|
const team =
|
|
(kwargs.team as string | undefined)?.trim() ||
|
|
process.env.ONES_TEAM_UUID?.trim() ||
|
|
process.env.ONES_TEAM_ID?.trim();
|
|
if (!team) {
|
|
throw new CliError(
|
|
'CONFIG',
|
|
'team UUID required',
|
|
'Use --team <teamUUID> or set ONES_TEAM_UUID (from …/team/<team>/…).',
|
|
);
|
|
}
|
|
|
|
const path = `team/${team}/task/${encodeURIComponent(id)}/info`;
|
|
const data = (await onesFetchInPage(page, path, { method: 'GET' })) as Record<string, unknown>;
|
|
|
|
if (typeof data.uuid !== 'string') {
|
|
const hint =
|
|
typeof data.reason === 'string'
|
|
? data.reason
|
|
: 'Use -f json to inspect response; check id length (often 16) and team.';
|
|
throw new CliError('FETCH_ERROR', `ONES task info: ${hint}`, 'Confirm task uuid and team match the browser URL.');
|
|
}
|
|
|
|
return [
|
|
{
|
|
uuid: String(data.uuid),
|
|
summary: String(data.summary ?? ''),
|
|
number: data.number != null ? String(data.number) : '',
|
|
status_uuid: String(data.status_uuid ?? ''),
|
|
assign: String(data.assign ?? ''),
|
|
owner: String(data.owner ?? ''),
|
|
project_uuid: String(data.project_uuid ?? ''),
|
|
updated: formatStamp(data.server_update_stamp),
|
|
},
|
|
];
|
|
},
|
|
});
|