From 8615648930a02a70f7a669dc67dcccfbd866bbfa Mon Sep 17 00:00:00 2001 From: Sekiro4321 <155538724+Sekiro4321@users.noreply.github.com> Date: Wed, 4 Feb 2026 20:32:50 +0530 Subject: [PATCH 1/8] Added A Multipy function, tests, CI Workflow --- .github/workflows/ci.yml | 27 +++++++++++++++++++++++++++ app.py | 4 ++++ tests/test_app.py | 14 +++++++++++++- 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..1bb952eb --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,27 @@ +name: CI + +on : + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install Dependencies + run: pip install -r requirements.txt + + - name: Run Tests + run: pytest -v + \ No newline at end of file diff --git a/app.py b/app.py index 8f2f7ae1..86919caf 100644 --- a/app.py +++ b/app.py @@ -14,3 +14,7 @@ def is_even(n: int) -> bool: def reverse_string(s: str) -> str: """Reverse a string.""" return s[::-1] + +def multiply(a: int, b: int) -> int: + """Multiply two numbers together.""" + return a * b \ No newline at end of file diff --git a/tests/test_app.py b/tests/test_app.py index 79c3e093..9eee85cc 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -1,6 +1,6 @@ """Tests for app.py - you'll add more!""" -from app import add, is_even, reverse_string +from app import add, is_even, reverse_string, multiply class TestMath: @@ -22,3 +22,15 @@ def test_reverse(self): def test_is_even(self): assert is_even(4) is True assert is_even(3) is False + +class TestMultiply: + """Tests for multiply function.""" + + def test_multiply_positive(self): + assert multiply(2, 3) == 6 + + def test_multiply_negative(self): + assert multiply(-1, 6) == -6 + + def test_multiply_zero(self): + assert multiply(0, 5) == 0 \ No newline at end of file From c4ab0fdd3f65eb97389ea50b157164b30b3bbd44 Mon Sep 17 00:00:00 2001 From: Sekiro4321 <155538724+Sekiro4321@users.noreply.github.com> Date: Wed, 4 Feb 2026 20:38:46 +0530 Subject: [PATCH 2/8] Broke the Test --- tests/test_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_app.py b/tests/test_app.py index 9eee85cc..53cf0120 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -27,7 +27,7 @@ class TestMultiply: """Tests for multiply function.""" def test_multiply_positive(self): - assert multiply(2, 3) == 6 + assert multiply(9, 9) == 81 # Corrected assertion def test_multiply_negative(self): assert multiply(-1, 6) == -6 From 4afdf7622e9066639ca719050ecdbbe5799d17c4 Mon Sep 17 00:00:00 2001 From: Sekiro4321 <155538724+Sekiro4321@users.noreply.github.com> Date: Wed, 4 Feb 2026 20:40:30 +0530 Subject: [PATCH 3/8] Broke the Test --- tests/test_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_app.py b/tests/test_app.py index 53cf0120..1596aa22 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -27,7 +27,7 @@ class TestMultiply: """Tests for multiply function.""" def test_multiply_positive(self): - assert multiply(9, 9) == 81 # Corrected assertion + assert multiply(9, 9) == 18 # Corrected assertion def test_multiply_negative(self): assert multiply(-1, 6) == -6 From eb9822fe5ca6e6e1e4584f0b442fa3f91c1510ba Mon Sep 17 00:00:00 2001 From: Sekiro4321 <155538724+Sekiro4321@users.noreply.github.com> Date: Wed, 4 Feb 2026 20:41:40 +0530 Subject: [PATCH 4/8] Fixed the Test --- tests/test_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_app.py b/tests/test_app.py index 1596aa22..53cf0120 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -27,7 +27,7 @@ class TestMultiply: """Tests for multiply function.""" def test_multiply_positive(self): - assert multiply(9, 9) == 18 # Corrected assertion + assert multiply(9, 9) == 81 # Corrected assertion def test_multiply_negative(self): assert multiply(-1, 6) == -6 From 12f699495379a5f20b58e6c083d1cec35ee3f6a8 Mon Sep 17 00:00:00 2001 From: Sekiro4321 <155538724+Sekiro4321@users.noreply.github.com> Date: Wed, 4 Feb 2026 20:51:15 +0530 Subject: [PATCH 5/8] Add build and artifact upload to CI --- .github/workflows/ci.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1bb952eb..acd3a61f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,4 +24,12 @@ jobs: - name: Run Tests run: pytest -v - \ No newline at end of file + + - name: Build package + run: python -m build + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: python-package + path: dist/ From 6546e8d45404a174a1644638537f217319ec563e Mon Sep 17 00:00:00 2001 From: Sekiro4321 <155538724+Sekiro4321@users.noreply.github.com> Date: Sun, 8 Feb 2026 22:02:18 +0530 Subject: [PATCH 6/8] Add AI code review script and PR workflow --- .github/workflows/pr-review.yml | 56 +++++++++++++++++++++++++++++++++ requirements.txt | 2 +- scripts/ai_review.py | 47 +++++++++++++++++++++++++++ scripts/sample_diff.txt | 17 ++++++++++ 4 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/pr-review.yml create mode 100644 scripts/ai_review.py create mode 100644 scripts/sample_diff.txt diff --git a/.github/workflows/pr-review.yml b/.github/workflows/pr-review.yml new file mode 100644 index 00000000..1bbebca3 --- /dev/null +++ b/.github/workflows/pr-review.yml @@ -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<> $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*` + }); diff --git a/requirements.txt b/requirements.txt index 5f456517..245709a3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ # Production dependencies (none for this simple app) - +google-genai>=1.0.0 # Development/testing dependencies pytest>=7.0.0 build>=1.0.0 diff --git a/scripts/ai_review.py b/scripts/ai_review.py new file mode 100644 index 00000000..24f28deb --- /dev/null +++ b/scripts/ai_review.py @@ -0,0 +1,47 @@ +from google import genai +import sys + +client = genai.Client() + + +def ReviewCode(diff_code): + + prompt = f"""You are an expert code reviewer. Review the following code diff and provide feedback. + +Focus on: +1. Security vulnerabilities +2. Bug risks +3. Performance issues +4. Best practice violations + +For each issue found, provide: +- Severity: HIGH / MEDIUM / LOW +- Description of the issue +- Suggested fix + +If the code looks good, say so. + +Keep The reveiew Concise and to the point. Do not provide feedback on code that has been deleted, only on new or modified code. + +Code diff to review: + +{diff_code} + + +Provide your review in a clear, structured format.""" + + response = client.models.generate_content( + model="gemini-2.5-flash", contents=prompt + ) + return response.text + +if __name__ == "__main__": + if len(sys.argv) > 1: + diff_file = sys.argv[1] + with open(diff_file, 'r') as f: + diff_code = f.read() + else: + diff_code = sys.stdin.read() + + review = ReviewCode(diff_code) + print(review) \ No newline at end of file diff --git a/scripts/sample_diff.txt b/scripts/sample_diff.txt new file mode 100644 index 00000000..d4b5984b --- /dev/null +++ b/scripts/sample_diff.txt @@ -0,0 +1,17 @@ +diff --git a/app.py b/app.py +index 1234567..abcdefg 100644 +--- a/app.py ++++ b/app.py +@@ -1,5 +1,12 @@ + """Simple utility functions""" + ++import sqlite3 ++ ++def get_user(username): ++ conn = sqlite3.connect("users.db") ++ query = f"SELECT * FROM users WHERE name = '{username}'" ++ return conn.execute(query).fetchone() ++ + def add(a: int, b: int) -> int: + """Add two numbers together.""" + return a + b From b24d8729956bb74a75d9bb8bb7d23a1fc59df568 Mon Sep 17 00:00:00 2001 From: Sekiro4321 <155538724+Sekiro4321@users.noreply.github.com> Date: Sun, 8 Feb 2026 22:06:22 +0530 Subject: [PATCH 7/8] Add command execution feature --- scripts/dangerous.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 scripts/dangerous.py diff --git a/scripts/dangerous.py b/scripts/dangerous.py new file mode 100644 index 00000000..5d477bcb --- /dev/null +++ b/scripts/dangerous.py @@ -0,0 +1,7 @@ +import subprocess + +def run_command(user_input): + """Run a shell command from user input.""" + subprocess.call(user_input, shell=True) + +API_KEY = "sk-live-abc123def456" From 4a10421744ad2d74fd163272a9da9f567257353b Mon Sep 17 00:00:00 2001 From: Sekiro4321 <155538724+Sekiro4321@users.noreply.github.com> Date: Sun, 8 Feb 2026 22:19:25 +0530 Subject: [PATCH 8/8] Fix security issues --- scripts/dangerous.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/dangerous.py b/scripts/dangerous.py index 5d477bcb..86d316f3 100644 --- a/scripts/dangerous.py +++ b/scripts/dangerous.py @@ -1,7 +1,10 @@ import subprocess +import shlex +import os def run_command(user_input): - """Run a shell command from user input.""" - subprocess.call(user_input, shell=True) + """Run a shell command safely.""" + args = shlex.split(user_input) + subprocess.call(args, shell=False) -API_KEY = "sk-live-abc123def456" +API_KEY = os.environ.get("API_KEY")