g2log 1.4.0 → 1.4.1
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/README.md +13 -5
- package/git-user-log.js +110 -123
- package/package.json +5 -2
package/README.md
CHANGED
@@ -66,13 +66,20 @@ npx g2log [--since="2023-01-01"] [--until="2023-12-31"] [选项]
|
|
66
66
|
|
67
67
|
### 命令行参数
|
68
68
|
|
69
|
+
时间参数:
|
69
70
|
- `--since="YYYY-MM-DD"` - 起始日期(如未指定,使用配置中的默认值)
|
70
71
|
- `--until="YYYY-MM-DD"` - 结束日期(如未指定,使用配置中的默认值)
|
71
|
-
- `--
|
72
|
-
- `--output="文件路径"` - 将输出保存到指定文件
|
72
|
+
- `--days=N` - 查询最近N天的记录
|
73
73
|
|
74
|
-
|
74
|
+
显示设置:
|
75
|
+
- `--no-color` - 禁用彩色输出
|
76
|
+
- `--save` 或 `--output="文件路径"` - 将输出保存到文件
|
77
|
+
- `--debug` - 显示调试信息
|
78
|
+
- `--show-prompt` - 显示完整的prompt内容
|
79
|
+
- `--version` - 显示当前版本号
|
75
80
|
|
81
|
+
配置管理命令:
|
82
|
+
- `--config` - 启动交互式配置向导
|
76
83
|
- `--set-api-key="KEY"` - 设置API密钥
|
77
84
|
- `--set-ai-model="MODEL"` - 设置AI模型(默认: deepseek-chat)
|
78
85
|
- `--set-api-provider="PROVIDER"` - 设置API提供商(deepseek或openai)
|
@@ -85,6 +92,7 @@ npx g2log [--since="2023-01-01"] [--until="2023-12-31"] [选项]
|
|
85
92
|
- `--set-prompt-template="file.txt"` - 从文件设置AI总结的prompt模板
|
86
93
|
- `--reset-prompt-template` - 重置AI总结的prompt模板为默认值
|
87
94
|
- `--fix-config` - 修复配置文件格式问题
|
95
|
+
- `--uninstall` - 删除g2log配置文件
|
88
96
|
- `--help` - 显示帮助信息
|
89
97
|
|
90
98
|
### 配置文件
|
@@ -95,7 +103,7 @@ npx g2log [--since="2023-01-01"] [--until="2023-12-31"] [选项]
|
|
95
103
|
{
|
96
104
|
"api_key": "your-api-key-here",
|
97
105
|
"default_author": "张三",
|
98
|
-
"default_since": "
|
106
|
+
"default_since": "7 days ago",
|
99
107
|
"default_until": "today",
|
100
108
|
"model": "deepseek-chat",
|
101
109
|
"api_base_url": "https://api.deepseek.com",
|
@@ -104,7 +112,7 @@ npx g2log [--since="2023-01-01"] [--until="2023-12-31"] [选项]
|
|
104
112
|
"前端": "/path/to/frontend-project",
|
105
113
|
"后端": "/path/to/backend-project"
|
106
114
|
},
|
107
|
-
"prompt_template": "请根据下面的Git提交记录,用3-5
|
115
|
+
"prompt_template": "请根据下面的Git提交记录,用3-5句话简洁地总结一天的工作内容。\n\n以下是Git提交记录:\n\n{{GIT_LOGS}}\n\n要求:\n1. 按项目和日期组织内容\n2. 每个项目每天的工作内容用3-5句话概括\n3. 使用清晰、专业但不晦涩的语言\n4. 突出重要的功能开发、问题修复和优化改进\n5. 适合放入工作日报的简洁描述\n6. 输出格式为:【日期】:\n 【项目名称】- 【工作内容概述】\n 【项目名称】- 【工作内容概述】\n7. 回复不要出现多余的内容,非必要不要用markdown格式"
|
108
116
|
}
|
109
117
|
```
|
110
118
|
|
package/git-user-log.js
CHANGED
@@ -17,6 +17,7 @@ const fs = require('fs');
|
|
17
17
|
const https = require('https');
|
18
18
|
const os = require('os');
|
19
19
|
const readline = require('readline');
|
20
|
+
const ora = require('ora');
|
20
21
|
|
21
22
|
// 检测是否通过npx运行
|
22
23
|
const isRunningWithNpx = process.env.npm_lifecycle_event === 'npx' ||
|
@@ -375,63 +376,41 @@ function fixConfigFile() {
|
|
375
376
|
// 显示帮助
|
376
377
|
function showHelp() {
|
377
378
|
console.log(`
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
--
|
387
|
-
|
388
|
-
|
389
|
-
--
|
390
|
-
--
|
391
|
-
|
392
|
-
|
393
|
-
--
|
394
|
-
|
395
|
-
|
396
|
-
--
|
397
|
-
--
|
398
|
-
--set-
|
399
|
-
--
|
400
|
-
--
|
401
|
-
--
|
402
|
-
--
|
403
|
-
|
404
|
-
|
405
|
-
--
|
406
|
-
--
|
407
|
-
--set-prompt-template="file.txt" 从文件设置AI总结的prompt模板
|
408
|
-
--reset-prompt-template 重置AI总结的prompt模板为默认值
|
409
|
-
--fix-config 修复配置文件格式问题
|
410
|
-
--uninstall 删除g2log配置文件 (~/.git-user-log-config.json)
|
411
|
-
--help 显示帮助信息
|
412
|
-
|
413
|
-
${colorize('📝 示例:', 'cyan')}
|
414
|
-
# 使用配置的默认值生成今日工作总结 (处理配置中的所有仓库)
|
415
|
-
g2log
|
416
|
-
|
417
|
-
# 指定时间范围
|
418
|
-
g2log --since="2023-01-01" --until="2023-12-31"
|
419
|
-
|
420
|
-
# 使用本地仓库
|
421
|
-
g2log --local
|
422
|
-
|
423
|
-
# 强制启用颜色显示(在使用管道或重定向时有用)
|
424
|
-
g2log --color | less -R
|
425
|
-
|
426
|
-
# 启动交互式配置向导
|
379
|
+
使用方法: g2log [选项]
|
380
|
+
|
381
|
+
时间参数:
|
382
|
+
--since <date> 开始日期 (默认: 7天前)
|
383
|
+
--until <date> 结束日期 (默认: 今天)
|
384
|
+
--days <number> 查询最近n天的记录 (默认: 7)
|
385
|
+
|
386
|
+
显示设置:
|
387
|
+
--no-color 禁用彩色输出
|
388
|
+
--save 保存结果到文件
|
389
|
+
--debug 显示调试信息
|
390
|
+
--show-prompt 显示完整的prompt内容
|
391
|
+
--version 显示当前版本号
|
392
|
+
|
393
|
+
配置管理:
|
394
|
+
--config 启动交互式配置向导
|
395
|
+
--set-api-key 设置API密钥
|
396
|
+
--set-api-provider 设置API提供商 (OpenAI/DeepSeek)
|
397
|
+
--set-api-base-url 设置API基础URL
|
398
|
+
--set-ai-model 设置AI模型
|
399
|
+
--set-default-author 设置默认作者
|
400
|
+
--add-repo 添加仓库配置
|
401
|
+
--remove-repo 移除仓库配置
|
402
|
+
--list-repos 列出所有配置的仓库
|
403
|
+
--uninstall 删除g2log配置文件 (~/.git-user-log-config.json)
|
404
|
+
|
405
|
+
示例:
|
406
|
+
g2log --since "2024-01-01" --until "2024-01-31"
|
407
|
+
g2log --days 30
|
427
408
|
g2log --config
|
428
|
-
|
429
|
-
|
430
|
-
g2log --
|
431
|
-
g2log --
|
432
|
-
g2log --
|
433
|
-
g2log --set-api-url="https://api.openai.com"
|
434
|
-
g2log --add-repo="frontend" --path="/path/to/frontend-project"
|
409
|
+
g2log --set-api-key "your-api-key"
|
410
|
+
g2log --add-repo "alias" "path/to/repo"
|
411
|
+
g2log --remove-repo "alias"
|
412
|
+
g2log --list-repos
|
413
|
+
g2log --version
|
435
414
|
`);
|
436
415
|
process.exit(0);
|
437
416
|
}
|
@@ -805,54 +784,54 @@ async function getOpenAIResponse(apiKey, prompt, modelName, apiBaseURL, spinner
|
|
805
784
|
|
806
785
|
// 确定使用http还是https
|
807
786
|
const protocol = urlObj.protocol === 'https:' ? require('https') : require('http');
|
808
|
-
|
809
|
-
|
810
|
-
|
787
|
+
|
788
|
+
// 创建请求
|
789
|
+
const req = protocol.request(options, (res) => {
|
811
790
|
// 检查状态码
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
791
|
+
if (res.statusCode !== 200) {
|
792
|
+
let errorData = '';
|
793
|
+
res.on('data', chunk => {
|
794
|
+
errorData += chunk.toString();
|
795
|
+
});
|
796
|
+
res.on('end', () => {
|
818
797
|
let errorMessage = `OpenAI API请求失败 (${res.statusCode})`;
|
819
|
-
|
820
|
-
|
798
|
+
try {
|
799
|
+
const parsedError = JSON.parse(errorData);
|
821
800
|
errorMessage += `: ${JSON.stringify(parsedError)}`;
|
822
|
-
|
801
|
+
} catch (e) {
|
823
802
|
errorMessage += `: ${errorData}`;
|
824
803
|
}
|
825
804
|
if (spinner) spinner.fail(`❌ ${errorMessage}`);
|
826
805
|
reject(new Error(errorMessage));
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
806
|
+
});
|
807
|
+
return;
|
808
|
+
}
|
809
|
+
|
831
810
|
let fullContent = '';
|
832
|
-
|
833
|
-
|
811
|
+
let buffer = '';
|
812
|
+
|
834
813
|
// 处理数据
|
835
|
-
|
836
|
-
|
837
|
-
|
814
|
+
res.on('data', (chunk) => {
|
815
|
+
// 将新的数据添加到缓冲区
|
816
|
+
buffer += chunk.toString();
|
817
|
+
|
818
|
+
// 尝试从缓冲区中提取完整的SSE消息
|
819
|
+
let match;
|
820
|
+
const dataRegex = /data: (.*?)\n\n/gs;
|
821
|
+
|
822
|
+
while ((match = dataRegex.exec(buffer)) !== null) {
|
823
|
+
const data = match[1];
|
838
824
|
|
839
|
-
//
|
840
|
-
|
841
|
-
const dataRegex = /data: (.*?)\n\n/gs;
|
825
|
+
// 跳过 [DONE] 消息
|
826
|
+
if (data === '[DONE]') continue;
|
842
827
|
|
843
|
-
|
844
|
-
const
|
828
|
+
try {
|
829
|
+
const parsedData = JSON.parse(data);
|
845
830
|
|
846
|
-
// 跳过 [DONE] 消息
|
847
|
-
if (data === '[DONE]') continue;
|
848
|
-
|
849
|
-
try {
|
850
|
-
const parsedData = JSON.parse(data);
|
851
|
-
|
852
831
|
// 获取内容增量
|
853
832
|
if (parsedData.choices &&
|
854
|
-
|
855
|
-
|
833
|
+
parsedData.choices[0] &&
|
834
|
+
parsedData.choices[0].delta &&
|
856
835
|
parsedData.choices[0].delta.content) {
|
857
836
|
const content = parsedData.choices[0].delta.content;
|
858
837
|
fullContent += content;
|
@@ -1003,27 +982,27 @@ async function getDeepSeekResponse(apiKey, prompt, modelName, apiBaseURL, spinne
|
|
1003
982
|
|
1004
983
|
// 直接输出内容增量到控制台
|
1005
984
|
process.stdout.write(content);
|
1006
|
-
}
|
1007
|
-
} catch (err) {
|
1008
|
-
// 忽略解析错误
|
1009
985
|
}
|
986
|
+
} catch (err) {
|
987
|
+
// 忽略解析错误
|
1010
988
|
}
|
1011
|
-
|
1012
|
-
// 保留可能不完整的最后一部分
|
1013
|
-
const lastIndex = buffer.lastIndexOf('\n\n');
|
1014
|
-
if (lastIndex !== -1) {
|
1015
|
-
buffer = buffer.substring(lastIndex + 2);
|
1016
|
-
}
|
1017
|
-
});
|
989
|
+
}
|
1018
990
|
|
991
|
+
// 保留可能不完整的最后一部分
|
992
|
+
const lastIndex = buffer.lastIndexOf('\n\n');
|
993
|
+
if (lastIndex !== -1) {
|
994
|
+
buffer = buffer.substring(lastIndex + 2);
|
995
|
+
}
|
996
|
+
});
|
997
|
+
|
1019
998
|
// 处理结束
|
1020
|
-
|
999
|
+
res.on('end', () => {
|
1021
1000
|
if (spinner) spinner.stop('✅ AI响应已接收');
|
1022
1001
|
console.log(); // 添加换行符
|
1023
1002
|
resolve(fullContent);
|
1024
|
-
});
|
1025
1003
|
});
|
1026
|
-
|
1004
|
+
});
|
1005
|
+
|
1027
1006
|
// 处理请求错误
|
1028
1007
|
req.on('error', (error) => {
|
1029
1008
|
if (spinner) spinner.fail(`❌ DeepSeek API网络错误: ${error.message}`);
|
@@ -1032,7 +1011,7 @@ async function getDeepSeekResponse(apiKey, prompt, modelName, apiBaseURL, spinne
|
|
1032
1011
|
|
1033
1012
|
// 发送请求体
|
1034
1013
|
req.write(JSON.stringify(data));
|
1035
|
-
|
1014
|
+
req.end();
|
1036
1015
|
} catch (error) {
|
1037
1016
|
if (spinner) spinner.fail(`❌ DeepSeek API错误: ${error.message}`);
|
1038
1017
|
reject(error);
|
@@ -1488,15 +1467,35 @@ async function setupConfigInteractive() {
|
|
1488
1467
|
|
1489
1468
|
// 主函数
|
1490
1469
|
async function getGitLogs() {
|
1470
|
+
const args = parseArgs();
|
1471
|
+
|
1472
|
+
// 显示帮助信息
|
1473
|
+
if (args['help']) {
|
1474
|
+
showHelp();
|
1475
|
+
return;
|
1476
|
+
}
|
1477
|
+
|
1478
|
+
// 显示版本信息
|
1479
|
+
if (args['version']) {
|
1480
|
+
const packageJson = require('./package.json');
|
1481
|
+
console.log(`g2log version ${packageJson.version}`);
|
1482
|
+
return;
|
1483
|
+
}
|
1484
|
+
|
1485
|
+
// 删除配置文件
|
1486
|
+
if (args['uninstall']) {
|
1487
|
+
const spinner = ora('正在删除配置文件...').start();
|
1488
|
+
const success = removeConfigFile();
|
1489
|
+
if (success) {
|
1490
|
+
spinner.succeed('配置文件已删除,如需完全卸载请运行: npm uninstall -g g2log');
|
1491
|
+
} else {
|
1492
|
+
spinner.fail('配置文件删除失败,可能文件不存在或无权限访问');
|
1493
|
+
}
|
1494
|
+
return;
|
1495
|
+
}
|
1496
|
+
|
1491
1497
|
try {
|
1492
1498
|
const spinner = createSpinner();
|
1493
|
-
const args = parseArgs();
|
1494
|
-
|
1495
|
-
// 显示帮助信息
|
1496
|
-
if (args.help) {
|
1497
|
-
showHelp();
|
1498
|
-
return;
|
1499
|
-
}
|
1500
1499
|
|
1501
1500
|
// 检查是否要显示自定义配置向导
|
1502
1501
|
if (args.config) {
|
@@ -1562,18 +1561,6 @@ async function getGitLogs() {
|
|
1562
1561
|
// 加载配置(在配置检查和可能的设置之后)
|
1563
1562
|
const config = loadConfig();
|
1564
1563
|
|
1565
|
-
// 删除配置文件
|
1566
|
-
if (args['uninstall']) {
|
1567
|
-
const uninstallSpinner = spinner.start('🗑️ 正在删除g2log配置文件...');
|
1568
|
-
if (removeConfigFile()) {
|
1569
|
-
uninstallSpinner.stop('✅ g2log配置文件已成功删除');
|
1570
|
-
console.log(colorize('💡 提示: 如需完全卸载g2log,还需执行 npm uninstall -g g2log', 'yellow'));
|
1571
|
-
} else {
|
1572
|
-
uninstallSpinner.fail('❌ 配置文件不存在或删除失败');
|
1573
|
-
}
|
1574
|
-
return;
|
1575
|
-
}
|
1576
|
-
|
1577
1564
|
// 修复配置文件
|
1578
1565
|
if (args['fix-config']) {
|
1579
1566
|
const fixSpinner = spinner.start('🔧 正在修复配置文件...');
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "g2log",
|
3
|
-
"version": "1.4.
|
3
|
+
"version": "1.4.1",
|
4
4
|
"description": "查询特定用户和时间范围的Git提交记录并通过AI进行总结,可通过npx直接运行",
|
5
5
|
"main": "git-user-log.js",
|
6
6
|
"bin": {
|
@@ -34,5 +34,8 @@
|
|
34
34
|
"bugs": {
|
35
35
|
"url": "https://github.com/chenxiangcai/git-user-log/issues"
|
36
36
|
},
|
37
|
-
"homepage": "https://github.com/chenxiangcai/git-user-log#readme"
|
37
|
+
"homepage": "https://github.com/chenxiangcai/git-user-log#readme",
|
38
|
+
"dependencies": {
|
39
|
+
"ora": "^8.2.0"
|
40
|
+
}
|
38
41
|
}
|