|
1 | 1 | import * as vscode from "vscode";
|
2 | 2 | import { BaseCommand } from "./BaseCommand";
|
3 |
| -import { NotificationHandler } from "../utils/NotificationHandler"; |
4 |
| -import { ProgressHandler } from "../utils/ProgressHandler"; |
5 |
| -import { LocalizationManager } from "../utils/LocalizationManager"; |
6 | 3 | import { WeeklyReportPanel } from "../webview/WeeklyReportPanel";
|
7 |
| -import { SCMFactory } from "../scm/SCMProvider"; |
8 |
| -import { AIProviderFactory } from "../ai/AIProviderFactory"; |
9 |
| -import { exec } from "child_process"; |
10 |
| -import { ConfigurationManager } from "../config/ConfigurationManager"; |
11 | 4 |
|
12 | 5 | export class GenerateWeeklyReportCommand extends BaseCommand {
|
13 |
| - async validateConfig(): Promise<boolean> { |
14 |
| - const scmProvider = await SCMFactory.detectSCM(); |
15 |
| - if (!scmProvider) { |
16 |
| - const locManager = LocalizationManager.getInstance(); |
17 |
| - await NotificationHandler.error( |
18 |
| - locManager.getMessage("scm.not.detected") |
19 |
| - ); |
20 |
| - return false; |
21 |
| - } |
22 |
| - return true; |
23 |
| - } |
24 |
| - |
25 |
| - async getPeriod(): Promise<string | undefined> { |
26 |
| - const options = ["本周", "上一周", "上两周"]; |
27 |
| - const selection = await vscode.window.showQuickPick(options, { |
28 |
| - placeHolder: "选择一个时间段", |
29 |
| - }); |
30 |
| - |
31 |
| - switch (selection) { |
32 |
| - case "本周": |
33 |
| - return "1 week ago"; |
34 |
| - case "上一周": |
35 |
| - return "2 weeks ago"; |
36 |
| - case "上两周": |
37 |
| - return "3 weeks ago"; |
38 |
| - default: |
39 |
| - return undefined; |
40 |
| - } |
41 |
| - } |
42 |
| - |
43 | 6 | async execute(): Promise<void> {
|
44 |
| - try { |
45 |
| - const period = await this.getPeriod(); |
46 |
| - if (!period) { |
47 |
| - return; |
48 |
| - } |
49 |
| - |
50 |
| - await ProgressHandler.withProgress( |
51 |
| - LocalizationManager.getInstance().getMessage("weeklyReport.generating"), |
52 |
| - async () => { |
53 |
| - const scmProvider = await SCMFactory.detectSCM(); |
54 |
| - if (!scmProvider) { |
55 |
| - await NotificationHandler.error( |
56 |
| - LocalizationManager.getInstance().getMessage("scm.not.detected") |
57 |
| - ); |
58 |
| - return; |
59 |
| - } |
60 |
| - |
61 |
| - const config = ConfigurationManager.getInstance(); |
62 |
| - const configuration = config.getConfiguration(); |
63 |
| - |
64 |
| - // 检查是否已配置 AI 提供商和模型 |
65 |
| - let provider = configuration.base.provider; |
66 |
| - let model = configuration.base.model; |
67 |
| - |
68 |
| - const commits = await this.getCommits(period); |
69 |
| - const aiProvider = AIProviderFactory.getProvider("ZHIPUAI"); |
70 |
| - const response = await aiProvider.generateWeeklyReport(commits); |
71 |
| - |
72 |
| - if (response?.content) { |
73 |
| - vscode.window.showInformationMessage("周报生成成功"); |
74 |
| - WeeklyReportPanel.createOrShow(this.context.extensionUri); |
75 |
| - WeeklyReportPanel.currentPanel?._panel.webview.postMessage({ |
76 |
| - command: "report", |
77 |
| - data: response.content, |
78 |
| - }); |
79 |
| - } else { |
80 |
| - vscode.window.showErrorMessage("周报生成失败"); |
81 |
| - } |
82 |
| - } |
83 |
| - ); |
84 |
| - } catch (error) { |
85 |
| - if (error instanceof Error) { |
86 |
| - await NotificationHandler.error( |
87 |
| - LocalizationManager.getInstance().format( |
88 |
| - "weeklyReport.generation.failed", |
89 |
| - error.message |
90 |
| - ) |
91 |
| - ); |
92 |
| - } |
93 |
| - } |
94 |
| - } |
95 |
| - |
96 |
| - private async getCommits(period: string): Promise<string[]> { |
97 |
| - return new Promise((resolve, reject) => { |
98 |
| - const workspaceFolders = vscode.workspace.workspaceFolders; |
99 |
| - if (!workspaceFolders || workspaceFolders.length === 0) { |
100 |
| - return reject("没有打开的工作区"); |
101 |
| - } |
102 |
| - |
103 |
| - const command = `git log --since="${period}" --pretty=format:"%h - %an, %ar : %s"`; |
104 |
| - exec( |
105 |
| - command, |
106 |
| - { cwd: workspaceFolders[0].uri.fsPath }, |
107 |
| - (error, stdout, stderr) => { |
108 |
| - if (error) { |
109 |
| - reject(`获取commit历史记录失败: ${stderr}`); |
110 |
| - } else { |
111 |
| - resolve(stdout.split("\n")); |
112 |
| - } |
113 |
| - } |
114 |
| - ); |
115 |
| - }); |
| 7 | + // 只负责打开WebView面板 |
| 8 | + WeeklyReportPanel.createOrShow(this.context.extensionUri); |
116 | 9 | }
|
117 | 10 | }
|
0 commit comments