Spaces:
Sleeping
Sleeping
corrected response
Browse files- code_review_agent.py +5 -4
code_review_agent.py
CHANGED
|
@@ -18,6 +18,7 @@ from collections import defaultdict
|
|
| 18 |
import logging as log
|
| 19 |
from datetime import datetime
|
| 20 |
from fastapi import FastAPI, Request, Header
|
|
|
|
| 21 |
|
| 22 |
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
| 23 |
parentdir = os.path.dirname(currentdir)
|
|
@@ -176,7 +177,7 @@ async def webhook(request: Request, x_gitlab_event: str = Header(...)):
|
|
| 176 |
data = await request.json()
|
| 177 |
except Exception as e:
|
| 178 |
log.error(f"Error parsing JSON: {e}")
|
| 179 |
-
return {"status": "error", "message": "Invalid JSON"}
|
| 180 |
log.info(f"Webhook data: {data}")
|
| 181 |
if x_gitlab_event == "Note Hook":
|
| 182 |
note = data["object_attributes"]["note"]
|
|
@@ -189,11 +190,11 @@ async def webhook(request: Request, x_gitlab_event: str = Header(...)):
|
|
| 189 |
headers = {"PRIVATE-TOKEN": GITLAB_TOKEN}
|
| 190 |
response = requests.get(diff_url, headers=headers).json()
|
| 191 |
git_hub_url = response["web_url"]
|
| 192 |
-
review_comment = main(git_hub_url, mr_iid) or "No issues found."
|
| 193 |
comment_url = f"https://gitlab.com/api/v4/projects/{project_id}/merge_requests/{mr_iid}/notes"
|
| 194 |
-
requests.post(comment_url, headers=headers, json={"body": f"
|
| 195 |
|
| 196 |
-
return {"status": "ok"}
|
| 197 |
#
|
| 198 |
# if __name__ == "__main__":
|
| 199 |
# repo_url = "https://github.com/huggingface/accelerate"
|
|
|
|
| 18 |
import logging as log
|
| 19 |
from datetime import datetime
|
| 20 |
from fastapi import FastAPI, Request, Header
|
| 21 |
+
from fastapi.responses import JSONResponse
|
| 22 |
|
| 23 |
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
| 24 |
parentdir = os.path.dirname(currentdir)
|
|
|
|
| 177 |
data = await request.json()
|
| 178 |
except Exception as e:
|
| 179 |
log.error(f"Error parsing JSON: {e}")
|
| 180 |
+
return JSONResponse(content={"status": "error", "message": "Invalid JSON"}, status_code=400)
|
| 181 |
log.info(f"Webhook data: {data}")
|
| 182 |
if x_gitlab_event == "Note Hook":
|
| 183 |
note = data["object_attributes"]["note"]
|
|
|
|
| 190 |
headers = {"PRIVATE-TOKEN": GITLAB_TOKEN}
|
| 191 |
response = requests.get(diff_url, headers=headers).json()
|
| 192 |
git_hub_url = response["web_url"]
|
| 193 |
+
review_comment = await main(git_hub_url, mr_iid) or "No issues found."
|
| 194 |
comment_url = f"https://gitlab.com/api/v4/projects/{project_id}/merge_requests/{mr_iid}/notes"
|
| 195 |
+
requests.post(comment_url, headers=headers, json={"body": f"AI Code Review:\n```\n{review_comment}\n```"})
|
| 196 |
|
| 197 |
+
return JSONResponse(content={"status": "ok"})
|
| 198 |
#
|
| 199 |
# if __name__ == "__main__":
|
| 200 |
# repo_url = "https://github.com/huggingface/accelerate"
|