Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/pr-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: AI Code Review

on:
pull_request:
branches: [main]

permissions:
contents: read
pull-requests: write

jobs:
review:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install dependencies
run: pip install -r requirements.txt

- name: Get PR diff
run: |
git diff origin/main...HEAD > pr_diff.txt

- name: Run AI review
id: ai-review
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
run: |
REVIEW=$(python scripts/ai_review.py pr_diff.txt)
echo "review<<EOF" >> $GITHUB_OUTPUT
echo "$REVIEW" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

- name: Post review comment
uses: actions/github-script@v7
env:
REVIEW: ${{ steps.ai-review.outputs.review }}
with:
script: |
const review = process.env.REVIEW;

await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `## 🤖 AI Code Review\n\n${review}\n\n---\n*Powered by Gemini AI*`
});
49 changes: 49 additions & 0 deletions .github/workflows/stale_code.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Stale Code Detector

on:
# Run every Monday at 9:00 AM UTC
schedule:
- cron: '0 9 * * 1'
# Allow manual triggering for testing
workflow_dispatch:

permissions:
contents: read
issues: write

jobs:
detect-stale-code:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install dependencies
run: |
pip install google-genai

- name: Run stale code detector
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
run: |
python scripts/find_stale.py || true

- name: Create GitHub Issue
if: hashFiles('stale_code_report.md') != ''
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Check if report has findings (not just "No dead code detected")
if grep -q "Found .* potential issues" stale_code_report.md; then
gh issue create \
--title "Weekly Stale Code Report - $(date +%Y-%m-%d)" \
--body-file stale_code_report.md
else
echo "No stale code findings to report"
fi
79 changes: 79 additions & 0 deletions .github/workflows/test-gen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: AI Test Generation

on:
pull_request:
types: [opened, synchronize]
paths:
- '**.py'
- '!tests/**'

jobs:
generate-tests:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install dependencies
run: |
pip install -r requirements.txt

- name: Check coverage threshold
id: coverage-check
continue-on-error: true
run: python scripts/check_coverage.py 80

- name: Skip message (coverage sufficient)
if: steps.coverage-check.outcome == 'success'
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '**Coverage check passed!** No additional tests needed.'
})


- name: Get changed Python files
if: steps.coverage-check.outcome == 'failure'
id: changed-files
run: |
FILES=$(git diff --name-only origin/${{ github.base_ref }}..HEAD -- '*.py' | grep -v '^tests/' | tr '\n' ' ')
echo "files=$FILES" >> $GITHUB_OUTPUT

- name: Generate tests
if: steps.coverage-check.outcome == 'failure' && steps.changed-files.outputs.files != ''
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
run: |
python scripts/generate_tests.py ${{ steps.changed-files.outputs.files }}

- name: Commit generated tests
if: steps.coverage-check.outcome == 'failure'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

if git diff --quiet tests/; then
echo "No new tests generated"
exit 0
fi

git add tests/
git commit -m "Auto-generate tests for new code [skip ci]"
git push
Binary file added Error-pics/error 1 fixed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Error-pics/error 1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Error-pics/error 2.1 poss fix explained.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Error-pics/error 2.1 poss fix.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Error-pics/error 2.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Error-pics/error 2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Error-pics/error 3 its working.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Error-pics/error 3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
149 changes: 149 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,152 @@ ci-starter/
├── requirements.txt
└── pyproject.toml
```

## Troubleshooting Guide

### Common Errors & Solutions

Below are real errors encountered during setup and their solutions:

---

#### Error 1: Git User Identity Not Configured

**Error Message:**
```
Author identity unknown
*** Please tell me who you are.
fatal: unable to auto-detect email address
```

![Error 1](Error-pics/error%201.png)

**What Happened:**
When trying to commit changes, git doesn't know who you are. Git requires a username and email to associate with commits.

**Solution:**
Configure your git identity globally:

```bash
git config --global user.name "your-github-username"
git config --global user.email "your-email@example.com"
```

![Error 1 Fixed](Error-pics/error%201%20fixed.png)

**Prevention:** Always configure git when setting up a new machine or development environment.

---

#### Error 2: Empty Workflow Files on Main Branch

**Error Message:**
```
Error: No event triggers defined in `on`
```

![Error 2](Error-pics/error%202.png)

**What Happened:**
The workflow files (`.github/workflows/pr-review.yml` and `.github/workflows/test-gen.yml`) existed on the main branch but were **empty**. When GitHub tries to run workflows for a PR, it uses the workflow files from the target branch (main), not the source branch. Since they were empty, GitHub couldn't find any trigger events.

**Root Cause:**
The workflow files were created but never properly populated with content on the main branch. This happened because:
1. Files were created with placeholders
2. Content was added to the feature branch
3. But the main branch still had empty files

![Error 2 Diagnosis](Error-pics/error%202.1.png)

**Solution:**
1. Switch to main branch
2. Add proper workflow content to both files
3. Commit and push to main

```bash
git checkout main
# Edit .github/workflows/pr-review.yml and test-gen.yml with proper content
git add .github/workflows/
git commit -m "Fix empty workflow files on main branch"
git push origin main
```

![Error 2 Fix](Error-pics/error%202.1%20poss%20fix.png)

The workflow files need to have the complete YAML configuration including:
- `name:` - Workflow name
- `on:` - Trigger events (pull_request, push, etc.)
- `jobs:` - The actual jobs to run

![Error 2 Fix Explained](Error-pics/error%202.1%20poss%20fix%20explained.png)

---

#### Error 3: Workflow Files on Feature Branch

**Error Message:**
```
Error: No event triggers defined in `on`
(When pushing to feature branch)
```

![Error 3](Error-pics/error%203.png)

**What Happened:**
The workflow files existed on BOTH the main branch AND the feature branch. When pushing to the feature branch, GitHub tried to run the workflows from that branch. However:
- `pr-review.yml` is configured to trigger ONLY on `pull_request` events
- Pushing to a branch triggers a `push` event, not a `pull_request` event
- GitHub complained because it was trying to run a workflow that had no matching trigger

**Solution:**
Remove workflow files from the feature branch since they should only exist on the target branch (main):

```bash
git checkout feature/new-function
git rm .github/workflows/pr-review.yml .github/workflows/test-gen.yml
git commit -m "Remove workflow files from feature branch"
git push
```

![Error 3 Fix](Error-pics/error%203%20fix%20replaced%20code%20in%202%20files.png)

**Best Practice:**
- Workflow files for PRs should live on the target branch (usually `main`)
- Don't include `.github/workflows/` files in feature branches unless you specifically need them
- PR workflows will use the configuration from the target branch, not the source branch

![Error 3 Success](Error-pics/error%203%20its%20working.png)

---

### Success Checklist

After fixing all errors, you should see:

✅ Green checkmarks on your PR
✅ AI Code Review bot comment with analysis
✅ AI Test Generation completing successfully
✅ All workflow runs passing

---

## Tips for Success

1. **Always configure git first:**
```bash
git config --global user.name "username"
git config --global user.email "email@example.com"
```

2. **Keep workflow files on main branch only** (for PR workflows)

3. **Check workflow files aren't empty:**
```bash
cat .github/workflows/pr-review.yml # Should show content, not empty
```

4. **Create actual PRs** - Workflows only trigger on real PR events, not just pushes

5. **Wait for workflows to complete** - Give them 1-2 minutes to run

6. **Check the Actions tab** for detailed logs if something fails
14 changes: 14 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,17 @@ def is_even(n: int) -> bool:
def reverse_string(s: str) -> str:
"""Reverse a string."""
return s[::-1]


def power(base, exponent):
"""
Calculate base raised to the power of exponent.

Args:
base: The base number
exponent: The power to raise the base to

Returns:
The result of base^exponent
"""
return base ** exponent
5 changes: 5 additions & 0 deletions more_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def is_palindrome(text):
"""Check if a string is a palindrome."""
cleaned = text.lower().replace(" ", "")
return cleaned == cleaned[::-1]

2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
# Development/testing dependencies
pytest>=7.0.0
build>=1.0.0
google-genai>=1.0.0
pytest-cov>=4.0.0
Loading