@@ -5,6 +5,9 @@ import { ProgressHandler } from "../utils/ProgressHandler";
5
5
import { LocalizationManager } from "../utils/LocalizationManager" ;
6
6
import { WeeklyReportPanel } from "../webview/WeeklyReportPanel" ;
7
7
import { SCMFactory } from "../scm/SCMProvider" ;
8
+ import { AIProviderFactory } from "../ai/AIProviderFactory" ;
9
+ import { exec } from "child_process" ;
10
+ import { ConfigurationManager } from "../config/ConfigurationManager" ;
8
11
9
12
export class GenerateWeeklyReportCommand extends BaseCommand {
10
13
async validateConfig ( ) : Promise < boolean > {
@@ -19,16 +22,63 @@ export class GenerateWeeklyReportCommand extends BaseCommand {
19
22
return true ;
20
23
}
21
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
+
22
43
async execute ( ) : Promise < void > {
23
44
try {
24
- if ( ! ( await this . validateConfig ( ) ) ) {
45
+ const period = await this . getPeriod ( ) ;
46
+ if ( ! period ) {
25
47
return ;
26
48
}
27
49
28
50
await ProgressHandler . withProgress (
29
51
LocalizationManager . getInstance ( ) . getMessage ( "weeklyReport.generating" ) ,
30
52
async ( ) => {
31
- WeeklyReportPanel . createOrShow ( this . context . extensionUri ) ;
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
+ }
32
82
}
33
83
) ;
34
84
} catch ( error ) {
@@ -42,4 +92,26 @@ export class GenerateWeeklyReportCommand extends BaseCommand {
42
92
}
43
93
}
44
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
+ } ) ;
116
+ }
45
117
}
0 commit comments