Skip to content

Commit d30ac95

Browse files
committed
Added first port of reviewer agent from ADO, and removed old ADO compatibility logic from push-branch script
1 parent 3e68577 commit d30ac95

12 files changed

Lines changed: 2881 additions & 64 deletions
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
name: 🤖 Copilot PR Reviewer
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
branches:
7+
- main
8+
- develop
9+
- feature/*
10+
11+
permissions:
12+
contents: read
13+
pull-requests: write
14+
15+
env:
16+
MODEL: claude-haiku-4.5
17+
COPILOT_VERSION: latest
18+
ANALYSIS_DIR: ${{ github.workspace }}/pr-analysis
19+
DIFF_FILE: ${{ github.workspace }}/pr-diff.json
20+
21+
jobs:
22+
review:
23+
runs-on: ubuntu-latest
24+
name: 🤖 Analyze PR and Generate Review
25+
26+
steps:
27+
- name: 📋 Show PR Information
28+
run: |
29+
echo "📋 Pull Request Information:"
30+
echo " - Repository: ${{ github.repository }}"
31+
echo " - PR #: ${{ github.event.pull_request.number }}"
32+
echo " - Source Branch: ${{ github.event.pull_request.head.ref }}"
33+
echo " - Target Branch: ${{ github.event.pull_request.base.ref }}"
34+
echo " - Source Commit: ${{ github.event.pull_request.head.sha }}"
35+
echo ""
36+
echo "📁 Working directories:"
37+
echo " - Analysis Dir: ${{ env.ANALYSIS_DIR }}"
38+
echo " - Diff File: ${{ env.DIFF_FILE }}"
39+
40+
- name: ⚙️ Setup Node.js 22.x
41+
uses: actions/setup-node@v4
42+
with:
43+
node-version: '22.x'
44+
cache: 'npm'
45+
46+
- name: 🔍 Detect NPM Global Path
47+
run: |
48+
NPM_PREFIX=$(npm config get prefix)
49+
echo "NPM_GLOBAL_PATH=${NPM_PREFIX}/lib/node_modules" >> $GITHUB_ENV
50+
echo "NPM global path: ${NPM_PREFIX}/lib/node_modules"
51+
52+
- name: 📦 Cache Global NPM Packages
53+
uses: actions/cache@v4
54+
with:
55+
key: npm-global-${{ runner.os }}-copilot-${{ env.COPILOT_VERSION }}
56+
path: ${{ env.NPM_GLOBAL_PATH }}
57+
restore-keys: |
58+
npm-global-${{ runner.os }}-copilot-
59+
60+
- name: 📦 Install Copilot CLI
61+
run: |
62+
if ! command -v copilot &> /dev/null; then
63+
echo "Installing @github/copilot@${{ env.COPILOT_VERSION }}..."
64+
npm install -g @github/copilot@${{ env.COPILOT_VERSION }}
65+
else
66+
echo "✅ @github/copilot already installed (from cache)"
67+
copilot --version
68+
fi
69+
70+
- name: 🔍 Get PR Differences
71+
env:
72+
GH_TOKEN: ${{ github.token }}
73+
GHES_HOST: ${{ github.server_url }}
74+
run: |
75+
# Extract host from server_url (remove https://)
76+
GHES_HOST="${{ github.server_url }}" | sed 's|https://||'
77+
78+
bash ./scripts/get-pr-diff.sh \
79+
"$GHES_HOST" \
80+
"${{ github.repository_owner }}" \
81+
"${{ github.event.repository.name }}" \
82+
"${{ github.event.pull_request.number }}" \
83+
"${{ github.token }}" \
84+
"${{ env.DIFF_FILE }}"
85+
86+
- name: 📁 Download Modified Files
87+
env:
88+
GH_TOKEN: ${{ github.token }}
89+
GHES_HOST: ${{ github.server_url }}
90+
run: |
91+
GHES_HOST="${{ github.server_url }}" | sed 's|https://||'
92+
93+
bash ./scripts/download-pr-files.sh \
94+
"$GHES_HOST" \
95+
"${{ github.repository_owner }}" \
96+
"${{ github.event.repository.name }}" \
97+
"${{ github.event.pull_request.number }}" \
98+
"${{ github.token }}" \
99+
"${{ env.ANALYSIS_DIR }}"
100+
101+
- name: 🤖 Analyze with GitHub Copilot CLI
102+
env:
103+
MODEL: ${{ env.MODEL }}
104+
run: |
105+
bash ./scripts/analyze-with-copilot.sh \
106+
"${{ env.ANALYSIS_DIR }}/source" \
107+
"${{ env.ANALYSIS_DIR }}/source/pr-comments"
108+
109+
- name: 💬 Publish Comment on PR
110+
env:
111+
GH_TOKEN: ${{ github.token }}
112+
GHES_HOST: ${{ github.server_url }}
113+
if: always()
114+
run: |
115+
GHES_HOST="${{ github.server_url }}" | sed 's|https://||'
116+
117+
bash ./scripts/post-pr-comment.sh \
118+
"$GHES_HOST" \
119+
"${{ github.repository_owner }}" \
120+
"${{ github.event.repository.name }}" \
121+
"${{ github.event.pull_request.number }}" \
122+
"${{ env.ANALYSIS_DIR }}/source/pr-comments" \
123+
"${{ github.token }}" || true
124+
125+
- name: 📦 Upload Analysis Artifacts
126+
if: always()
127+
uses: actions/upload-artifact@v4
128+
with:
129+
name: pr-analysis-${{ github.event.pull_request.number }}
130+
path: ${{ env.ANALYSIS_DIR }}/
131+
retention-days: 30
132+
if-no-files-found: warn
133+
134+
- name: 📊 Summary
135+
if: always()
136+
run: |
137+
echo "## 📊 PR Review Analysis Summary" >> $GITHUB_STEP_SUMMARY
138+
echo "" >> $GITHUB_STEP_SUMMARY
139+
echo "**PR Details:**" >> $GITHUB_STEP_SUMMARY
140+
echo "- Repository: ${{ github.repository }}" >> $GITHUB_STEP_SUMMARY
141+
echo "- PR #: ${{ github.event.pull_request.number }}" >> $GITHUB_STEP_SUMMARY
142+
echo "- Author: ${{ github.event.pull_request.user.login }}" >> $GITHUB_STEP_SUMMARY
143+
echo "" >> $GITHUB_STEP_SUMMARY
144+
145+
if [ -d "${{ env.ANALYSIS_DIR }}/source/pr-comments" ]; then
146+
COMMENT_COUNT=$(find "${{ env.ANALYSIS_DIR }}/source/pr-comments" -name "*_analysis.md" 2>/dev/null | wc -l)
147+
echo "**Review Results:**" >> $GITHUB_STEP_SUMMARY
148+
echo "- Comments Generated: $COMMENT_COUNT" >> $GITHUB_STEP_SUMMARY
149+
echo "- Model Used: ${{ env.MODEL }}" >> $GITHUB_STEP_SUMMARY
150+
echo "" >> $GITHUB_STEP_SUMMARY
151+
152+
if [ $COMMENT_COUNT -gt 0 ]; then
153+
echo "**Issues Found:**" >> $GITHUB_STEP_SUMMARY
154+
find "${{ env.ANALYSIS_DIR }}/source/pr-comments" -name "*_analysis.md" | sort | while read file; do
155+
echo "- $(basename "$file" _analysis.md)" >> $GITHUB_STEP_SUMMARY
156+
done
157+
else
158+
echo "✅ No issues found!" >> $GITHUB_STEP_SUMMARY
159+
fi
160+
else
161+
echo "**Review Results:**" >> $GITHUB_STEP_SUMMARY
162+
echo "- Comments Generated: 0" >> $GITHUB_STEP_SUMMARY
163+
echo "- Model Used: ${{ env.MODEL }}" >> $GITHUB_STEP_SUMMARY
164+
echo "- Status: ✅ No issues found!" >> $GITHUB_STEP_SUMMARY
165+
fi
166+
167+
echo "" >> $GITHUB_STEP_SUMMARY
168+
echo "**Artifacts:**" >> $GITHUB_STEP_SUMMARY
169+
echo "- Full analysis available in [pr-analysis artifact](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}#artifacts)" >> $GITHUB_STEP_SUMMARY

‎README.md‎

Lines changed: 97 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This repository implements an automated coding workflow using **GitHub Copilot C
1414

1515
### ✨ Key Features
1616

17+
#### 🤖 Copilot Coder
1718
- 🏷️ **Label-driven workflow** - Trigger code generation by adding the `copilot` label
1819
- 🤖 **AI-powered coding** - GitHub Copilot CLI generates code based on issue descriptions
1920
- 🌿 **Automatic branching** - Creates feature branches (`copilot/{issue-number}`)
@@ -23,6 +24,14 @@ This repository implements an automated coding workflow using **GitHub Copilot C
2324
- 📦 **Artifact logging** - Captures and stores execution logs
2425
- 🔄 **MCP integration** - Uses Context7 for documentation and best practices
2526

27+
#### 🔍 Copilot PR Reviewer (NEW!)
28+
- 💬 **Automatic PR reviews** - Reviews code on every PR open/update
29+
- 🔒 **Security analysis** - Detects security vulnerabilities
30+
- ⚡ **Performance checks** - Identifies performance issues
31+
- 🧹 **Code quality** - Flags code quality concerns
32+
- 📝 **Detailed feedback** - Posts actionable comments with examples
33+
- 📊 **Artifact logs** - Complete analysis available for reference
34+
2635
## 🚀 Quick Start
2736

2837
### 1️⃣ Setup (One Time)
@@ -91,23 +100,72 @@ The workflow will automatically:
91100
### 5️⃣ Review and Merge
92101

93102
1. Review the Pull Request
94-
2. Test the implementation
95-
3. Approve and merge when ready
103+
2. **Copilot Reviewer automatically analyzes the code** ✨
104+
3. Test the implementation
105+
4. Approve and merge when ready
106+
107+
## 🤖 Copilot PR Reviewer (Automatic)
108+
109+
The **Copilot PR Reviewer** automatically analyzes every pull request:
110+
111+
- 🔄 **Triggers on every PR** - Open or update
112+
- 🔍 **Analyzes all changed files** - Security, performance, code quality
113+
- 💬 **Posts review comments** - With actionable recommendations
114+
- 📊 **Generates analysis report** - Available as artifact
115+
116+
### Review Process
117+
118+
```
119+
PR Opened/Updated
120+
↓
121+
Reviewer Workflow Triggers (Automatic)
122+
↓
123+
1️⃣ Download Changed Files
124+
2️⃣ Run Copilot Analysis
125+
3️⃣ Post Review Comments
126+
↓
127+
� Feedback Ready for Developer
128+
```
129+
130+
### Example Review Output
131+
132+
Copilot identifies and comments on issues like:
133+
134+
- 🔒 **Security**: SQL injection, exposed secrets, unsafe deserialization
135+
- ⚡ **Performance**: Inefficient loops, unnecessary allocations, N+1 queries
136+
- 🧹 **Code Quality**: Naming, documentation, complexity, error handling
137+
- 📝 **Best Practices**: Type safety, error handling, edge cases
138+
139+
**No action required!** The reviewer workflow runs automatically on every PR. Just merge your code after addressing the findings.
140+
141+
For detailed information, see [Copilot PR Reviewer Documentation](docs/COPILOT-REVIEWER.md).
96142

97-
## 🎯 How It Works
143+
## �🎯 How It Works
98144

99-
### Workflow Trigger
145+
### Coder Workflow Trigger
100146

101147
```yaml
102148
on:
103149
issues:
104150
types: [opened, labeled]
105151
```
106152
107-
The workflow triggers when:
153+
The coder workflow triggers when:
108154
- An issue is opened with the `copilot` label
109155
- The `copilot` label is added to an existing issue
110156

157+
### Reviewer Workflow Trigger
158+
159+
```yaml
160+
on:
161+
pull_request:
162+
types: [opened, synchronize]
163+
```
164+
165+
The reviewer workflow triggers when:
166+
- A pull request is opened
167+
- A pull request is updated (new commits)
168+
111169
### Architecture
112170

113171
```
@@ -147,21 +205,28 @@ Update Labels (completed, ready-for-review)
147205
```
148206
.github/
149207
├── workflows/
150-
│ └── copilot-coder.yml # Main GitHub Actions workflow
151-
└── copilot-instructions.md # Instructions for Copilot CLI
208+
│ ├── copilot-coder.yml # Code generation workflow
209+
│ └── copilot-reviewer.yml # PR review workflow (NEW!)
210+
└── copilot-instructions.md # Instructions for Copilot CLI
152211

153212
scripts/
154-
├── prepare-commit.sh # Prepare commit with co-author
155-
├── push-branch.sh # Push branch to remote
156-
├── post-workflow-comment.sh # Post completion comment
157-
└── post-workflow-comment.sh # Post completion comment
213+
├── prepare-commit.sh # Prepare commit with co-author
214+
├── push-branch.sh # Push branch to remote
215+
├── post-workflow-comment.sh # Post completion comment
216+
├── get-pr-diff.sh # Get PR file changes (reviewer)
217+
├── download-pr-files.sh # Download changed files (reviewer)
218+
├── analyze-with-copilot.sh # Run AI analysis (reviewer)
219+
└── post-pr-comment.sh # Post review comments (reviewer)
158220

159221
docs/
160-
├── GHES-SETUP.md # Detailed setup guide
161-
├── MIGRATION-GUIDE.md # Migration from ADO guide
162-
└── TROUBLESHOOTING.md # Common issues and solutions
163-
164-
mcp-config.json # MCP servers configuration
222+
├── GHES-SETUP.md # Detailed setup guide
223+
├── GHES-COMPATIBILITY.md # GHES compatibility info
224+
├── COPILOT-REVIEWER.md # PR Reviewer documentation (NEW!)
225+
├── REVIEWER-MIGRATION.md # ADO to GHES adaptation guide (NEW!)
226+
├── MIGRATION-GUIDE.md # Migration from ADO guide
227+
└── TROUBLESHOOTING.md # Common issues and solutions
228+
229+
mcp-config.json # MCP servers configuration
165230
```
166231
167232
## 🛠️ Technologies Used
@@ -340,8 +405,12 @@ permissions:
340405

341406
Detailed guides are available in the `docs/` directory:
342407

408+
Detailed guides are available in the `docs/` directory:
409+
343410
- **[GHES Setup Guide](docs/GHES-SETUP.md)** - Complete setup instructions
411+
- **[Copilot PR Reviewer Guide](docs/COPILOT-REVIEWER.md)** - Automated PR review
344412
- **[Migration Guide](docs/MIGRATION-GUIDE.md)** - Migrate from Azure DevOps
413+
- **[Reviewer Migration Guide](docs/REVIEWER-MIGRATION.md)** - ADO Reviewer adaptation details
345414
- **[Troubleshooting](docs/TROUBLESHOOTING.md)** - Common issues and solutions
346415

347416
## 🔄 Migration from Azure DevOps
@@ -353,6 +422,18 @@ If you're migrating from the Azure DevOps implementation, see the **[Migration G
353422
- Parallel operation strategies
354423
- Cleanup procedures
355424

425+
### ADO Reviewer Agent Porting
426+
427+
The **Copilot PR Reviewer** is an adaptation of the [ADO_ReviewerAgent](https://github.com/0GiS0/ADO_ReviewerAgent) project by [0GiS0](https://github.com/0GiS0), adapted for GitHub Enterprise Server.
428+
429+
Key adaptations:
430+
- ✅ Azure Pipelines → GitHub Actions
431+
- ✅ Azure DevOps API → GitHub API
432+
- ✅ ADO authentication → GitHub token auth
433+
- ✅ Thread comments → Review comments
434+
435+
See [REVIEWER-MIGRATION.md](docs/REVIEWER-MIGRATION.md) for detailed technical comparison.
436+
356437
Legacy ADO documentation: [README-ADO.md](README-ADO.md)
357438

358439
## 🆘 Troubleshooting

0 commit comments

Comments
 (0)