generate_daily_report
Generate and send GitLab commit summaries as daily reports to WeChat Work groups. Query commits by date, user, or project for automated team updates.
Instructions
生成并发送GitLab提交记录的日报到企业微信
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| username | No | GitLab用户名(可选,默认使用配置的用户名) | |
| date | Yes | 查询日期,格式:YYYY-MM-DD | |
| projectId | No | 项目ID(可选,不指定则查询所有项目) |
Implementation Reference
- src/index.js:203-240 (handler)Main handler function that implements the generate_daily_report tool logic: validates input, fetches GitLab commits using GitLabService, generates report content using helper, sends markdown report via WeChatService, and returns result.async handleGenerateDailyReport(args) { // 验证参数 ErrorHandler.validateParams(args, { date: { required: true, type: 'string', format: 'date' }, username: { required: false, type: 'string' }, projectId: { required: false, type: 'string' }, }); const { username, date, projectId } = args; const gitlabConfig = config.getGitLabConfig(); const actualUsername = username || gitlabConfig.username; logger.info('开始生成日报', { date, username: actualUsername, projectId }); // 获取提交记录 const commits = await this.gitlabService.getCommitsByDate( actualUsername, date, projectId ); // 生成日报内容 const report = this.generateReportContent(commits, date, actualUsername); // 发送到企业微信 const result = await this.wechatService.sendMessage(report, 'markdown'); logger.info(`日报生成并发送${result.success ? '成功' : '失败'}`, { commitCount: commits.length }); return { content: [ { type: 'text', text: `日报生成并发送${result.success ? '成功' : '失败'}\n\n报告内容:\n${report}`, }, ], }; }
- src/index.js:242-268 (helper)Supporting function that formats the daily report as Markdown from the list of commits, including summary stats and detailed list.generateReportContent(commits, date, username) { const commitCount = commits.length; const projects = [...new Set(commits.map(c => c.project_name))]; let report = `# ${username} 的代码提交日报\n\n`; report += `**日期**: ${date}\n`; report += `**提交数量**: ${commitCount}\n`; report += `**涉及项目**: ${projects.join(', ')}\n\n`; if (commitCount === 0) { report += '今日无代码提交记录。'; } else { report += '## 提交详情\n\n'; commits.forEach((commit, index) => { report += `### ${index + 1}. ${commit.title}\n`; report += `- **项目**: ${commit.project_name}\n`; report += `- **时间**: ${new Date(commit.committed_date).toLocaleString('zh-CN')}\n`; report += `- **分支**: ${commit.ref_name || 'unknown'}\n`; if (commit.message && commit.message !== commit.title) { report += `- **详情**: ${commit.message.replace(commit.title, '').trim()}\n`; } report += `- **链接**: [查看提交](${commit.web_url})\n\n`; }); } return report; }
- src/index.js:91-108 (schema)Input schema defining parameters for generate_daily_report tool: date (required), username and projectId (optional).inputSchema: { type: 'object', properties: { username: { type: 'string', description: 'GitLab用户名(可选,默认使用配置的用户名)', }, date: { type: 'string', description: '查询日期,格式:YYYY-MM-DD', }, projectId: { type: 'string', description: '项目ID(可选,不指定则查询所有项目)', }, }, required: ['date'], },
- src/index.js:88-109 (registration)Registration of the generate_daily_report tool in the ListTools response, including name, description, and input schema.{ name: 'generate_daily_report', description: '生成并发送GitLab提交记录的日报到企业微信', inputSchema: { type: 'object', properties: { username: { type: 'string', description: 'GitLab用户名(可选,默认使用配置的用户名)', }, date: { type: 'string', description: '查询日期,格式:YYYY-MM-DD', }, projectId: { type: 'string', description: '项目ID(可选,不指定则查询所有项目)', }, }, required: ['date'], }, },
- src/index.js:126-127 (registration)Dispatch/registration of the handler in the CallToolRequest switch statement.case 'generate_daily_report': return await this.handleGenerateDailyReport(args);