get_commit
Fetch detailed information for a specific commit in a GitHub repository by providing owner, repository name, and SHA.
Instructions
Get details for a commit from a GitHub repository
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| owner | Yes | Repository owner | |
| repo | Yes | Repository name | |
| sha | Yes | Commit SHA, branch name, or tag name |
Implementation Reference
- src/tools/repositories.ts:189-252 (registration)Tool 'get_commit' is registered via server.tool() with name 'get_commit'
server.tool( "get_commit", "Get details for a commit from a GitHub repository", { owner: z.string().describe("Repository owner"), repo: z.string().describe("Repository name"), sha: z.string().describe("Commit SHA, branch name, or tag name"), }, async ({ owner, repo, sha }) => { try { const response = await octokit.rest.repos.getCommit({ owner, repo, ref: sha, }) const commit = response.data // Format as clean markdown let markdown = `# Commit ${commit.sha.substring(0, 7)}\n\n` markdown += `**Message:** ${commit.commit.message}\n\n` markdown += `**Author:** ${commit.commit.author?.name} <${commit.commit.author?.email}>\n` markdown += `**Date:** ${new Date(commit.commit.author?.date || "").toLocaleDateString()}\n` if (commit.commit.committer?.name !== commit.commit.author?.name) { markdown += `**Committer:** ${commit.commit.committer?.name} <${commit.commit.committer?.email}>\n` } markdown += `\n## Changes\n\n` markdown += `- **Files changed:** ${commit.files?.length || 0}\n` markdown += `- **Additions:** ${commit.stats?.additions || 0}\n` markdown += `- **Deletions:** ${commit.stats?.deletions || 0}\n` if (commit.files && commit.files.length > 0) { markdown += `\n## Files\n\n` commit.files.forEach(file => { const status = file.status === "added" ? "[A]" : file.status === "removed" ? "[D]" : file.status === "modified" ? "[M]" : file.status === "renamed" ? "[R]" : "[?]" markdown += `- ${status} ${file.filename} (+${file.additions} -${file.deletions})\n` }) } markdown += `\n## Links\n\n` markdown += `- **Commit URL:** ${commit.html_url}\n` markdown += `- **Full SHA:** ${commit.sha}\n` return { content: [{ type: "text", text: markdown }], } } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.message}` }], } } }, ) - src/tools/repositories.ts:192-196 (schema)Zod schema defining input parameters: owner (string), repo (string), sha (string)
{ owner: z.string().describe("Repository owner"), repo: z.string().describe("Repository name"), sha: z.string().describe("Commit SHA, branch name, or tag name"), }, - src/tools/repositories.ts:197-251 (handler)Handler function that calls octokit.rest.repos.getCommit() with owner, repo, and ref=sha, then formats commit details as markdown
async ({ owner, repo, sha }) => { try { const response = await octokit.rest.repos.getCommit({ owner, repo, ref: sha, }) const commit = response.data // Format as clean markdown let markdown = `# Commit ${commit.sha.substring(0, 7)}\n\n` markdown += `**Message:** ${commit.commit.message}\n\n` markdown += `**Author:** ${commit.commit.author?.name} <${commit.commit.author?.email}>\n` markdown += `**Date:** ${new Date(commit.commit.author?.date || "").toLocaleDateString()}\n` if (commit.commit.committer?.name !== commit.commit.author?.name) { markdown += `**Committer:** ${commit.commit.committer?.name} <${commit.commit.committer?.email}>\n` } markdown += `\n## Changes\n\n` markdown += `- **Files changed:** ${commit.files?.length || 0}\n` markdown += `- **Additions:** ${commit.stats?.additions || 0}\n` markdown += `- **Deletions:** ${commit.stats?.deletions || 0}\n` if (commit.files && commit.files.length > 0) { markdown += `\n## Files\n\n` commit.files.forEach(file => { const status = file.status === "added" ? "[A]" : file.status === "removed" ? "[D]" : file.status === "modified" ? "[M]" : file.status === "renamed" ? "[R]" : "[?]" markdown += `- ${status} ${file.filename} (+${file.additions} -${file.deletions})\n` }) } markdown += `\n## Links\n\n` markdown += `- **Commit URL:** ${commit.html_url}\n` markdown += `- **Full SHA:** ${commit.sha}\n` return { content: [{ type: "text", text: markdown }], } } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.message}` }], } } },