# gitLog **Repository Path**: he-mengzhen/git-log ## Basic Information - **Project Name**: gitLog - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-05-27 - **Last Updated**: 2026-06-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Git日报生成器 一个Python脚本,用于获取Git提交记录并自动生成工作日报。支持定时任务、AI增强报告生成等功能。 ## 功能特性 - ✅ 自动获取当前账户下所有分支的Git提交记录 - ✅ 自动排除合并提交(merge commits) - ✅ 按分支分组展示,格式为"分支名称:工作内容" - ✅ 支持多种输出格式(Markdown、纯文本、JSON) - ✅ 可配置是否保存文件 - ✅ 配置文件管理Git账号和定时任务 - ✅ 定时自动生成日报 - ✅ AI智能报告生成(可选) - ✅ 灵活的过滤和自定义选项 ## 安装 ### 方法1:全局安装(推荐) ```bash # 在 gitLog 目录执行一次安装 cd d:\Users\15362\Desktop\gitLog pip install -e . ``` 安装后,你可以在**任何Git项目**中直接使用 `git-report` 命令。 ### 方法2:仅安装依赖 ```bash pip install -r requirements.txt ``` 然后使用 `python main.py` 运行。 ### 2. 配置 编辑 `config.json` 文件: ```json { "git_accounts": [ { "name": "default", "email": "your-email@example.com", "username": "your-username" } ], "schedule": { "enabled": false, "time": "18:00", "timezone": "Asia/Shanghai", "repo_paths": [ "d:/path/to/project1", "d:/path/to/project2" ] }, "output": { "_comment": "输出配置", "format": "markdown", "directory": "./reports", "filename_pattern": "daily_report_{date}.md", "save_to_file": true, }, "ai": { "enabled": false, "api_url": "https://api.openai.com/v1/chat/completions", "api_key": "your-api-key", "model": "gpt-3.5-turbo" }, "filters": { "exclude_branches": ["merge", "HEAD"], "exclude_commits_keywords": ["merge", "Merge"] } } ``` ### 输出配置说明 - `save_to_file`: 是否保存日报到文件(默认 true) ### 多项目配置说明 在 `schedule.repo_paths` 中配置多个项目路径,定时任务会依次处理每个项目: ```json "schedule": { "enabled": true, "time": "18:00", "repo_paths": [ "d:/projects/project-a", "d:/projects/project-b", "d:/projects/project-c" ] } ``` **注意:** - 每个项目的日报会分别保存在各自项目的 `reports/` 目录下 - 如果某个项目路径不存在或不是Git仓库,会跳过并继续处理下一个 - 也可以留空数组 `[]`,此时使用当前工作目录 # 使用AI生成智能日报 git-report --ai # 启动定时任务(前台运行,会占用终端) git-report --schedule # 遵循 config.json 中 ai.enabled ```bash # 进入你的Git项目目录 cd your-git-project # 生成今天的日报 git-report # 生成指定日期的日报 git-report --date 2024-01-15 # 使用AI生成智能日报 git-report --ai # 启动定时任务(前台运行,会占用终端) git-report --schedule # 指定输出格式 git-report --format json ``` ### 直接运行脚本 ```bash python main.py python main.py --date 2024-01-15 python main.py --ai ``` ```bash python main.py --schedule ``` ### 指定输出格式 ```bash python main.py --format json ``` ### 完整参数说明 ``` usage: main.py [-h] [--date DATE] [--author AUTHOR] [--branch BRANCH] [--config CONFIG] [--ai] [--schedule] [--format FORMAT] [--no-save] Git日报生成器 - 根据Git提交记录生成工作日报 options: -h, --help show this help message and exit --date DATE 日期,格式 YYYY-MM-DD,默认为今天 --author AUTHOR 作者邮箱或用户名 --branch BRANCH 分支名称 --config CONFIG 配置文件路径,默认为 config.json --ai 使用AI生成智能日报 --schedule 启动定时任务 --format FORMAT 输出格式 (markdown, text, json) --no-save 不保存到文件,仅输出到控制台 ``` ## 项目结构 ``` gitLog/ ├── main.py # 主入口脚本 ├── git_helper.py # Git日志获取模块 ├── report_generator.py # 日报生成模块 ├── scheduler.py # 定时任务模块 ├── ai_integration.py # AI接口集成模块 ├── config.json # 配置文件 ├── requirements.txt # Python依赖 ├── README.md # 说明文档 └── reports/ # 生成的日报存储目录 └── daily_report_2024-01-15.md ``` ## 配置说明 ### Git账号配置 在 `config.json` 的 `git_accounts` 数组中配置多个Git账号: ```json "git_accounts": [ { "name": "work", "email": "work@example.com", "username": "work-user" }, { "name": "personal", "email": "personal@example.com", "username": "personal-user" } ] ``` ### 定时任务配置 启用定时任务: ```json "schedule": { "enabled": true, "time": "18:00", "timezone": "Asia/Shanghai" } ``` ### AI配置 配置OpenAI API或其他兼容的API: ```json "ai": { "enabled": true, "api_url": "https://api.openai.com/v1/chat/completions", "api_key": "sk-your-api-key", "model": "gpt-3.5-turbo" } ``` 也可以使用其他兼容OpenAI API的服务,如: - Azure OpenAI - 本地部署的LLM(Ollama、LM Studio等) - 其他第三方API服务 ### 过滤配置 排除特定分支和提交: ```json "filters": { "exclude_branches": ["merge", "HEAD", "develop"], "exclude_commits_keywords": ["merge", "Merge", "WIP"] } ``` ## 输出示例 ### Markdown格式(优化版) 日报采用"**分支名称**:工作内容"的简洁格式: ```markdown # 工作日报 (2024-01-15) **生成时间**: 2024-01-15 18:30:00 **作者**: Your Name **feature-login**:添加用户登录功能;修复登录验证bug **feature-dashboard**:实现数据看板页面 --- ## 详细提交记录 ### feature-login - [2024-01-15 10:23:45] 添加用户登录功能 (`a1b2c3d4`) - [2024-01-15 14:56:12] 修复登录验证bug (`e5f6g7h8`) ### feature-dashboard - [2024-01-15 16:30:00] 实现数据看板页面 (`i9j0k1l2`) --- **统计信息**: - 总提交数: 3 - 涉及分支: 2 ``` ### 纯文本格式 ``` 工作日报 (2024-01-15) ================================================== 生成时间: 2024-01-15 18:30:00 feature-login:添加用户登录功能;修复登录验证bug feature-dashboard:实现数据看板页面 ================================================== 统计: 总提交数 3, 涉及分支 2 ``` ## 高级用法 ### 作为模块导入 ```python from main import generate_daily_report import json # 加载配置 with open('config.json', 'r') as f: config = json.load(f) # 生成日报 report = generate_daily_report( config=config, date="2024-01-15", author="user@example.com", use_ai=True ) # 处理报告内容 print(report) ``` ### 自定义报告格式 ```python from report_generator import ReportGenerator from git_helper import GitHelper git_helper = GitHelper() commits = git_helper.get_commits_by_date(date="2024-01-15") report_gen = ReportGenerator(config) # 生成不同格式的报告 markdown_report = report_gen.generate_report(commits, format_type="markdown") text_report = report_gen.generate_report(commits, format_type="text") json_report = report_gen.generate_report(commits, format_type="json") ``` ## 注意事项 1. 确保在项目根目录或有 `.git` 文件夹的目录下运行 2. 定时任务需要保持脚本持续运行 3. AI功能需要有效的API密钥和网络连接 4. 建议将敏感信息(如API密钥)从版本控制中排除 ## 许可证 MIT License