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. | 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 | | |