Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] AI 코드 리뷰 시스템 구축 #15

Open
wants to merge 74 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
c9142a7
chore(BE): AI 코드 리뷰 워크플로우 추가
viaunixue Oct 4, 2024
c1b9525
feat(BE): AI 코드 리뷰 로직 추가
viaunixue Oct 4, 2024
652d78d
chore(BE): AI 코드 리뷰 프롬프트 추가
viaunixue Oct 4, 2024
675820a
refactor(BE): AI 코드 리뷰 로직 수정
viaunixue Oct 4, 2024
58b3ea3
feat(BE): AI 코드 리뷰 로직 수정
viaunixue Oct 4, 2024
de6ce5e
chore(BE): AI 코드 리뷰 워크플로우 수정
viaunixue Oct 4, 2024
7a70d85
chore(BE): AI 코드 리뷰 워크플로우 수정
viaunixue Oct 4, 2024
eae1916
chore(BE): AI 코드 리뷰 워크플로우 수정
viaunixue Oct 4, 2024
1b0b481
chore(BE): AI 코드 리뷰 워크플로우 수정
viaunixue Oct 4, 2024
a6b6e45
chore(BE): AI 코드 리뷰 워크플로우 수정
viaunixue Oct 4, 2024
fecf1bc
chore(BE): AI 코드 리뷰 워크플로우 수정
viaunixue Oct 5, 2024
c03fbd7
refactor(BE): AI 코드 리뷰 로직 수정
viaunixue Oct 5, 2024
f83c691
refactor(BE): AI 코드 리뷰 로직 수정
viaunixue Oct 5, 2024
2cae807
refactor(BE): AI 코드 리뷰 로직 수정
viaunixue Oct 5, 2024
2140039
refactor(BE): AI 코드 리뷰 로직 수정
viaunixue Oct 5, 2024
c5a642b
refactor(BE): AI 코드 리뷰 로직 수정
viaunixue Oct 7, 2024
40c9adb
refactor(BE): AI 코드 리뷰 로직 수정
viaunixue Oct 7, 2024
cbe72ca
test(BE): AI 코드 리뷰 테스트
viaunixue Oct 7, 2024
eae5402
refactor(BE): AI 코드 리뷰 로직 수정
viaunixue Oct 7, 2024
d310b4c
refactor(BE): AI 코드 리뷰 로직 수정
viaunixue Oct 7, 2024
9c0209e
refactor(BE): AI 코드 리뷰 로직 수정
viaunixue Oct 7, 2024
8449bda
refactor(BE): AI 코드 리뷰 로직 수정
viaunixue Oct 7, 2024
01567e3
refactor(BE): AI 코드 리뷰 로직 수정
viaunixue Oct 7, 2024
66dc263
refactor(BE): AI 코드 리뷰 로직 수정
viaunixue Oct 7, 2024
5cb4c13
refactor(BE): AI 코드 리뷰 로직 수정
viaunixue Oct 7, 2024
aa39f64
refactor(BE): AI 코드 리뷰 로직 수정
viaunixue Oct 7, 2024
1b82091
refactor(BE): AI 코드 리뷰 로직 수정
viaunixue Oct 7, 2024
836b65a
refactor(BE): AI 코드 리뷰 로직 수정
viaunixue Oct 7, 2024
93885c3
refactor(BE): AI 코드 리뷰 로직 수정
viaunixue Oct 7, 2024
1ae125e
refactor(BE): AI 코드 리뷰 로직 수정
viaunixue Oct 7, 2024
1161f1e
refactor(BE): AI 코드 리뷰 Groq 적용
viaunixue Oct 7, 2024
9240aab
refactor(BE): AI 코드 리뷰 Groq 적용
viaunixue Oct 7, 2024
86fbd46
fix(BE): AI 코드 리뷰 Groq 환경변수 경로 설정
viaunixue Oct 7, 2024
df063d8
refactor(BE): AI 코드 리뷰 프롬프트 수정
viaunixue Oct 7, 2024
92e8bf1
refactor(BE): AI 코드 리뷰 로직 수정
viaunixue Oct 7, 2024
afe21bd
refactor(BE): AI 코드 리뷰 프롬프트 수정
viaunixue Oct 7, 2024
5ba5e2a
refactor(BE): AI 코드 리뷰 로직 수정
viaunixue Oct 8, 2024
23ebf36
feat(BE): AI 코드 리뷰 환경 파일 추가
viaunixue Oct 8, 2024
fbe3f23
refactor(BE): AI 코드 리뷰 로직 수정
viaunixue Oct 8, 2024
506037b
refactor(BE): AI 코드 리뷰 로직 수정
viaunixue Oct 8, 2024
21b1ef3
refactor(BE): AI 코드 리뷰 프롬프트 수정
viaunixue Oct 8, 2024
b0d522e
refactor(BE): AI 코드 리뷰 프롬프트 수정
viaunixue Oct 8, 2024
a645899
refactor(BE): AI 코드 리뷰 프롬프트 수정
viaunixue Oct 8, 2024
ecc1e90
refactor(BE): AI 코드 리뷰 프롬프트 수정
viaunixue Oct 8, 2024
1d802e1
feat(BE): AI 코드 리뷰 주요 파일 선별 가중치 구현
viaunixue Oct 8, 2024
d8309db
refactor(BE): AI 코드 리뷰 프롬프트 수정
viaunixue Oct 8, 2024
2b0a6bf
fix(BE): import 에러 수정
viaunixue Oct 8, 2024
3cb0ceb
refactor(BE): AI 코드 리뷰 로직 수정
viaunixue Oct 8, 2024
2c0e684
refactor(BE): AI 코드 리뷰 프롬프트 수정
viaunixue Oct 8, 2024
1670fe4
refactor(BE): AI 코드 리뷰 프롬프트 수정
viaunixue Oct 8, 2024
302b13d
refactor(BE): AI 코드 리뷰 모델 수정
viaunixue Oct 8, 2024
2febe06
refactor(BE): AI 코드 리뷰 모델 수정
viaunixue Oct 8, 2024
68911c0
refactor(BE): AI 코드 리뷰 모델 수정
viaunixue Oct 8, 2024
8be7c16
refactor(BE): AI 코드 리뷰 프롬프트 수정
viaunixue Oct 8, 2024
a154687
refactor(BE): AI 코드 리뷰 프롬프트 수정
viaunixue Oct 8, 2024
8b53d91
refactor(BE): AI 코드 리뷰 프롬프트 수정
viaunixue Oct 8, 2024
e0f5707
refactor(BE): AI 코드 리뷰 모델 수정
viaunixue Oct 8, 2024
36c9462
refactor(BE): AI 코드 리뷰 모델 수정
viaunixue Oct 8, 2024
b140c02
refactor(BE): AI 코드 리뷰 모델 수정
viaunixue Oct 8, 2024
74b1436
refactor(BE): AI 코드 리뷰 프롬프트 수정
viaunixue Oct 8, 2024
c598b98
refactor(BE): AI 코드 리뷰 프롬프트 수정
viaunixue Oct 8, 2024
d01b1a4
refactor(BE): AI 코드 리뷰 프롬프트 수정
viaunixue Oct 8, 2024
eca1782
refactor(BE): AI 코드 리뷰 모델 옵션 수정
viaunixue Oct 8, 2024
a77808c
refactor(BE): AI 코드 리뷰 프롬프트 수정
viaunixue Oct 8, 2024
a48344b
refactor(BE): AI 코드 리뷰 프롬프트 수정
viaunixue Oct 8, 2024
babd019
refactor(BE): AI 코드 리뷰 프롬프트 수정
viaunixue Oct 8, 2024
c089270
refactor(BE): AI 코드 리뷰 프롬프트 수정
viaunixue Oct 8, 2024
3895ace
refactor(BE): AI 코드 리뷰 프롬프트 수정
viaunixue Oct 8, 2024
d7d12e8
refactor(BE): AI 코드 리뷰 프롬프트 수정
viaunixue Oct 8, 2024
037e751
refactor(BE): AI 코드 리뷰 프롬프트 수정
viaunixue Oct 8, 2024
b8a43e0
refactor(BE): AI 코드 리뷰 프롬프트 수정
viaunixue Oct 8, 2024
4469e4b
refactor(BE): AI 코드 리뷰 프롬프트 수정
viaunixue Oct 8, 2024
e554eb8
refactor(BE): AI 코드 리뷰 프롬프트 테스트
viaunixue Oct 8, 2024
8d85f3e
refactor(BE): AI 코드 리뷰 프롬프트 테스트
viaunixue Oct 8, 2024
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
549 changes: 549 additions & 0 deletions .github/scripts/ai_code_review.py

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions .github/scripts/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from data_processor import process_data
from utils import calculate_average, format_output

def main():
data = [1, 2, 3, 4, 5]
processed_data = process_data(data)
average = calculate_average(processed_data)
formatted_output = format_output(average)
print(formatted_output)

if __name__ == "__main__":
main()
27 changes: 27 additions & 0 deletions .github/scripts/review_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 리뷰에서 제외할 파일 목록
viaunixue marked this conversation as resolved.
Show resolved Hide resolved
viaunixue marked this conversation as resolved.
Show resolved Hide resolved
IGNORED_FILES = [
'.gitignore',
'requirements.txt',
'docker-compose.yml',
'Dockerfile',
'setup.cfg',
'pyproject.toml',
'.env.example',
'README.md',
'LICENSE',
]

# 리뷰에서 제외할 파일 확장자
IGNORED_EXTENSIONS = [
'.md',
'.txt',
'.log',
'.json',
'.yaml', '.yml',
]

# 중요 파일 판단 기준
IMPORTANT_FILE_CHANGE_THRESHOLD = 100

# 파일당 최대 코멘트 수
MAX_COMMENTS_PER_FILE = 3
16 changes: 16 additions & 0 deletions .github/scripts/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import unittest
from utils import calculate_average, is_prime

class TestUtils(unittest.TestCase):
def test_calculate_average(self):
self.assertEqual(calculate_average([1, 2, 3, 4, 5]), 3)
self.assertEqual(calculate_average([]), 0)

def test_is_prime(self):
self.assertTrue(is_prime(2))
self.assertTrue(is_prime(17))
self.assertFalse(is_prime(4))
self.assertFalse(is_prime(1))

if __name__ == '__main__':
unittest.main()
18 changes: 18 additions & 0 deletions .github/scripts/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def calculate_average(numbers):
total = 0
count = 0
for num in numbers:
total += num
count += 1
return total / count if count > 0 else 0

def format_output(value):
return f"The result is: {value:.2f}"

def is_prime(n):
if n < 1:
return False
for i in range(2, n):
if n % i == 0:
return False
return True
60 changes: 60 additions & 0 deletions .github/workflows/code-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: AI Code Review
viaunixue marked this conversation as resolved.
Show resolved Hide resolved

on:
pull_request:
types: [opened, synchronize]

permissions:
contents: read
pull-requests: write

jobs:
code-review:
runs-on: ubuntu-latest
# runs-on: self-hosted

steps:
- uses: actions/checkout@v4

# - name: Set Python Path
# run: echo "PYTHON_PATH=$(which python3)" >> $GITHUB_ENV
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

# - name: Install dependencies
# run: |
# ${{ env.PYTHON_PATH }} -m pip install --upgrade pip
# ${{ env.PYTHON_PATH }} -m pip install requests

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests groq

- name: Run AI Code Review
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }}
run: |
export PYTHONPATH=$PYTHONPATH:${{ github.workspace }}
python .github/scripts/ai_code_review.py

# - name: Check Ollama availability
# run: |
# curl http://localhost:11434/api/tags

# - name: Check Python version
# run: |
# python3 --version
# which python3

# - name: Run AI Code Review
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# run: |
# echo "Starting AI Code Review"
# export PYTHONPATH=$PYTHONPATH:${{ github.workspace }}
# /usr/local/bin/python3 /Users/jonghyunjung/VisualStudioProjects/neonadeuli-main/.github/scripts/ai_code_review.py
# echo "AI Code Review completed"
1 change: 1 addition & 0 deletions app/backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ flake8-comprehensions
flake8-pytest-style
viaunixue marked this conversation as resolved.
Show resolved Hide resolved
isort
mypy
groq
5 changes: 4 additions & 1 deletion app/backend/src/main/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from dotenv import load_dotenv
viaunixue marked this conversation as resolved.
Show resolved Hide resolved
viaunixue marked this conversation as resolved.
Show resolved Hide resolved
viaunixue marked this conversation as resolved.
Show resolved Hide resolved

# load .env file
load_dotenv()
load_dotenv('app/backend/.env')

from pydantic import (
PostgresDsn,
Expand Down Expand Up @@ -73,6 +73,9 @@ class Settings(BaseSettings):
# ALGORITHM : str
# ACCESS_TOKEN_EXPIRE_MINUTES : int

# Groq API
GROQ_API_KEY: str

# 기본 이미지 URL
# DEFAULT_IMAGE_URL : str

Expand Down
101 changes: 101 additions & 0 deletions scripts/review_prompt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
REVIEW_PROMPT = """
viaunixue marked this conversation as resolved.
Show resolved Hide resolved
viaunixue marked this conversation as resolved.
Show resolved Hide resolved
viaunixue marked this conversation as resolved.
Show resolved Hide resolved
viaunixue marked this conversation as resolved.
Show resolved Hide resolved
You have deep knowledge and expertise in Python, FastAPI for the back end, React and Next.js for the front.
Here is the new PR information.
- title: {title}
- description: {description}
- commit messages: {commit_messages}
- changed files: {changed_files}

viaunixue marked this conversation as resolved.
Show resolved Hide resolved
Please understand and review the purpose and context of the change considering PR information and commit message.
Please be sure to thoroughly analyze and review the following format and provide a comprehensive review.
If the author has written a post in accordance with the 🙏 review requirements (optional) written in the PR description section,
please provide a solution to resolve the content first.
If not, please find one part of the entire code provided that needs the most improvement and provide a solution.
Please find the number one priority that needs improvement in the entire code you provided and write it strictly in the format below.
--------------------------------------------------------
## 🧑🏻‍💻 주요 기능

viaunixue marked this conversation as resolved.
Show resolved Hide resolved
[Provide a brief description of the main features of this file, including its core functionality, expected input and output, and any specific exception cases it handles.]

## 🔍 개선할 점

[Write down any areas that need improvement, including performance bottlenecks, readability issues, and security vulnerabilities.]

## 📢 제안된 솔루션

1. 현재 코드

[problematic code fragment]

2. 권장되는 변경

[updated code snippet]

3. 변경 이유

[Brief reasons why the new approach is better, considering performance, readability, security, etc.]
--------------------------------------------------------

Full Code: {all_code}

If you need to put in a code block, keep it brief, no more than 10 lines of code that needs improvement.
Please write one sentence within 70 characters, including the maximum space, that you need to explain.
If you write one sentence for readability, please write the next sentence in the next column instead of the next one.

The person receiving this feedback is a Korean developer.
Please make sure to follow the above format strictly in Korean, but please provide specific and constructive feedback.
"""

viaunixue marked this conversation as resolved.
Show resolved Hide resolved
FILE_REVIEW_PROMPT = """
다음 {filename} 파일의 코드를 리뷰하고, 아래 형식으로 상세한 리뷰를 제공해주세요:

## {filename} 파일 리뷰

### 주요 기능
[파일의 주요 기능 설명]

### 좋은 점
[좋은 점 나열]
viaunixue marked this conversation as resolved.
Show resolved Hide resolved

### 개선할 점
[개선이 필요한 점 나열]

### 제안 사항
[구체적인 개선 제안, 코드 예시 포함]

파일 내용:
{content}
"""

LINE_COMMENTS_PROMPT = """
다음 {filename} 파일의 코드를 리뷰하고, 중요한 라인에 대해 구체적인 코멘트를 제공해주세요.
형식은 '라인 번호: 코멘트'로 해주세요.

{content}
"""

OVERALL_COMMENTS_PROMPT = """
## AI 코드 리뷰 요약

{overall_review}
"""

def get_review_prompt(all_code, pr_context, commit_messages, changed_files):
formatted_commit_messages = "\n".join([f"- {msg}" for msg in commit_messages])
return REVIEW_PROMPT.format(
title=pr_context['title'],
description=pr_context['description'],
commit_messages=formatted_commit_messages,
changed_files=changed_files,
all_code=all_code
)

def get_file_review_prompt(filename, content):
return FILE_REVIEW_PROMPT.format(filename=filename, content=content)

def get_line_comments_prompt(filename, content):
return LINE_COMMENTS_PROMPT.format(filename=filename, content=content)

def get_total_comments_prompt(overall_review):
return OVERALL_COMMENTS_PROMPT.format(overall_review=overall_review)

Loading