Skip to content
Open

pr #2

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
01e7e74
Delete .github/workflows/ci.yml
kahu-bit Jan 23, 2026
e008ea5
Added workflow
CARWHO Jan 23, 2026
956dfa8
Break a test
CARWHO Jan 23, 2026
ebfa8eb
Fix the test
CARWHO Jan 23, 2026
a45d8bf
Add build and artifact upload to CI
CARWHO Jan 23, 2026
53cb057
Add multiply function, tests, and CI workflow
CARWHO Jan 23, 2026
d842687
Break a test
CARWHO Jan 23, 2026
bf46578
Fix the test
CARWHO Jan 23, 2026
0f9409d
Add build and artifact upload to CI
CARWHO Jan 23, 2026
ee6888b
Add AI code review script and PR workflow
CARWHO Jan 24, 2026
3401e71
Add test generation script and workflow
CARWHO Jan 27, 2026
e581b00
Add factorial function
CARWHO Jan 27, 2026
7c6eab2
Add factorial function
CARWHO Jan 27, 2026
6b8f8da
Add factorial function
CARWHO Jan 27, 2026
4e96d91
Add factorial function
CARWHO Jan 27, 2026
3d31fc5
Add factorial function
CARWHO Jan 27, 2026
b477870
Add factorial function
CARWHO Jan 27, 2026
32c1ac9
Auto-generate tests for new code [skip ci]
github-actions[bot] Jan 27, 2026
c501ee2
Updated
CARWHO Jan 27, 2026
560b079
Merge branch 'feature/new-function_' of https://github.com/kahu-bit/a…
CARWHO Jan 27, 2026
487ca05
Merge pull request #28 from kahu-bit/feature/new-function_
kahu-bit Jan 27, 2026
212b4c5
Updated
CARWHO Jan 27, 2026
0f94615
Add factorial function
CARWHO Jan 27, 2026
5a3bd63
Add factorial function
CARWHO Jan 27, 2026
0fdaeaa
Add factorial function
CARWHO Jan 27, 2026
b6ab698
Merge pull request #29 from kahu-bit/feature/new-function_
kahu-bit Jan 27, 2026
3e258f7
Add factorial function
CARWHO Jan 27, 2026
bf910d1
Updated
CARWHO Jan 27, 2026
c8436f3
Merge pull request #30 from kahu-bit/feature/new-function_
kahu-bit Jan 27, 2026
37db13c
Add factorial function
CARWHO Jan 27, 2026
5c9c08a
Auto-generate tests for new code [skip ci]
github-actions[bot] Jan 27, 2026
4dabfc1
Merge pull request #31 from kahu-bit/feature/new-function_
kahu-bit Jan 27, 2026
f5502b5
Add palindrome checker (no tests)
CARWHO Jan 27, 2026
1eb0a94
Auto-generate tests for new code [skip ci]
github-actions[bot] Jan 27, 2026
6a83556
Merge pull request #32 from kahu-bit/feature/untested-function_
kahu-bit Jan 27, 2026
6f77efe
Add stale code detector with weekly workflow
CARWHO Jan 28, 2026
28aaacf
Add stale code detector with weekly workflow
CARWHO Jan 28, 2026
e87e1dc
Add stale code detector with weekly workflow
CARWHO Jan 28, 2026
c95a925
Add stale code detector with weekly workflow
CARWHO Jan 28, 2026
7386c40
Added delay
CARWHO Jan 28, 2026
874c537
Added delay
CARWHO Jan 28, 2026
9465298
Added delay
CARWHO Jan 28, 2026
9931e28
Force sync
CARWHO Jan 28, 2026
78e34f7
Added delay
CARWHO Jan 28, 2026
ebd5289
Add time estimates to stale code detector
CARWHO Jan 28, 2026
42e9495
Add time estimates to stale code detector
CARWHO Jan 28, 2026
9d12345
Fix hashFiles condition - evaluate at runtime
CARWHO Jan 28, 2026
ea0ff02
Updated
CARWHO Jan 29, 2026
eb74f97
Updated
CARWHO Jan 29, 2026
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
26 changes: 9 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: CI Pipeline
name: CI

on:
push:
branches: [master]
branches: [main]
pull_request:
branches: [master]
branches: [main]

jobs:
build:
Expand All @@ -20,24 +20,16 @@ jobs:
python-version: '3.11'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install ruff pytest
run: pip install -r requirements.txt

- name: Run linter (ruff)
run: ruff check .

- name: Run tests (pytest)
- name: Run tests
run: pytest -v

- name: Build distribution
run: |
pip install build
python -m build
- name: Build package
run: python -m build

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
name: python-package
path: dist/
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*`
});
48 changes: 48 additions & 0 deletions .github/workflows/stale-code.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Check if report exists and has findings
if [ -f stale_code_report.md ] && grep -q "issues found" 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
59 changes: 59 additions & 0 deletions .github/workflows/test-gen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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: Get changed Python files
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.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
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

if [ -z "$(git status --porcelain 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
21 changes: 21 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,24 @@ def is_even(n: int) -> bool:
def reverse_string(s: str) -> str:
"""Reverse a string."""
return s[::-1]


def multiply(a,b):
"""Multiply two integers, a and b"""
return a * b

def factorial(n):
"""Calculate the factorial of n."""

# Handle invalid input - factorial isn't defined for negatives
if n < 0:
raise ValueError(
"Factorial not defined for negative numbers"
)

# Base case - stop recursion when n is 0 or 1
if n <= 1:
return 1

# Recursive case - n! = n × (n-1)!
return n * factorial(n-1)
9 changes: 9 additions & 0 deletions more_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import random
import string

def generate_password(length=12, include_symbols=True):
"""Generate a random password with specified length."""
characters = string.ascii_letters + string.digits
if include_symbols:
characters += string.punctuation
return ''.join(random.choice(characters) for _ in range(length))
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ version = "0.1.0"
description = "A starter project for learning GitHub Actions CI/CD"
readme = "README.md"
requires-python = ">=3.9"
license = {text = "MIT"}
license = "MIT"
authors = [
{name = "Your Name", email = "you@example.com"}
]

[tool.setuptools]
py-modules = ["app", "more_utils"]

[project.optional-dependencies]
dev = [
"pytest>=7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Production dependencies (none for this simple app)
google-genai>=1.0.0

# Development/testing dependencies
pytest>=7.0.0
ruff>=0.1.0
build>=1.0.0
39 changes: 39 additions & 0 deletions scripts/ai_review.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from google import genai
import sys

client = genai.Client()

# Define a function that takes a code diff as input
def review_code(diff_text):

# Write a multi-line f-string prompt that includes {diff_text}
# Tell Gemini to act as a code reviewer and focus on security, bugs, performance
prompt = f""" Act as a code reviewer and focus on security, bugs and performance {diff_text}"""

# Send the prompt to the model and get a response
response = client.models.generate_content(
model="gemini-2.5-flash", contents=prompt
)

# Return just the text from the response
return response.text

# Only run this code when the script is executed directly
if __name__ == "__main__":

# Check if a filename was passed as a command-line argument
if len(sys.argv) > 1:

# Get the filename from sys.argv and read the file
diff_file = sys.argv[1]
with open(diff_file, "r") as f:
diff_content = f.read()

# If no filename was passed, read from standard input
else:
diff_content = sys.stdin.read()

# Call the review function and print the result
review = review_code(diff_content)
print(review)

Loading