mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-03 20:30:41 +08:00
fix PR code suggestions
This commit is contained in:
@ -10,7 +10,7 @@ from .git_provider import GitProvider
|
|||||||
from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo
|
from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo
|
||||||
|
|
||||||
AZURE_DEVOPS_AVAILABLE = True
|
AZURE_DEVOPS_AVAILABLE = True
|
||||||
MEX_PR_DESCRIPTION_LENGTH = 4000-1
|
MAX_PR_DESCRIPTION_LENGTH = 4000-1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# noinspection PyUnresolvedReferences
|
# noinspection PyUnresolvedReferences
|
||||||
@ -325,9 +325,9 @@ class AzureDevopsProvider(GitProvider):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def publish_description(self, pr_title: str, pr_body: str):
|
def publish_description(self, pr_title: str, pr_body: str):
|
||||||
if len(pr_body) > MEX_PR_DESCRIPTION_LENGTH:
|
if len(pr_body) > MAX_PR_DESCRIPTION_LENGTH:
|
||||||
trunction_message = " ... (description truncated due to length limit)"
|
trunction_message = " ... (description truncated due to length limit)"
|
||||||
pr_body = pr_body[:MEX_PR_DESCRIPTION_LENGTH - len(trunction_message)] + trunction_message
|
pr_body = pr_body[:MAX_PR_DESCRIPTION_LENGTH - len(trunction_message)] + trunction_message
|
||||||
get_logger().warning(
|
get_logger().warning(
|
||||||
"PR description exceeds the maximum character limit of 4000. Truncating the description."
|
"PR description exceeds the maximum character limit of 4000. Truncating the description."
|
||||||
)
|
)
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import uvicorn
|
import uvicorn
|
||||||
from fastapi import APIRouter, FastAPI
|
from fastapi import APIRouter, Depends, FastAPI
|
||||||
|
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
||||||
from fastapi.encoders import jsonable_encoder
|
from fastapi.encoders import jsonable_encoder
|
||||||
from starlette import status
|
from starlette import status
|
||||||
from starlette.background import BackgroundTasks
|
from starlette.background import BackgroundTasks
|
||||||
@ -19,7 +19,6 @@ from starlette_context.middleware import RawContextMiddleware
|
|||||||
from pr_agent.agent.pr_agent import PRAgent, command2class
|
from pr_agent.agent.pr_agent import PRAgent, command2class
|
||||||
from pr_agent.config_loader import get_settings
|
from pr_agent.config_loader import get_settings
|
||||||
from pr_agent.log import get_logger
|
from pr_agent.log import get_logger
|
||||||
import base64
|
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
available_commands_rgx = re.compile(r"^\/(" + "|".join(command2class.keys()) + r")\s*")
|
available_commands_rgx = re.compile(r"^\/(" + "|".join(command2class.keys()) + r")\s*")
|
||||||
@ -93,14 +92,20 @@ async def handle_webhook(background_tasks: BackgroundTasks, request: Request):
|
|||||||
# currently only basic auth is supported with azure webhooks
|
# currently only basic auth is supported with azure webhooks
|
||||||
# for this reason, https must be enabled to ensure the credentials are not sent in clear text
|
# for this reason, https must be enabled to ensure the credentials are not sent in clear text
|
||||||
def validate_basic_auth(request: Request):
|
def validate_basic_auth(request: Request):
|
||||||
auth = request.headers.get("Authorization")
|
try:
|
||||||
if not auth:
|
auth = request.headers.get("Authorization")
|
||||||
return False
|
if not auth:
|
||||||
if not auth.startswith("Basic "):
|
return False
|
||||||
return False
|
if not auth.startswith("Basic "):
|
||||||
decoded_auth = base64.b64decode(auth.split(" ")[1]).decode()
|
return False
|
||||||
username, password = decoded_auth.split(":")
|
security = HTTPBasic()
|
||||||
return username == WEBHOOK_USERNAME and password == WEBHOOK_PASSWORD
|
credentials: HTTPBasicCredentials = Depends(security)
|
||||||
|
username = credentials.username
|
||||||
|
password = credentials.password
|
||||||
|
return username == WEBHOOK_USERNAME and password == WEBHOOK_PASSWORD
|
||||||
|
except:
|
||||||
|
get_logger().error("Failed to validate basic auth")
|
||||||
|
return False
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
app = FastAPI(middleware=[Middleware(RawContextMiddleware)])
|
app = FastAPI(middleware=[Middleware(RawContextMiddleware)])
|
||||||
|
Reference in New Issue
Block a user