{"id":46367481,"url":"https://github.com/gaetanovespero81/ai-code-review-bot","last_synced_at":"2026-03-05T02:34:20.550Z","repository":{"id":326273072,"uuid":"1104854003","full_name":"gaetanovespero81/ai-code-review-bot","owner":"gaetanovespero81","description":"Automated AI-powered code review bot using GitHub Actions and GitHub Models to analyze PR diffs and generate structured reviews.","archived":false,"fork":false,"pushed_at":"2025-11-26T20:18:51.000Z","size":10,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-29T15:54:42.515Z","etag":null,"topics":["ai","ai-code-review","automation","azure-ai","chatgpt","code-review","devops","github-actions","github-models","llm","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gaetanovespero81.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-26T19:32:33.000Z","updated_at":"2025-11-26T20:23:41.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/gaetanovespero81/ai-code-review-bot","commit_stats":null,"previous_names":["gaetanovespero81/ai-code-review-bot"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/gaetanovespero81/ai-code-review-bot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gaetanovespero81%2Fai-code-review-bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gaetanovespero81%2Fai-code-review-bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gaetanovespero81%2Fai-code-review-bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gaetanovespero81%2Fai-code-review-bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gaetanovespero81","download_url":"https://codeload.github.com/gaetanovespero81/ai-code-review-bot/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gaetanovespero81%2Fai-code-review-bot/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30107260,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-05T01:39:18.192Z","status":"online","status_checked_at":"2026-03-05T02:00:06.710Z","response_time":93,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","ai-code-review","automation","azure-ai","chatgpt","code-review","devops","github-actions","github-models","llm","python"],"created_at":"2026-03-05T02:34:19.918Z","updated_at":"2026-03-05T02:34:20.538Z","avatar_url":"https://github.com/gaetanovespero81.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🤖 AI Code Review Bot (GitHub Actions + GitHub Models)\n\n![CI](https://github.com/gaetanovespero81/ai-code-review-bot/actions/workflows/ai-review.yml/badge.svg)\n![Version](https://img.shields.io/github/v/tag/gaetanovespero81/ai-code-review-bot?label=version)\n\nThis repository contains an automated **AI-powered code review system** built using  \n**GitHub Actions**, **GitHub Models**, and the **Azure AI Inference SDK**.\n\nOn every Pull Request, the workflow:\n\n- extracts the PR diff\n- sends the diff to an LLM (`openai/gpt-4o-mini`)\n- generates a structured, professional review\n- posts the review directly as a PR comment\n- stores the full output as an artifact (`ai_review.md`)\n\nThis project demonstrates a realistic integration of **CI/CD automation** and **AI-driven code quality analysis**, suitable for enterprise environments and technical portfolios.\n\n---\n\n## 🚀 Features\n\n### 🔍 Automated AI Code Review\nTriggered on PR events (opened, updated, reopened):\n\n1. Extract the pull request diff using `gh pr diff`\n2. Build an LLM prompt dynamically\n3. Call GitHub Models via Azure AI Inference\n4. Generate a clear review in Markdown\n5. Comment directly on the PR\n6. Upload the review as an artifact\n\n### 🧠 GitHub Models Integration\nThe system uses the GitHub Models inference endpoint with the Azure SDK:\n- `@azure-rest/ai-inference`\n- `@azure/core-auth`\n- `@azure/core-sse`\n\n### 🔐 Secure Authentication\nThe workflow uses a dedicated **Personal Access Token (PAT)** stored as:\n\nGH_MODELS_TOKEN\n\nThis PAT includes `models:read` and is valid until:\n\n- 📅 **25 November 2026**\n\n### 💸 Free Model Usage\nThe workflow uses:\nopenai/gpt-4o-mini\n\nwhich is **free** under GitHub Models usage limits and reliably available for API inference.\n\n---\n\n## 🧩 Architecture Overview\n\n\n**flowchart TD**\n- A[Pull Request Event] --\u003e B[GitHub Actions Workflow]\n- B --\u003e C[Extract PR Diff\u003cbr\u003e(gh pr diff)]\n- C --\u003e D[Azure AI Inference\u003cbr\u003evia GitHub Models]\n- D --\u003e E[LLM Generates Code Review]\n- E --\u003e F[Comment on PR]\n- E --\u003e G[Upload ai_review.md Artifact]\n\n---\n\n## 📦 Repository Structure\n\nThis repository is intentionally kept clean and lightweight.\nAll AI-related JavaScript files (ai_review.js, package.json, dependencies) are not committed.\n\nThey are created dynamically by the workflow during execution.\n\n├─ .github/\n\n| └─ workflows/\n\n| | └─ ai-review.yml\n\n├─ bot/\n\n| └─ review.py\n\nThe CI pipeline handles everything else automatically inside the GitHub Actions runner.\n\n---\n\n## 🐍 Optional Local Tool — `bot/review.py`\n\nIn addition to the CI-based Node.js workflow, this repository includes an optional\nPython utility located at:\nbot/review.py\nThis module provides a **standalone AI code review tool** that can be executed locally,\noutside the GitHub Actions environment. It enables developers to request an AI-generated\nreview for any diff directly from the command line.\n\n### 🔧 What It Does\n\n- Reads a diff from a text file (e.g., output of `git diff`)\n- Builds a professional review prompt\n- Calls GitHub Models (`openai/gpt-4o-mini`) through the official Inference API\n- Prints the full review to stdout\n\nThis is useful for:\n- rapid offline testing\n- experimenting with prompt design\n- local pre-review before opening a Pull Request\n- demonstration of Python-based LLM integration\n\n### ▶️ How to Use\n\n1. Set your GitHub Models PAT:\n\n\n`export GITHUB_TOKEN=\u003cyour GH_MODELS_TOKEN\u003e`\n\n2.\tSave any diff to a file:\n\n`git diff \u003e pr_diff.txt`\n\n3.\tRun the review script:\n\n`python -m bot.review pr_diff.txt`\n\nYou will receive a full Markdown-formatted AI code review directly in the terminal.\n\n**🧠 Notes**\n- This local tool uses the same model and same PAT as the CI workflow.\n- It does not require committing any additional files (package.json, Node dependencies).\n- It demonstrates multi-language AI integration (Node.js in CI, Python locally).\n\n---\n\n## ⚙️ Setup Instructions\n\n1️⃣ Generate the PAT (Personal Access Token)\n\nThe token was generated directly from the GPT-5 model page on GitHub Marketplace.\nThis ensures the token automatically includes the required:\n\n`models:read`\n\nThe PAT used by this workflow expires on:\n\n- 🗓️ 25.11.2026\n\n2️⃣ Store the PAT in Repository Secrets\n\n**Navigate to:**\n\nSettings → Secrets and variables → Actions → New repository secret\n\n**Create:**\n\nName: GH_MODELS_TOKEN\n\nValue: `\u003cyour PAT\u003e`\n\n⚠️ Must be a secret, not a variable.\n\n---\n\n## 🛠 Workflow Execution Details\n\nThe workflow:\n1.\tInstalls Node.js\n2.\tDynamically creates a lightweight package.json\n3.\tInstalls Azure AI dependencies\n4.\tGenerates ai_review.js (the inference logic)\n5.\tExecutes the script to produce AI feedback\n6.\tComments on the PR\n7.\tSaves ai_review.md as an artifact\n\nThe repository stays clean — no JS files committed — while the workflow remains fully functional.\n\n---\n\n## 🧪 Testing the System\n\nYou can manually test the AI inference locally by exporting the PAT:\n\n`export GITHUB_TOKEN=\u003cyour GH_MODELS_TOKEN\u003e`\n\nnode ai_review.js\n\nOr trigger the workflow by:\n- opening a PR\n- updating an existing PR\n\n---\n\n## 🩻 Troubleshooting\n\n❌ Unavailable model: gpt-5\n\nYou have UI access to GPT-5, but API inference is not enabled for your account/region.\n\nUse instead:\n- openai/gpt-4o-mini   (recommended, free)\n\n❌ key must be a non-empty string\n\nThe GH_MODELS_TOKEN secret is missing or empty.\n\nFix:\n- Ensure it is stored under Secrets, not Variables\n- No spaces, quotes, or trailing newlines\n\n❌ The bot comments “null”\n\nMeans the model call failed silently → check token + model name.\n\n---\n\n## 💼 Why This Project Is Valuable for Companies\n\nThis repository demonstrates capabilities in:\n- Advanced GitHub Actions automation\n- Secure secret management\n- Integration with cloud LLM inference APIs\n- Dynamic CI scripting\n- Code quality automation\n- AI-assisted development workflows\n- PR workflow enhancements\n\nIt presents practical skills for:\n- DevOps / CI/CD Engineers\n- Software Engineers\n- AI Integration Engineers\n- Automation Engineers\n\nPerfect for modern engineering teams adopting AI in their pipelines.\n\n---\n\n## 📜 License\n\nMIT License.\n\n---\n\n## 👤 Author\n\n*Gaetano Vespero*\n\n*DevOps \u0026 Automation Engineer* | *Specialist in CI/CD + AI Workflow Integration*","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgaetanovespero81%2Fai-code-review-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgaetanovespero81%2Fai-code-review-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgaetanovespero81%2Fai-code-review-bot/lists"}