From 221ff8fab5f85d6512aa7305747484ce7c36b76b Mon Sep 17 00:00:00 2001 From: Esteban Dalel R Date: Thu, 21 Sep 2023 09:28:14 -0500 Subject: [PATCH 1/4] Remove unused imports --- app/api/analytics/vsmarketplace/update/route.ts | 1 - app/api/user/settings/route.ts | 5 ----- 2 files changed, 6 deletions(-) diff --git a/app/api/analytics/vsmarketplace/update/route.ts b/app/api/analytics/vsmarketplace/update/route.ts index 7ea25656..3794acc2 100644 --- a/app/api/analytics/vsmarketplace/update/route.ts +++ b/app/api/analytics/vsmarketplace/update/route.ts @@ -2,7 +2,6 @@ import { NextResponse } from "next/server"; import validateParams from "../../../../../utils/api/validateParams"; import Airtable from "airtable"; import { missingParamsResponse } from "../../../../../utils/api/responses"; -import { missingParamsPosthogTracking } from "../../../../../utils/api/posthogTracking"; Airtable.configure({ endpointUrl: "https://api.airtable.com", apiKey: process.env.AIRTABLE_API_KEY, diff --git a/app/api/user/settings/route.ts b/app/api/user/settings/route.ts index caabad3d..c9fb511a 100644 --- a/app/api/user/settings/route.ts +++ b/app/api/user/settings/route.ts @@ -5,11 +5,6 @@ import { missingParamsResponse, successResponse, } from "../../../../utils/api/responses"; -import { - failedPosthogTracking, - missingParamsPosthogTracking, - successPosthogTracking, -} from "../../../../utils/api/posthogTracking"; export async function POST(request: Request) { const req = await request.json(); From f09808706c9087f267afe31f0766b484f32182b6 Mon Sep 17 00:00:00 2001 From: Esteban Dalel R Date: Thu, 21 Sep 2023 09:28:27 -0500 Subject: [PATCH 2/4] Add unauthorized response --- app/api/extension/intellijLogin/route.ts | 2 +- utils/api/posthogTracking.ts | 8 ++++++++ utils/api/responses.ts | 4 +++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/api/extension/intellijLogin/route.ts b/app/api/extension/intellijLogin/route.ts index 51f6ddc3..4c7465b2 100644 --- a/app/api/extension/intellijLogin/route.ts +++ b/app/api/extension/intellijLogin/route.ts @@ -17,7 +17,7 @@ export async function POST(request: Request) { const userData = await intellijLogin({ watermelon_user: token }); if (!userData || !userData.email) { - return unauthorizedResponse({ email: token }); + return unauthorizedResponse({ email: token, url: request.url }); } return successResponse({ diff --git a/utils/api/posthogTracking.ts b/utils/api/posthogTracking.ts index 106395a3..d5397cf6 100644 --- a/utils/api/posthogTracking.ts +++ b/utils/api/posthogTracking.ts @@ -20,3 +20,11 @@ export function missingParamsPosthogTracking({ url, missingParams }) { properties: missingParams, }); } +} +export function unauthorizedPosthogTracking({ url, email, error }) { + posthog.capture({ + distinctId: email, + event: `${url}-unauthorized`, + properties: error, + }); +} \ No newline at end of file diff --git a/utils/api/responses.ts b/utils/api/responses.ts index 49f568e2..40283c15 100644 --- a/utils/api/responses.ts +++ b/utils/api/responses.ts @@ -3,6 +3,7 @@ import { failedPosthogTracking, missingParamsPosthogTracking, successPosthogTracking, + unauthorizedPosthogTracking, } from "./posthogTracking"; export function successResponse({ url, email, data }) { @@ -26,8 +27,9 @@ export function missingParamsResponse({ url, missingParams }) { ); } -export function unauthorizedResponse({ email }) { +export function unauthorizedResponse({ email, url }) { const responseText = `email: ${email} is not authorized`; + unauthorizedPosthogTracking({ email, url, error: responseText }); return NextResponse.json( { error: responseText, From 2bf15ce5114b79aa86a09232cd99bae426c1b6f4 Mon Sep 17 00:00:00 2001 From: Esteban Dalel R Date: Thu, 21 Sep 2023 09:33:56 -0500 Subject: [PATCH 3/4] Remove extra bracket --- utils/api/posthogTracking.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/utils/api/posthogTracking.ts b/utils/api/posthogTracking.ts index d5397cf6..11f80f37 100644 --- a/utils/api/posthogTracking.ts +++ b/utils/api/posthogTracking.ts @@ -20,11 +20,10 @@ export function missingParamsPosthogTracking({ url, missingParams }) { properties: missingParams, }); } -} export function unauthorizedPosthogTracking({ url, email, error }) { posthog.capture({ distinctId: email, event: `${url}-unauthorized`, properties: error, }); -} \ No newline at end of file +} From eaa76cc198cfad32f819924fdda920cee07e9c08 Mon Sep 17 00:00:00 2001 From: Esteban Dalel R Date: Thu, 21 Sep 2023 10:00:36 -0500 Subject: [PATCH 4/4] Add random suggestions to MD --- app/api/actions/github/route.ts | 7 ++++--- utils/actions/markdownHelpers/randomText.ts | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 utils/actions/markdownHelpers/randomText.ts diff --git a/app/api/actions/github/route.ts b/app/api/actions/github/route.ts index 718d0775..b426ff1c 100644 --- a/app/api/actions/github/route.ts +++ b/app/api/actions/github/route.ts @@ -13,7 +13,7 @@ import { } from "../../../../utils/api/responses"; import validateParams from "../../../../utils/api/validateParams"; -import labelPullRequest from "../../../../utils/actions/labelPullRequest"; +import labelPullRequest from "../../../../utils/actions/labelPullRequest"; import { failedPosthogTracking, @@ -21,6 +21,7 @@ import { } from "../../../../utils/api/posthogTracking"; import { NextResponse } from "next/server"; import getAllServices from "../../../../utils/actions/getAllServices"; +import randomText from "../../../../utils/actions/markdownHelpers/randomText"; const app = new App({ appId: process.env.GITHUB_APP_ID!, privateKey: process.env.GITHUB_PRIVATE_KEY!, @@ -295,7 +296,6 @@ export async function POST(request: Request) { } = serviceAnswers; if (error) { return failedToFetchResponse({ - url: request.url, error: error.message, email: req.email, @@ -400,6 +400,7 @@ export async function POST(request: Request) { isPrivateRepo: repository.private, repoName: repo, }); + textToWrite += randomText(); // Make Watermelon Review the PR's business logic here by comparing the title with the AI-generated summary await labelPullRequest({ @@ -410,7 +411,7 @@ export async function POST(request: Request) { issue_number: number, installationId, reqUrl: request.url, - reqEmail: req.email + reqEmail: req.email, }); await addActionLog({ diff --git a/utils/actions/markdownHelpers/randomText.ts b/utils/actions/markdownHelpers/randomText.ts new file mode 100644 index 00000000..69b00b82 --- /dev/null +++ b/utils/actions/markdownHelpers/randomText.ts @@ -0,0 +1,16 @@ +const randomText = () => { + const textList = [ + "\n[Why not invite more people to your team?](https://app.watermelontools.com/team)", + "\n[Have you starred Watermelon?](https://github.com/watermelontools/watermelon)", + "\n[Try us on VSCode!](https://marketplace.visualstudio.com/items?itemName=WatermelonTools.watermelon-tools)", + "\n[Try us on VSCodium!](https://open-vsx.org/extension/WatermelonTools/watermelon-tools)", + "\n[Try us on any JetBrains IDE!](https://plugins.jetbrains.com/plugin/22720-watermelon-context)", + ]; + + let randomChance = Math.random() * 100; + if (randomChance < 50) { + return textList[Math.floor(Math.random() * textList.length)]; + } + return ""; +}; +export default randomText;