get_commit
Retrieve detailed commit information from GitLab projects by providing project ID and commit SHA to access changes, author details, and timestamps.
Instructions
取得 Commit 詳細資訊
Args: project_id: 專案 ID 或路徑 sha: Commit SHA(完整或縮短)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | ||
| sha | Yes |
Implementation Reference
- src/gitlab_mcp/server.py:863-891 (handler)The MCP tool registration and handler function for 'get_commit'.
@mcp.tool() def get_commit(project_id: int | str, sha: str) -> str: """取得 Commit 詳細資訊 Args: project_id: 專案 ID 或路徑 sha: Commit SHA(完整或縮短) """ try: client = get_client() c = client.get_commit(project_id, sha) stats = c.get("stats", {}) return f"""Commit {c.get('id', 'N/A')} 標題: {c.get('title', 'N/A')} 訊息: {c.get('message', 'N/A')} 作者: {c.get('author_name', 'N/A')} <{c.get('author_email', '')}> 時間: {c.get('authored_date', 'N/A')} 新增: {stats.get('additions', 0)} 行 | 刪除: {stats.get('deletions', 0)} 行 | 變更檔案: {stats.get('total', 0)} 網址: {c.get('web_url', '')}""" except GitLabAPIError as e: return f"取得 commit 失敗: {str(e)}" @mcp.tool() def compare_branches(project_id: int | str, from_ref: str, to_ref: str) -> str: """比較兩個分支或 commit 的差異 Args: - The Gitlab client method that makes the API request to fetch commit details.
def get_commit(self, project_id: int | str, sha: str) -> dict: """GET /projects/:id/repository/commits/:sha""" pid = self._resolve_project_id(project_id) return self._get_json(f"/projects/{pid}/repository/commits/{sha}")