get_gitlab_commits
Retrieve GitLab commit records for specified dates to generate daily work reports and share them via WeChat Work integration.
Instructions
获取GitLab用户在指定日期的代码提交记录
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | Yes | 查询日期,格式:YYYY-MM-DD | |
| projectId | No | 项目ID(可选,不指定则查询所有项目) | |
| username | No | GitLab用户名(可选,默认使用配置的用户名) |
Input Schema (JSON Schema)
{
"properties": {
"date": {
"description": "查询日期,格式:YYYY-MM-DD",
"type": "string"
},
"projectId": {
"description": "项目ID(可选,不指定则查询所有项目)",
"type": "string"
},
"username": {
"description": "GitLab用户名(可选,默认使用配置的用户名)",
"type": "string"
}
},
"required": [
"date"
],
"type": "object"
}
Implementation Reference
- src/index.js:152-179 (handler)The MCP tool handler for 'get_gitlab_commits' that validates input parameters, fetches commits using GitLabService, and returns them as JSON.async handleGetGitLabCommits(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 commits = await this.gitlabService.getCommitsByDate( username || gitlabConfig.username, date, projectId ); logger.info(`获取到 ${commits.length} 条提交记录`, { date, username: username || gitlabConfig.username }); return { content: [ { type: 'text', text: JSON.stringify(commits, null, 2), }, ], }; }
- src/index.js:46-67 (registration)Registers the 'get_gitlab_commits' tool in the MCP server's list of tools, including name, description, and input schema.{ name: 'get_gitlab_commits', 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:49-66 (schema)Defines the input schema for the 'get_gitlab_commits' tool, specifying parameters like date (required), username, and projectId.inputSchema: { type: 'object', properties: { username: { type: 'string', description: 'GitLab用户名(可选,默认使用配置的用户名)', }, date: { type: 'string', description: '查询日期,格式:YYYY-MM-DD', }, projectId: { type: 'string', description: '项目ID(可选,不指定则查询所有项目)', }, }, required: ['date'], },
- src/services/gitlab.js:29-53 (helper)Core helper method in GitLabService that fetches commits for a user on a specific date, either from a single project or all user projects.async getCommitsByDate(username, date, projectId = null) { try { const startDate = new Date(date); const endDate = new Date(date); endDate.setDate(endDate.getDate() + 1); const since = startDate.toISOString(); const until = endDate.toISOString(); let commits = []; if (projectId) { // 查询指定项目的提交 commits = await this.getProjectCommits(projectId, username, since, until); } else { // 查询用户所有项目的提交 commits = await this.getAllUserCommits(username, since, until); } return commits; } catch (error) { console.error('获取GitLab提交记录失败:', error.message); throw new Error(`获取GitLab提交记录失败: ${error.message}`); } }