Skip to main content
Glama

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
NameRequiredDescriptionDefault
project_idYes
shaYes

Implementation Reference

  • 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}")

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/snowild/gitlab-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server