Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitamalinov committed Mar 9, 2024
1 parent aafb2e0 commit 8613202
Showing 1 changed file with 133 additions and 1 deletion.
134 changes: 133 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,73 @@
from config import GITHUB_WEBHOOK_SECRET, ENV
from services.github.github_manager import verify_webhook_signature
from services.webhook_handler import handle_webhook_event

from utils.file_manager import apply_patch
# Create FastAPI instance
app = FastAPI()

original_text = """import type { NextApiRequest, NextApiResponse } from "next";
import { z, ZodError } from "zod";
const schema = z.object({
folderName: z.string(),
});
import { v2 as cloudinary } from "cloudinary";
cloudinary.config({
cloud_name: "duaiiecow",
api_key: "896513553396748",
api_secret: "dtVnFQqHwz1WsYSUN3w52n6rqWs",
});
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
if (req.method !== "GET") {
res.status(405).json({ message: "Method not allowed" });
return;
}
try {
const folderName = schema.parse(req.query).folderName;
const images = await cloudinary.api.resources({
type: "upload",
prefix: folderName,
max_results: 100,
});
const videos = await cloudinary.api.resources({
type: "upload",
resource_type: "video",
prefix: folderName,
max_results: 100,
});
let imageAssets = images.resources.map((resource: any) => ({
public_id: resource.public_id,
url: resource.secure_url,
}));
let videoAssets = videos.resources.map((resource: any) => ({
public_id: resource.public_id,
url: resource.secure_url,
}));
res
.status(200)
.json({ imageAssets: imageAssets, videoAssets: videoAssets });
} catch (err) {
console.error(err);
if (err instanceof ZodError) {
res.status(400).json({ message: err.issues[0].message });
} else {
res.status(500).json({ message: "Internal server error" });
}
}
return;
}"""
sentry_sdk.init(
"https://b7ca4effebf7d7825b6464eade11734f@o4506827828101120.ingest.us.sentry.io/4506865231200256",
environment=ENV,
Expand All @@ -24,6 +87,75 @@

handler = Mangum(app=app)

@app.get(path="/test")
async def test():
apply_patch(original_text="Hello", diff_text="World")
return {"message": "Test successful"}

@app.get(path="/test2")
async def test():
diff_text = """```diff
--- pages/api/photos/get-cloudinary-photos.ts
+++ pages/api/photos/get-cloudinary-photos.ts
@@ -0,0 +1,22 @@
+import type { NextApiRequest, NextApiResponse } from 'next';
+import { v2 as cloudinary } from 'cloudinary';
+
+export default async function handler(
+ req: NextApiRequest,
+ res: NextApiResponse
+) {
+ cloudinary.config({
+ cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
+ api_key: process.env.CLOUDINARY_API_KEY,
+ api_secret: process.env.CLOUDINARY_API_SECRET,
+ });
+
+ const { resources } = await cloudinary.search
+ .expression('folder:merch')
+ .sort_by('public_id', 'desc')
+ .max_results(30)
+ .execute();
+
+ const images = resources.map(({ public_id, secure_url }) => ({ public_id, url: secure_url }));
+ res.status(200).json({ images });
+}
```"""
apply_patch(original_text=original_text, diff_text=diff_text)
return {"message": "Test successful"}

@app.get(path="/test3")
async def test():
diff_text = """
--- pages/api/photos/get-cloudinary-photos.ts
+++ pages/api/photos/get-cloudinary-photos.ts
@@ -0,0 +1,22 @@
+import type { NextApiRequest, NextApiResponse } from 'next';
+import { v2 as cloudinary } from 'cloudinary';
+
+export default async function handler(
+ req: NextApiRequest,
+ res: NextApiResponse
+) {
+ cloudinary.config({
+ cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
+ api_key: process.env.CLOUDINARY_API_KEY,
+ api_secret: process.env.CLOUDINARY_API_SECRET,
+ });
+
+ const { resources } = await cloudinary.search
+ .expression('folder:merch')
+ .sort_by('public_id', 'desc')
+ .max_results(30)
+ .execute();
+
+ const images = resources.map(({ public_id, secure_url }) => ({ public_id, url: secure_url }));
+ res.status(200).json({ images });
+}
"""
apply_patch(original_text=original_text, diff_text=diff_text)
return {"message": "Test successful"}

@app.post(path="/webhook")
async def handle_webhook(request: Request) -> dict[str, str]:
try:
Expand Down

0 comments on commit 8613202

Please sign in to comment.