@hangox/pm-cli 1.1.1 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +88 -35
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -530,6 +530,9 @@ function outputError(error, pretty = false) {
|
|
|
530
530
|
const finalResult = addKeyMappingToResult(result);
|
|
531
531
|
console.log(JSON.stringify(finalResult, null, pretty ? 2 : 0));
|
|
532
532
|
}
|
|
533
|
+
function extractErrorMessage(result, defaultMsg = "\u64CD\u4F5C\u5931\u8D25") {
|
|
534
|
+
return result.post_error_msg || result.api_error_msg || result.message || result.msg || defaultMsg;
|
|
535
|
+
}
|
|
533
536
|
|
|
534
537
|
// src/commands/test.ts
|
|
535
538
|
function createTestCommand() {
|
|
@@ -553,7 +556,7 @@ function createTestCommand() {
|
|
|
553
556
|
data: result.data
|
|
554
557
|
}, options.pretty);
|
|
555
558
|
} else {
|
|
556
|
-
outputError(result
|
|
559
|
+
outputError(extractErrorMessage(result, "\u8FDE\u63A5\u5931\u8D25"), options.pretty);
|
|
557
560
|
process.exit(1);
|
|
558
561
|
}
|
|
559
562
|
});
|
|
@@ -1168,7 +1171,7 @@ var IssueService = class {
|
|
|
1168
1171
|
return {
|
|
1169
1172
|
id: issueId,
|
|
1170
1173
|
success: false,
|
|
1171
|
-
error: result.
|
|
1174
|
+
error: result.post_error_msg || result.api_error_msg || result.message || result.msg || "\u83B7\u53D6\u5931\u8D25"
|
|
1172
1175
|
};
|
|
1173
1176
|
}
|
|
1174
1177
|
} catch (error) {
|
|
@@ -1420,7 +1423,7 @@ var IssueService = class {
|
|
|
1420
1423
|
);
|
|
1421
1424
|
}
|
|
1422
1425
|
} else {
|
|
1423
|
-
const errorMsg = createResult.
|
|
1426
|
+
const errorMsg = createResult.post_error_msg || createResult.api_error_msg || createResult.message || "\u521B\u5EFA\u5931\u8D25";
|
|
1424
1427
|
logger_default.error(`\u274C \u521B\u5EFA\u5B50\u4EFB\u52A1\u5931\u8D25: ${taskName}`, errorMsg);
|
|
1425
1428
|
result.totalFailed++;
|
|
1426
1429
|
result.failed.push({
|
|
@@ -1628,7 +1631,7 @@ var IssueService = class {
|
|
|
1628
1631
|
);
|
|
1629
1632
|
}
|
|
1630
1633
|
} else {
|
|
1631
|
-
const errorMsg = createResult.
|
|
1634
|
+
const errorMsg = createResult.post_error_msg || createResult.api_error_msg || createResult.message || "\u521B\u5EFA\u5931\u8D25";
|
|
1632
1635
|
logger_default.error(`\u274C \u521B\u5EFA\u5B50\u4EFB\u52A1\u5931\u8D25: ${taskName}`, errorMsg);
|
|
1633
1636
|
result.totalFailed++;
|
|
1634
1637
|
result.failed.push({
|
|
@@ -1926,7 +1929,7 @@ function createIssueCommand() {
|
|
|
1926
1929
|
}
|
|
1927
1930
|
}
|
|
1928
1931
|
} else {
|
|
1929
|
-
outputError(result
|
|
1932
|
+
outputError(extractErrorMessage(result, "\u83B7\u53D6\u95EE\u9898\u5931\u8D25"), options.pretty);
|
|
1930
1933
|
process.exit(1);
|
|
1931
1934
|
}
|
|
1932
1935
|
} else {
|
|
@@ -1947,7 +1950,7 @@ function createIssueCommand() {
|
|
|
1947
1950
|
pretty: options.pretty
|
|
1948
1951
|
});
|
|
1949
1952
|
} else {
|
|
1950
|
-
outputError(result
|
|
1953
|
+
outputError(extractErrorMessage(result, "\u83B7\u53D6\u95EE\u9898\u5931\u8D25"), options.pretty);
|
|
1951
1954
|
process.exit(1);
|
|
1952
1955
|
}
|
|
1953
1956
|
}
|
|
@@ -2037,7 +2040,7 @@ function createIssueCommand() {
|
|
|
2037
2040
|
if (result.success && result.data) {
|
|
2038
2041
|
outputSuccess(result.data, options.pretty);
|
|
2039
2042
|
} else {
|
|
2040
|
-
outputError(result
|
|
2043
|
+
outputError(extractErrorMessage(result, "\u521B\u5EFA\u95EE\u9898\u5931\u8D25"), options.pretty);
|
|
2041
2044
|
process.exit(1);
|
|
2042
2045
|
}
|
|
2043
2046
|
});
|
|
@@ -2063,7 +2066,7 @@ function createIssueCommand() {
|
|
|
2063
2066
|
...options,
|
|
2064
2067
|
host: urlHost || options.host
|
|
2065
2068
|
});
|
|
2066
|
-
const validation = validateCredentials(creds);
|
|
2069
|
+
const validation = validateCredentials(creds, ["token", "host"]);
|
|
2067
2070
|
if (!validation.valid) {
|
|
2068
2071
|
outputError(`\u7F3A\u5C11\u5FC5\u8981\u53C2\u6570: ${validation.missing.join(", ")}`, options.pretty);
|
|
2069
2072
|
process.exit(1);
|
|
@@ -2156,7 +2159,7 @@ function createIssueCommand() {
|
|
|
2156
2159
|
if (result.success && result.data) {
|
|
2157
2160
|
outputSuccess(result.data, options.pretty);
|
|
2158
2161
|
} else {
|
|
2159
|
-
outputError(result
|
|
2162
|
+
outputError(extractErrorMessage(result, "\u66F4\u65B0\u95EE\u9898\u5931\u8D25"), options.pretty);
|
|
2160
2163
|
process.exit(1);
|
|
2161
2164
|
}
|
|
2162
2165
|
});
|
|
@@ -2181,7 +2184,7 @@ function createIssueCommand() {
|
|
|
2181
2184
|
if (result.success && result.data) {
|
|
2182
2185
|
outputSuccess(result.data, options.pretty);
|
|
2183
2186
|
} else {
|
|
2184
|
-
outputError(result
|
|
2187
|
+
outputError(extractErrorMessage(result, "\u67E5\u8BE2\u5931\u8D25"), options.pretty);
|
|
2185
2188
|
process.exit(1);
|
|
2186
2189
|
}
|
|
2187
2190
|
});
|
|
@@ -2208,7 +2211,7 @@ function createIssueCommand() {
|
|
|
2208
2211
|
if (result.success && result.data) {
|
|
2209
2212
|
outputSuccess(result.data, options.pretty);
|
|
2210
2213
|
} else {
|
|
2211
|
-
outputError(result
|
|
2214
|
+
outputError(extractErrorMessage(result, "\u67E5\u8BE2\u5931\u8D25"), options.pretty);
|
|
2212
2215
|
process.exit(1);
|
|
2213
2216
|
}
|
|
2214
2217
|
});
|
|
@@ -2227,7 +2230,7 @@ function createIssueCommand() {
|
|
|
2227
2230
|
if (result.success) {
|
|
2228
2231
|
outputSuccess(result.data, options.pretty);
|
|
2229
2232
|
} else {
|
|
2230
|
-
outputError(result
|
|
2233
|
+
outputError(extractErrorMessage(result, "\u83B7\u53D6\u5B57\u6BB5\u9009\u9879\u5931\u8D25"), options.pretty);
|
|
2231
2234
|
process.exit(1);
|
|
2232
2235
|
}
|
|
2233
2236
|
});
|
|
@@ -2305,7 +2308,7 @@ function createIssueCommand() {
|
|
|
2305
2308
|
outputSuccess(result.data, options.pretty);
|
|
2306
2309
|
}
|
|
2307
2310
|
} else {
|
|
2308
|
-
outputError(result
|
|
2311
|
+
outputError(extractErrorMessage(result, "\u67E5\u8BE2\u5B50\u4EFB\u52A1\u5931\u8D25"), options.pretty);
|
|
2309
2312
|
process.exit(1);
|
|
2310
2313
|
}
|
|
2311
2314
|
});
|
|
@@ -2361,7 +2364,7 @@ function createIssueCommand() {
|
|
|
2361
2364
|
pretty: options.pretty
|
|
2362
2365
|
});
|
|
2363
2366
|
} else {
|
|
2364
|
-
outputError(result
|
|
2367
|
+
outputError(extractErrorMessage(result, "\u6279\u91CF\u83B7\u53D6\u95EE\u9898\u5931\u8D25"), options.pretty);
|
|
2365
2368
|
process.exit(1);
|
|
2366
2369
|
}
|
|
2367
2370
|
});
|
|
@@ -2467,7 +2470,7 @@ function createIssueCommand() {
|
|
|
2467
2470
|
pretty: options.pretty
|
|
2468
2471
|
});
|
|
2469
2472
|
} else {
|
|
2470
|
-
outputError(result
|
|
2473
|
+
outputError(extractErrorMessage(result, "\u540C\u6B65\u5B50\u5355\u5931\u8D25"), options.pretty);
|
|
2471
2474
|
process.exit(1);
|
|
2472
2475
|
}
|
|
2473
2476
|
});
|
|
@@ -2578,7 +2581,7 @@ function createIssueCommand() {
|
|
|
2578
2581
|
pretty: options.pretty
|
|
2579
2582
|
});
|
|
2580
2583
|
} else {
|
|
2581
|
-
outputError(result
|
|
2584
|
+
outputError(extractErrorMessage(result, "\u6279\u91CF\u521B\u5EFA\u5931\u8D25"), options.pretty);
|
|
2582
2585
|
process.exit(1);
|
|
2583
2586
|
}
|
|
2584
2587
|
});
|
|
@@ -2707,7 +2710,7 @@ function createTimeCommand() {
|
|
|
2707
2710
|
logger_default.info("\u67E5\u8BE2\u6240\u6709\u9879\u76EE\u7684\u5DE5\u65F6...");
|
|
2708
2711
|
const projectsResult = await userService.getProjects(creds.token, creds.host);
|
|
2709
2712
|
if (!projectsResult.success || !projectsResult.data) {
|
|
2710
|
-
outputError(projectsResult
|
|
2713
|
+
outputError(extractErrorMessage(projectsResult, "\u83B7\u53D6\u9879\u76EE\u5217\u8868\u5931\u8D25"), options.pretty);
|
|
2711
2714
|
process.exit(1);
|
|
2712
2715
|
}
|
|
2713
2716
|
const projects = projectsResult.data;
|
|
@@ -2784,14 +2787,14 @@ function createTimeCommand() {
|
|
|
2784
2787
|
if (result.success && result.data) {
|
|
2785
2788
|
outputSuccess(result.data, options.pretty);
|
|
2786
2789
|
} else {
|
|
2787
|
-
outputError(result
|
|
2790
|
+
outputError(extractErrorMessage(result, "\u67E5\u8BE2\u5DE5\u65F6\u5931\u8D25"), options.pretty);
|
|
2788
2791
|
process.exit(1);
|
|
2789
2792
|
}
|
|
2790
2793
|
}
|
|
2791
2794
|
});
|
|
2792
|
-
timeCmd.command("create").description("\u521B\u5EFA\u5DE5\u65F6\u6761\u76EE").requiredOption("--issue <id>", "\u95EE\u9898 ID").requiredOption("--days <days>", "\u5DE5\u65F6\uFF08\u5929\uFF09").requiredOption("--activity <id>", "\u6D3B\u52A8\u7C7B\u578B ID\uFF08\u4F7F\u7528 pm-cli time options \u83B7\u53D6\u53EF\u7528\u503C\uFF09").option("--date <date>", "\u65E5\u671F (YYYY-MM-DD)\uFF0C\u9ED8\u8BA4\u4ECA\u5929").option("--comments <comments>", "\u5907\u6CE8").option("--token <token>", "API Token").option("--host <host>", "PM \u4E3B\u673A\u5730\u5740").option("--project <project>", "\u9879\u76EE\u540D\u79F0").option("--profile <name>", "\u4F7F\u7528\u914D\u7F6E profile").option("--config <path>", "\u81EA\u5B9A\u4E49\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84").option("--pretty", "\u683C\u5F0F\u5316\u8F93\u51FA JSON\uFF08\u9ED8\u8BA4\u538B\u7F29\uFF09").action(async (options) => {
|
|
2795
|
+
timeCmd.command("create").description("\u521B\u5EFA\u5DE5\u65F6\u6761\u76EE").requiredOption("--issue <id>", "\u95EE\u9898 ID").requiredOption("--days <days>", "\u5DE5\u65F6\uFF08\u5929\uFF09").requiredOption("--activity <id>", "\u6D3B\u52A8\u7C7B\u578B ID\uFF08\u4F7F\u7528 pm-cli time options \u83B7\u53D6\u53EF\u7528\u503C\uFF09").option("--date <date>", "\u65E5\u671F (YYYY-MM-DD)\uFF0C\u9ED8\u8BA4\u4ECA\u5929").option("--comments <comments>", "\u5907\u6CE8").option("--token <token>", "API Token").option("--host <host>", "PM \u4E3B\u673A\u5730\u5740").option("--project <project>", "\u9879\u76EE\u540D\u79F0\uFF08\u53EF\u9009\uFF0C\u4F1A\u81EA\u52A8\u4ECE\u95EE\u9898\u83B7\u53D6\uFF09").option("--profile <name>", "\u4F7F\u7528\u914D\u7F6E profile").option("--config <path>", "\u81EA\u5B9A\u4E49\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84").option("--pretty", "\u683C\u5F0F\u5316\u8F93\u51FA JSON\uFF08\u9ED8\u8BA4\u538B\u7F29\uFF09").action(async (options) => {
|
|
2793
2796
|
const creds = resolveCredentials(options);
|
|
2794
|
-
const validation = validateCredentials(creds);
|
|
2797
|
+
const validation = validateCredentials(creds, ["token", "host"]);
|
|
2795
2798
|
if (!validation.valid) {
|
|
2796
2799
|
outputError(`\u7F3A\u5C11\u5FC5\u8981\u53C2\u6570: ${validation.missing.join(", ")}`, options.pretty);
|
|
2797
2800
|
process.exit(1);
|
|
@@ -2820,10 +2823,25 @@ function createTimeCommand() {
|
|
|
2820
2823
|
outputError("\u65E0\u6548\u7684\u6D3B\u52A8\u7C7B\u578B ID\uFF0C\u4F7F\u7528 pm-cli time options \u83B7\u53D6\u53EF\u7528\u503C", options.pretty);
|
|
2821
2824
|
process.exit(1);
|
|
2822
2825
|
}
|
|
2826
|
+
let projectName = creds.project;
|
|
2827
|
+
if (!projectName) {
|
|
2828
|
+
logger_default.info(`\u672A\u6307\u5B9A\u9879\u76EE\uFF0C\u6B63\u5728\u4ECE\u95EE\u9898 #${issueId} \u83B7\u53D6\u9879\u76EE\u4FE1\u606F...`);
|
|
2829
|
+
const issueResult = await issueService.getIssue(creds.token, creds.host, "", issueId);
|
|
2830
|
+
if (!issueResult.success || !issueResult.data) {
|
|
2831
|
+
outputError(extractErrorMessage(issueResult, `\u83B7\u53D6\u95EE\u9898 #${issueId} \u5931\u8D25\uFF0C\u65E0\u6CD5\u786E\u5B9A\u9879\u76EE`), options.pretty);
|
|
2832
|
+
process.exit(1);
|
|
2833
|
+
}
|
|
2834
|
+
projectName = issueResult.data.project?.name;
|
|
2835
|
+
if (!projectName) {
|
|
2836
|
+
outputError(`\u95EE\u9898 #${issueId} \u6CA1\u6709\u5173\u8054\u7684\u9879\u76EE\u4FE1\u606F`, options.pretty);
|
|
2837
|
+
process.exit(1);
|
|
2838
|
+
}
|
|
2839
|
+
logger_default.info(`\u4ECE\u95EE\u9898\u83B7\u53D6\u5230\u9879\u76EE\u540D\u79F0: ${projectName}`);
|
|
2840
|
+
}
|
|
2823
2841
|
const params = {
|
|
2824
2842
|
token: creds.token,
|
|
2825
2843
|
host: creds.host,
|
|
2826
|
-
project:
|
|
2844
|
+
project: projectName,
|
|
2827
2845
|
issue_id: issueId,
|
|
2828
2846
|
hours: days,
|
|
2829
2847
|
// API 参数名为 hours,但单位是天
|
|
@@ -2840,13 +2858,13 @@ function createTimeCommand() {
|
|
|
2840
2858
|
if (result.success && result.data) {
|
|
2841
2859
|
outputSuccess(result.data, options.pretty);
|
|
2842
2860
|
} else {
|
|
2843
|
-
outputError(result
|
|
2861
|
+
outputError(extractErrorMessage(result, "\u521B\u5EFA\u5DE5\u65F6\u5931\u8D25"), options.pretty);
|
|
2844
2862
|
process.exit(1);
|
|
2845
2863
|
}
|
|
2846
2864
|
});
|
|
2847
|
-
timeCmd.command("update <id>").description("\u66F4\u65B0\u5DE5\u65F6\u6761\u76EE").requiredOption("--issue <id>", "\u95EE\u9898 ID\uFF08\u5FC5\u586B\uFF09").requiredOption("--days <days>", "\u5DE5\u65F6\uFF08\u5929\uFF09\uFF08\u5FC5\u586B\uFF09").requiredOption("--activity <id>", "\u6D3B\u52A8\u7C7B\u578B ID\uFF08\u5FC5\u586B\uFF09").requiredOption("--date <date>", "\u65E5\u671F (YYYY-MM-DD)\uFF08\u5FC5\u586B\uFF09").option("--comments <comments>", "\u5907\u6CE8").option("--token <token>", "API Token").option("--host <host>", "PM \u4E3B\u673A\u5730\u5740").option("--project <project>", "\u9879\u76EE\u540D\u79F0").option("--profile <name>", "\u4F7F\u7528\u914D\u7F6E profile").option("--config <path>", "\u81EA\u5B9A\u4E49\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84").option("--pretty", "\u683C\u5F0F\u5316\u8F93\u51FA JSON\uFF08\u9ED8\u8BA4\u538B\u7F29\uFF09").action(async (id, options) => {
|
|
2865
|
+
timeCmd.command("update <id>").description("\u66F4\u65B0\u5DE5\u65F6\u6761\u76EE").requiredOption("--issue <id>", "\u95EE\u9898 ID\uFF08\u5FC5\u586B\uFF09").requiredOption("--days <days>", "\u5DE5\u65F6\uFF08\u5929\uFF09\uFF08\u5FC5\u586B\uFF09").requiredOption("--activity <id>", "\u6D3B\u52A8\u7C7B\u578B ID\uFF08\u5FC5\u586B\uFF09").requiredOption("--date <date>", "\u65E5\u671F (YYYY-MM-DD)\uFF08\u5FC5\u586B\uFF09").option("--comments <comments>", "\u5907\u6CE8").option("--token <token>", "API Token").option("--host <host>", "PM \u4E3B\u673A\u5730\u5740").option("--project <project>", "\u9879\u76EE\u540D\u79F0\uFF08\u53EF\u9009\uFF0C\u4F1A\u81EA\u52A8\u4ECE\u95EE\u9898\u83B7\u53D6\uFF09").option("--profile <name>", "\u4F7F\u7528\u914D\u7F6E profile").option("--config <path>", "\u81EA\u5B9A\u4E49\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84").option("--pretty", "\u683C\u5F0F\u5316\u8F93\u51FA JSON\uFF08\u9ED8\u8BA4\u538B\u7F29\uFF09").action(async (id, options) => {
|
|
2848
2866
|
const creds = resolveCredentials(options);
|
|
2849
|
-
const validation = validateCredentials(creds);
|
|
2867
|
+
const validation = validateCredentials(creds, ["token", "host"]);
|
|
2850
2868
|
if (!validation.valid) {
|
|
2851
2869
|
outputError(`\u7F3A\u5C11\u5FC5\u8981\u53C2\u6570: ${validation.missing.join(", ")}`, options.pretty);
|
|
2852
2870
|
process.exit(1);
|
|
@@ -2870,10 +2888,25 @@ function createTimeCommand() {
|
|
|
2870
2888
|
outputError("\u65E0\u6548\u7684\u95EE\u9898 ID", options.pretty);
|
|
2871
2889
|
process.exit(1);
|
|
2872
2890
|
}
|
|
2891
|
+
let projectName = creds.project;
|
|
2892
|
+
if (!projectName) {
|
|
2893
|
+
logger_default.info(`\u672A\u6307\u5B9A\u9879\u76EE\uFF0C\u6B63\u5728\u4ECE\u95EE\u9898 #${issueId} \u83B7\u53D6\u9879\u76EE\u4FE1\u606F...`);
|
|
2894
|
+
const issueResult = await issueService.getIssue(creds.token, creds.host, "", issueId);
|
|
2895
|
+
if (!issueResult.success || !issueResult.data) {
|
|
2896
|
+
outputError(extractErrorMessage(issueResult, `\u83B7\u53D6\u95EE\u9898 #${issueId} \u5931\u8D25\uFF0C\u65E0\u6CD5\u786E\u5B9A\u9879\u76EE`), options.pretty);
|
|
2897
|
+
process.exit(1);
|
|
2898
|
+
}
|
|
2899
|
+
projectName = issueResult.data.project?.name;
|
|
2900
|
+
if (!projectName) {
|
|
2901
|
+
outputError(`\u95EE\u9898 #${issueId} \u6CA1\u6709\u5173\u8054\u7684\u9879\u76EE\u4FE1\u606F`, options.pretty);
|
|
2902
|
+
process.exit(1);
|
|
2903
|
+
}
|
|
2904
|
+
logger_default.info(`\u4ECE\u95EE\u9898\u83B7\u53D6\u5230\u9879\u76EE\u540D\u79F0: ${projectName}`);
|
|
2905
|
+
}
|
|
2873
2906
|
const params = {
|
|
2874
2907
|
token: creds.token,
|
|
2875
2908
|
host: creds.host,
|
|
2876
|
-
project:
|
|
2909
|
+
project: projectName,
|
|
2877
2910
|
id: timeEntryId,
|
|
2878
2911
|
// 工时 ID
|
|
2879
2912
|
issue_id: issueId,
|
|
@@ -2894,7 +2927,7 @@ function createTimeCommand() {
|
|
|
2894
2927
|
if (result.success && result.data) {
|
|
2895
2928
|
outputSuccess(result.data, options.pretty);
|
|
2896
2929
|
} else {
|
|
2897
|
-
outputError(result
|
|
2930
|
+
outputError(extractErrorMessage(result, "\u66F4\u65B0\u5DE5\u65F6\u5931\u8D25"), options.pretty);
|
|
2898
2931
|
process.exit(1);
|
|
2899
2932
|
}
|
|
2900
2933
|
});
|
|
@@ -2918,22 +2951,42 @@ function createTimeCommand() {
|
|
|
2918
2951
|
if (result.success) {
|
|
2919
2952
|
outputSuccess({ message: "\u5DE5\u65F6\u6761\u76EE\u5DF2\u5220\u9664", id: timeEntryId }, options.pretty);
|
|
2920
2953
|
} else {
|
|
2921
|
-
outputError(result
|
|
2954
|
+
outputError(extractErrorMessage(result, "\u5220\u9664\u5DE5\u65F6\u5931\u8D25"), options.pretty);
|
|
2922
2955
|
process.exit(1);
|
|
2923
2956
|
}
|
|
2924
2957
|
});
|
|
2925
|
-
timeCmd.command("options").description("\u83B7\u53D6\u5DE5\u65F6\u6761\u76EE\u9009\u9879\uFF08\u6D3B\u52A8\u7C7B\u578B\u5217\u8868\u7B49\uFF09").option("--issue <id>", "\u95EE\u9898 ID\uFF08\u53EF\u9009\uFF0C\u7528\u4E8E\u83B7\u53D6\u7279\u5B9A\u95EE\u9898\u7684\u5DE5\u65F6\u9009\u9879\uFF09").option("--token <token>", "API Token").option("--host <host>", "PM \u4E3B\u673A\u5730\u5740").option("--project <project>", "\u9879\u76EE\u540D\u79F0").option("--profile <name>", "\u4F7F\u7528\u914D\u7F6E profile").option("--config <path>", "\u81EA\u5B9A\u4E49\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84").option("--pretty", "\u683C\u5F0F\u5316\u8F93\u51FA JSON\uFF08\u9ED8\u8BA4\u538B\u7F29\uFF09").action(async (options) => {
|
|
2958
|
+
timeCmd.command("options").description("\u83B7\u53D6\u5DE5\u65F6\u6761\u76EE\u9009\u9879\uFF08\u6D3B\u52A8\u7C7B\u578B\u5217\u8868\u7B49\uFF09").option("--issue <id>", "\u95EE\u9898 ID\uFF08\u53EF\u9009\uFF0C\u7528\u4E8E\u83B7\u53D6\u7279\u5B9A\u95EE\u9898\u7684\u5DE5\u65F6\u9009\u9879\uFF0C\u540C\u65F6\u53EF\u81EA\u52A8\u63A8\u65AD\u9879\u76EE\uFF09").option("--token <token>", "API Token").option("--host <host>", "PM \u4E3B\u673A\u5730\u5740").option("--project <project>", "\u9879\u76EE\u540D\u79F0\uFF08\u53EF\u9009\uFF0C\u53EF\u4ECE\u95EE\u9898\u81EA\u52A8\u83B7\u53D6\uFF09").option("--profile <name>", "\u4F7F\u7528\u914D\u7F6E profile").option("--config <path>", "\u81EA\u5B9A\u4E49\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84").option("--pretty", "\u683C\u5F0F\u5316\u8F93\u51FA JSON\uFF08\u9ED8\u8BA4\u538B\u7F29\uFF09").action(async (options) => {
|
|
2926
2959
|
const creds = resolveCredentials(options);
|
|
2927
|
-
const validation = validateCredentials(creds);
|
|
2960
|
+
const validation = validateCredentials(creds, ["token", "host"]);
|
|
2928
2961
|
if (!validation.valid) {
|
|
2929
2962
|
outputError(`\u7F3A\u5C11\u5FC5\u8981\u53C2\u6570: ${validation.missing.join(", ")}`, options.pretty);
|
|
2930
2963
|
process.exit(1);
|
|
2931
2964
|
}
|
|
2932
2965
|
const issueId = options.issue ? parseInt(options.issue.replace(/^#/, ""), 10) : void 0;
|
|
2966
|
+
let projectName = creds.project;
|
|
2967
|
+
if (!projectName) {
|
|
2968
|
+
if (issueId) {
|
|
2969
|
+
logger_default.info(`\u672A\u6307\u5B9A\u9879\u76EE\uFF0C\u6B63\u5728\u4ECE\u95EE\u9898 #${issueId} \u83B7\u53D6\u9879\u76EE\u4FE1\u606F...`);
|
|
2970
|
+
const issueResult = await issueService.getIssue(creds.token, creds.host, "", issueId);
|
|
2971
|
+
if (!issueResult.success || !issueResult.data) {
|
|
2972
|
+
outputError(extractErrorMessage(issueResult, `\u83B7\u53D6\u95EE\u9898 #${issueId} \u5931\u8D25\uFF0C\u65E0\u6CD5\u786E\u5B9A\u9879\u76EE`), options.pretty);
|
|
2973
|
+
process.exit(1);
|
|
2974
|
+
}
|
|
2975
|
+
projectName = issueResult.data.project?.name;
|
|
2976
|
+
if (!projectName) {
|
|
2977
|
+
outputError(`\u95EE\u9898 #${issueId} \u6CA1\u6709\u5173\u8054\u7684\u9879\u76EE\u4FE1\u606F`, options.pretty);
|
|
2978
|
+
process.exit(1);
|
|
2979
|
+
}
|
|
2980
|
+
logger_default.info(`\u4ECE\u95EE\u9898\u83B7\u53D6\u5230\u9879\u76EE\u540D\u79F0: ${projectName}`);
|
|
2981
|
+
} else {
|
|
2982
|
+
outputError("\u7F3A\u5C11\u9879\u76EE\u540D\u79F0\uFF0C\u8BF7\u4F7F\u7528 --project \u6307\u5B9A\u6216\u901A\u8FC7 --issue \u81EA\u52A8\u83B7\u53D6", options.pretty);
|
|
2983
|
+
process.exit(1);
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2933
2986
|
const result = await timeEntryService.getTimeEntryOptions(
|
|
2934
2987
|
creds.token,
|
|
2935
2988
|
creds.host,
|
|
2936
|
-
|
|
2989
|
+
projectName,
|
|
2937
2990
|
issueId
|
|
2938
2991
|
);
|
|
2939
2992
|
if (result.success && result.data) {
|
|
@@ -2945,7 +2998,7 @@ function createTimeCommand() {
|
|
|
2945
2998
|
outputSuccess(result.data, options.pretty);
|
|
2946
2999
|
}
|
|
2947
3000
|
} else {
|
|
2948
|
-
outputError(result
|
|
3001
|
+
outputError(extractErrorMessage(result, "\u83B7\u53D6\u9009\u9879\u5931\u8D25"), options.pretty);
|
|
2949
3002
|
process.exit(1);
|
|
2950
3003
|
}
|
|
2951
3004
|
});
|
|
@@ -2987,7 +3040,7 @@ function createTimeCommand() {
|
|
|
2987
3040
|
}
|
|
2988
3041
|
const projectsResult = await userService.getProjects(creds.token, creds.host);
|
|
2989
3042
|
if (!projectsResult.success || !projectsResult.data) {
|
|
2990
|
-
outputError(projectsResult
|
|
3043
|
+
outputError(extractErrorMessage(projectsResult, "\u83B7\u53D6\u9879\u76EE\u5217\u8868\u5931\u8D25"), options.pretty);
|
|
2991
3044
|
process.exit(1);
|
|
2992
3045
|
}
|
|
2993
3046
|
const projects = projectsResult.data;
|
|
@@ -3061,7 +3114,7 @@ function createProjectCommand() {
|
|
|
3061
3114
|
if (result.success && result.data) {
|
|
3062
3115
|
outputSuccess(result.data, options.pretty);
|
|
3063
3116
|
} else {
|
|
3064
|
-
outputError(result
|
|
3117
|
+
outputError(extractErrorMessage(result, "\u83B7\u53D6\u9879\u76EE\u5217\u8868\u5931\u8D25"), options.pretty);
|
|
3065
3118
|
process.exit(1);
|
|
3066
3119
|
}
|
|
3067
3120
|
});
|
|
@@ -3080,7 +3133,7 @@ function createProjectCommand() {
|
|
|
3080
3133
|
if (result.success && result.data) {
|
|
3081
3134
|
outputSuccess(result.data, options.pretty);
|
|
3082
3135
|
} else {
|
|
3083
|
-
outputError(result
|
|
3136
|
+
outputError(extractErrorMessage(result, "\u83B7\u53D6\u7528\u6237\u5217\u8868\u5931\u8D25"), options.pretty);
|
|
3084
3137
|
process.exit(1);
|
|
3085
3138
|
}
|
|
3086
3139
|
});
|
|
@@ -3095,7 +3148,7 @@ function createProjectCommand() {
|
|
|
3095
3148
|
if (result.success) {
|
|
3096
3149
|
outputSuccess(result.data, options.pretty);
|
|
3097
3150
|
} else {
|
|
3098
|
-
outputError(result
|
|
3151
|
+
outputError(extractErrorMessage(result, "\u83B7\u53D6\u4E3B\u673A\u4FE1\u606F\u5931\u8D25"), options.pretty);
|
|
3099
3152
|
process.exit(1);
|
|
3100
3153
|
}
|
|
3101
3154
|
});
|