cd /news/developer-tools/code-review-the-actual-git-branch-us… · home topics developer-tools article
[ARTICLE · art-84481] src=gist.github.com ↗ pub= topic=developer-tools verified=true sentiment=· neutral

Code review the actual git branch using github copilot sdk.

A developer has built a script that uses the GitHub Copilot SDK to automatically review the actual git branch by sending the diff between main and HEAD to a large language model for analysis. The script generates a JSON file with review comments, including file paths and line numbers, following enterprise standards. The tool is designed to streamline code review processes by leveraging AI.

read3 min views9 publishedJul 29, 2026
| import { execSync } from "node:child_process"; | |
| import fs from "node:fs"; | |
| import { CopilotClient } from "@github/copilot-sdk"; | |

| // Get diff Git | |

| function getBranchDiff(projectlocation = "./") { | |
| if (projectlocation !== "./") { | |
| execSync(`cd ${projectlocation}`); | |

| } | | | return execSync("git diff main...HEAD", { | | | encoding: "utf8", | | | maxBuffer: 10 * 1024 * 1024, | | | }); | | | } | | | // Send the diff to Copilot for review | | | async function reviewDiff(diff) { | | | // Initialize the client with your GitHub token | | | const client = new CopilotClient({ | | | gitHubToken: process.env.GITHUB_TOKEN, | | | useLoggedInUser: false, | |

| }); | |
| await client.start(); | |

| // Create a session with the desired model and streaming enabled | |

| const session = await client.createSession({ | |
| model: process.env.MODEL || "claude-sonnet-5", | |

| streaming: true | | | }); | | | const prompt = ` | | | You are a senior software reviewer. Perform an in-depth code review following enterprise standards based on the provided context. | | | CRITICAL OUTPUT INSTRUCTIONS: | | | Return ONLY a valid JSON array. | | | Do not include markdown. | | | Do not include code fences. | | | Do not include explanations outside the JSON. | | | Do not include any text before or after the JSON. | | | Each item in the array must follow exactly this structure: | | | [ | | | { | | | "body": "Clear and actionable review comment", | | | "labels": ["code-review"], | | | "assignee_id": 456, | | | "id": 0, | | | "file_path": "path/to/file.js", | | | "line_number": 42 | | | } | | | ] | | | Rules: | | | - Focus only on meaningful issues | | | - Keep comments concise and useful | | | - Do not invent file paths or line numbers | | | - Do not include fields other than "body" | | | - Return [] if there are no important review comments | | | <git_diff> | |

| ${diff} | |
| </git_diff>`; | |

| // Send the prompt to the session and wait for the response | |

| const response = await session.sendAndWait(prompt,300000); | |
| await client.stop(); | |

| return response; | | | } | | | async function main() { | | | const diff = getBranchDiff('./'); // Adjust the path to your project if needed | | | const review = await reviewDiff(diff); | | | // create a JSON file with the review result | | | fs.writeFileSync('review.json', review.data.content); | | | } | |

| main().catch((error) => { | |
| console.error("Script failed:", error); | |
| process.exit(1); | |
| }); |
── more in #developer-tools 4 stories · sorted by recency
── more on @github copilot sdk 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/code-review-the-actu…] indexed:0 read:3min 2026-07-29 ·