get_gitlab_commits
Retrieve GitLab commit records for specified dates to generate work reports, with optional filtering by user or project for integration with enterprise messaging systems.
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:152-179 (handler)The main handler function for the 'get_gitlab_commits' MCP tool. Validates input parameters and delegates to GitLabService.getCommitsByDate to fetch the commits, then 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 (schema)Defines the tool name, description, and input schema for 'get_gitlab_commits' in the MCP tools list.{ 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:122-123 (registration)Switch case in the CallToolRequest handler that routes 'get_gitlab_commits' calls to the specific handler function.case 'get_gitlab_commits': return await this.handleGetGitLabCommits(args);
- 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 using GitLab API.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}`); } }