Skip to content

Commit 72e45dd

Browse files
CopilotFuzzysTodd
andcommitted
Add GitHub workflow and documentation for Gemini agent
Co-authored-by: FuzzysTodd <157565446+FuzzysTodd@users.noreply.github.com>
1 parent b33ec15 commit 72e45dd

2 files changed

Lines changed: 149 additions & 0 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Gemini Code Analysis
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
file_path:
7+
description: 'Path to the file to analyze'
8+
required: true
9+
type: string
10+
pull_request:
11+
types: [opened, synchronize]
12+
13+
permissions:
14+
contents: read
15+
pull-requests: write
16+
17+
jobs:
18+
analyze:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
23+
with:
24+
persist-credentials: false
25+
26+
- name: Setup Node.js
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: '18'
30+
31+
- name: Run Gemini Analysis (Manual)
32+
if: github.event_name == 'workflow_dispatch'
33+
env:
34+
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
35+
run: |
36+
if [ -z "$GEMINI_API_KEY" ]; then
37+
echo "Warning: GEMINI_API_KEY secret is not set. Skipping analysis."
38+
exit 0
39+
fi
40+
node scripts/gemini_agent.js "${{ github.event.inputs.file_path }}" --api-key="$GEMINI_API_KEY"
41+
42+
- name: Run Gemini Analysis (PR)
43+
if: github.event_name == 'pull_request'
44+
env:
45+
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
46+
run: |
47+
if [ -z "$GEMINI_API_KEY" ]; then
48+
echo "Warning: GEMINI_API_KEY secret is not set. Skipping analysis."
49+
exit 0
50+
fi
51+
52+
# Get list of changed files in the PR
53+
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -E '\.(go|js|ts|sol)$' || true)
54+
55+
if [ -z "$CHANGED_FILES" ]; then
56+
echo "No relevant files changed in this PR."
57+
exit 0
58+
fi
59+
60+
# Analyze each changed file
61+
echo "$CHANGED_FILES" | while read -r file; do
62+
if [ -f "$file" ]; then
63+
echo "Analyzing $file..."
64+
node scripts/gemini_agent.js "$file" --api-key="$GEMINI_API_KEY" || true
65+
fi
66+
done

scripts/GEMINI_AGENT_README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Gemini Code Analysis Agent
2+
3+
This script uses Google's Gemini AI model to analyze code for potential vulnerabilities, best practice deviations, and mathematical instability.
4+
5+
## Features
6+
7+
- Analyzes code files using the Gemini 2.5 Flash Preview model
8+
- Provides a Protocol Stability Score (1-10)
9+
- Identifies potential flaws and security issues
10+
- Suggests repaired code when issues are found
11+
12+
## Prerequisites
13+
14+
- Node.js 18+ (which includes built-in fetch support)
15+
- A Google Gemini API key
16+
17+
## Usage
18+
19+
### Command Line
20+
21+
```bash
22+
node scripts/gemini_agent.js <filepath> --api-key=<your_key>
23+
```
24+
25+
Example:
26+
```bash
27+
node scripts/gemini_agent.js ./pkg/model/model.go --api-key=your_gemini_api_key
28+
```
29+
30+
### GitHub Actions
31+
32+
The script can be run automatically via GitHub Actions:
33+
34+
1. **Manual Trigger**: Go to Actions → "Gemini Code Analysis" → Run workflow, and specify the file path
35+
2. **Automatic PR Analysis**: The workflow will automatically analyze changed files in pull requests (if GEMINI_API_KEY secret is configured)
36+
37+
## Setting up the API Key
38+
39+
### For Local Development
40+
41+
```bash
42+
node scripts/gemini_agent.js path/to/file.go --api-key=YOUR_API_KEY
43+
```
44+
45+
### For GitHub Actions
46+
47+
Add `GEMINI_API_KEY` as a repository secret:
48+
49+
1. Go to your repository settings
50+
2. Navigate to Secrets and variables → Actions
51+
3. Add a new secret named `GEMINI_API_KEY`
52+
4. Paste your Google Gemini API key
53+
54+
## Getting a Gemini API Key
55+
56+
1. Visit [Google AI Studio](https://makersuite.google.com/app/apikey)
57+
2. Sign in with your Google account
58+
3. Create a new API key
59+
4. Copy the key for use with this script
60+
61+
## Output
62+
63+
The script will output:
64+
- Protocol Stability Score (1-10)
65+
- Summary of potential flaws
66+
- Repaired code block (if issues are found)
67+
- "NO REPAIR NEEDED" (if code is perfect)
68+
69+
## Error Handling
70+
71+
The script includes comprehensive error handling:
72+
- Missing API key: Shows usage instructions
73+
- Missing file: Shows file read error
74+
- API failures: Shows detailed error message
75+
- Network issues: Gracefully handles fetch failures
76+
77+
## Note
78+
79+
This is a conceptual implementation designed for protocol analysis. The script can be extended to:
80+
- Write repaired code back to files
81+
- Comment on GitHub PRs with analysis results
82+
- Support batch analysis of multiple files
83+
- Integrate with CI/CD pipelines

0 commit comments

Comments
 (0)