Skip to content

Commit

Permalink
[BE] OAuth 로그인 인증 시스템 초기 구축 (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
viaunixue authored Oct 19, 2024
2 parents cde5631 + f10454a commit 237d212
Show file tree
Hide file tree
Showing 73 changed files with 2,304 additions and 381 deletions.
74 changes: 37 additions & 37 deletions .github/scripts/ai_code_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,51 +435,51 @@ def generate_reviews(pr_files, repo, pr_number, latest_commit_id, github_token):
logger.warning("리뷰할 코드가 없습니다. 모든 파일 내용을 가져오는 데 실패했습니다.")
return None, []

pr_context = get_pr_context(repo, pr_number, github_token)
commit_messages = get_commit_messages(repo, pr_number, github_token)
changed_files = get_changed_files(repo, pr_number, github_token)
# pr_context = get_pr_context(repo, pr_number, github_token)
# commit_messages = get_commit_messages(repo, pr_number, github_token)
# changed_files = get_changed_files(repo, pr_number, github_token)

# 개선된 리뷰 프롬프트 생성
review_prompt = get_review_prompt(all_code, pr_context, commit_messages, changed_files)
# review_prompt = get_review_prompt(all_code, pr_context, commit_messages, changed_files)

# 전체 코드에 대한 상세한 리뷰
overall_review = review_code_groq(review_prompt)
#overall_review = review_code_groq(review_prompt)

# 중요 파일에 대한 상세 리뷰 (라인 별 코멘트 비활성화)
# for file in important_files:
# logger.info(f"중요 파일 상세 리뷰 중: {file['filename']}")
# if file['status'] == 'removed':
# file_review = f"파일 '{file['filename']}'이(가) 삭제되었습니다. 이 변경이 적절한지 확인해 주세요."
# else:
# content = requests.get(file['raw_url']).text
# file_review_prompt = get_file_review_prompt(file['filename'], content)
# file_review = review_code_groq(file_review_prompt)
for file in important_files:
logger.info(f"중요 파일 상세 리뷰 중: {file['filename']}")
if file['status'] == 'removed':
file_review = f"파일 '{file['filename']}'이(가) 삭제되었습니다. 이 변경이 적절한지 확인해 주세요."
else:
content = requests.get(file['raw_url']).text
file_review_prompt = get_file_review_prompt(file['filename'], content)
file_review = review_code_groq(file_review_prompt)

# # 파일 전체에 대한 리뷰 코멘트
# post_file_comment(
# repo,
# pr_number,
# latest_commit_id,
# file['filename'],
# file_review,
# github_token
# )

# # 라인 별 코멘트
# line_comments_prompt = get_line_comments_prompt(file['filename'], content)
# line_comments = review_code_groq(line_comments_prompt)

# post_line_comments(
# repo,
# pr_number,
# latest_commit_id,
# file['filename'],
# file['patch'],
# line_comments,
# github_token
# )
# 파일 전체에 대한 리뷰 코멘트
post_file_comment(
repo,
pr_number,
latest_commit_id,
file['filename'],
file_review,
github_token
)

# 라인 별 코멘트
# line_comments_prompt = get_line_comments_prompt(file['filename'], content)
# line_comments = review_code_groq(line_comments_prompt)

# post_line_comments(
# repo,
# pr_number,
# latest_commit_id,
# file['filename'],
# file['patch'],
# line_comments,
# github_token
# )

return overall_review
# return overall_review

def post_file_comment(repo, pr_number, commit_sha, file_path, body, token):
url = f"https://api.github.com/repos/{repo}/pulls/{pr_number}/comments"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-review-reminder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ jobs:
current_time=$(date --utc +%Y-%m-%dT%H:%M:%SZ)
merge_notification=$(jq -n \
--arg title "병합 준비 완료!" \
--arg description "$mentions\n\n다음 PR들이 모든 리뷰를 통과하여 병합 준비가 완료되었습니다:\n$pr_list" \
--arg description "$mentions\\\\n\\\\n다음 PR들이 모든 리뷰를 통과하여 병합 준비가 완료되었습니다:\\n$pr_list" \
--arg thumbnail "https://github.com/user-attachments/assets/5bbf4cfb-67a9-402b-969e-8fb142c37f0f" \
--arg author_name "PR MERGE BOT" \
--arg author_icon "https://avatars.githubusercontent.com/u/9919?s=200&v=4" \
Expand Down
20 changes: 0 additions & 20 deletions app/backend/Dockerfile

This file was deleted.

63 changes: 23 additions & 40 deletions app/backend/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,39 @@
version: '3.8'

services:
backend:
build:
context: .
dockerfile: Dockerfile
ports:
- "8000:8000"
environment:
- DATABASE_URL=postgresql://user:password@db:5432/neonadeuli
volumes:
- .:/app/backend
depends_on:
- db


db:
postgresql:
container_name: neonadeuli-postgresql
image: postgres:13
restart: unless-stopped
environment:
- POSTGRES_DB=neonadeuli
- POSTGRES_USER=root
- POSTGRES_PASSWORD=1234
ports:
- "5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U root -d neonadeuli"]
interval: 10s
timeout: 4s
retries: 5
start_period: 30s
volumes:
- postgres_data:/var/lib/postgresql/data

sonarqube:
image: sonarqube:latest
redis:
container_name: neonadeuli-redis
image: redis:latest
restart: always
ports:
- "9000:9000"
environment:
- SONAR_JDBC_URL=jdbc:postgresql://sonarqube_db:5432/sonar
- SONAR_JDBC_USERNAME=sonar
- SONAR_JDBC_PASSWORD=sonar
volumes:
- sonarqube_data:/opt/sonarqube/data
- sonarqube_extensions:/opt/sonarqube/extensions
- sonarqube_logs:/opt/sonarqube/logs
depends_on:
- sonarqube_db

sonarqube_db:
image: postgres:13
environment:
- POSTGRES_DB=sonar
- POSTGRES_USER=sonar
- POSTGRES_PASSWORD=sonar
- "6379:6379"
volumes:
- sonarqube_db_data:/var/lib/postgresql/data
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 5

volumes:
postgres_data:
sonarqube_data:
sonarqube_extensions:
sonarqube_logs:
sonarqube_db_data:
redis_data:
68 changes: 0 additions & 68 deletions app/backend/main.py

This file was deleted.

9 changes: 8 additions & 1 deletion app/backend/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
[tool.poetry]
name = "너나들이"
packages = [
{ include = "neonadeuli", from = "src" },
version = "0.3.3"
description = "대화형 챗봇 AI와 다양한 콘텐츠로 한국의 국가 유산과 역사를 재미있게 탐구하는 문화 콘텐츠 서비스"
authors = ["정종현 <[email protected]>", "김강현 <[email protected]>"]
authors = ["정종현 <[email protected]>"]

[tool.pytest.ini_options]
pythonpath = [
"src"
]

[tool.poetry.dependencies]
python = "^3.12"
Expand Down
3 changes: 3 additions & 0 deletions app/backend/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
testpaths = src/test
pythonpath = src/main
6 changes: 5 additions & 1 deletion app/backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ flake8-comprehensions
flake8-pytest-style
isort
mypy
groq
authlib
email-validator >= 2.0
sphinx
groq
redis
36 changes: 2 additions & 34 deletions app/backend/src/main/api/deps.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,6 @@
from fastapi import Depends, HTTPException, status
from fastapi.security import OAuth2PasswordBearer
from sqlalchemy.orm import Session
from jose import jwt, JWTError
def get_pagination_params(skip: int=0, limit: int=100):
return {"skip": skip, "limit": limit}

from src.main.core.config import settings
from src.main.db.deps import get_db
from src.main.domains.user.services import UserService
from src.main.domains.user.models.user import User

oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")

async def get_current_user(
db: Session = Depends(get_db),
token: str = Depends(oauth2_scheme)
) -> User:
credentials_exception = HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
details="자격 증명을 검증할 수 없습니다.",
headers={"WWW-Authenticate":"Bearer"},
)
try:
payload = jwt.decode(
token, settings.SECRET_KEY, algorithm=[settings.ALGORITHM]
)
username: str = payload.get("sub")
if username is None:
raise credentials_exception
except JWTError:
raise credentials_exception

user_service = UserService(db)
user = user_service.get_user_by_name(username)
if user is None:
raise credentials_exception
return user


10 changes: 10 additions & 0 deletions app/backend/src/main/core/auth/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""
인증 관련 기능을 제공하는 패키지입니다.
JWT 토큰 처리, OAuth 인증, 그리고 사용자 인증을 위한 의존성 함수를 포함합니다.
"""

from .jwt import create_access_token, verify_token
from .oauth import setup_oauth

__all__ = ['create_access_token', 'verify_token', 'setup_oauth']
Loading

0 comments on commit 237d212

Please sign in to comment.