From efc1be6a0c19b418db288bebb87247e7512f6343 Mon Sep 17 00:00:00 2001 From: baristaGeek Date: Fri, 22 Sep 2023 16:14:35 -0500 Subject: [PATCH 1/5] Add conditional if the count passes 500 --- utils/actions/markdownHelpers/count.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utils/actions/markdownHelpers/count.ts b/utils/actions/markdownHelpers/count.ts index b4502a48a..f6160b8eb 100644 --- a/utils/actions/markdownHelpers/count.ts +++ b/utils/actions/markdownHelpers/count.ts @@ -11,8 +11,10 @@ const countMarkdown = ({ if (count.error) { return `\n We're sorry, we ran into an error: ${count.error}`; } else { - if (count.name && count.github_app_uses) { + if (count.name && (count.github_app_uses <= 500)) { return `\n Your team ${count.name} has used Watermelon ${count.github_app_uses} times.`; + } else { + return `\n Your team has surpassed the free monthly usage. [Please click here](https://calendly.com/evargas-14/watermelon-business) to upgrade.`; } } } else { From 5404ad4e6eb6d655a8ae56e745eb210bad27bca4 Mon Sep 17 00:00:00 2001 From: baristaGeek Date: Mon, 25 Sep 2023 13:11:30 -0500 Subject: [PATCH 2/5] Replace all indexed information with invitation to pay --- app/api/actions/github/route.ts | 331 ++++++++++++++++++-------------- 1 file changed, 183 insertions(+), 148 deletions(-) diff --git a/app/api/actions/github/route.ts b/app/api/actions/github/route.ts index 718d07755..530f4231e 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, @@ -295,7 +295,6 @@ export async function POST(request: Request) { } = serviceAnswers; if (error) { return failedToFetchResponse({ - url: request.url, error: error.message, email: req.email, @@ -324,174 +323,210 @@ export async function POST(request: Request) { } } const count = await addActionCount({ watermelon_user }); - textToWrite += `### WatermelonAI Summary \n`; - let businessLogicSummary; - if (AISummary) { - businessLogicSummary = await getOpenAISummary({ - commitList, - values: { - github: github?.data, - jira: jira?.data, - confluence: confluence?.data, - slack: slack?.data, - notion: notion?.data, - linear: linear?.data, - asana: asana?.data, - }, - title, - body, - }); + console.log("count: ", count.github_app_uses); + + if (count.github_app_uses <= 500) { + textToWrite += `### WatermelonAI Summary \n`; - if (businessLogicSummary) { - textToWrite += businessLogicSummary + "\n"; + let businessLogicSummary; + if (AISummary) { + businessLogicSummary = await getOpenAISummary({ + commitList, + values: { + github: github?.data, + jira: jira?.data, + confluence: confluence?.data, + slack: slack?.data, + notion: notion?.data, + linear: linear?.data, + asana: asana?.data, + }, + title, + body, + }); + + if (businessLogicSummary) { + textToWrite += businessLogicSummary + "\n"; + } else { + textToWrite += + "Error getting summary" + businessLogicSummary?.error + "\n"; + } } else { - textToWrite += - "Error getting summary" + businessLogicSummary?.error + "\n"; + textToWrite += `AI Summary deactivated by ${userLogin} \n`; } - } else { - textToWrite += `AI Summary deactivated by ${userLogin} \n`; - } - textToWrite += generalMarkdownHelper({ - value: github, - userLogin, - systemName: "GitHub", - systemResponseName: "GitHub PRs", - }); - textToWrite += generalMarkdownHelper({ - value: jira, - userLogin, - systemName: "Jira", - systemResponseName: "Jira Tickets", - }); - textToWrite += generalMarkdownHelper({ - value: confluence, - userLogin, - systemName: "Confluence", - systemResponseName: "Confluence Docs", - }); - textToWrite += generalMarkdownHelper({ - value: slack, - userLogin, - systemName: "Slack", - systemResponseName: "Slack Threads", - }); - textToWrite += generalMarkdownHelper({ - value: notion, - userLogin, - systemName: "Notion", - systemResponseName: "Notion Pages", - }); - textToWrite += generalMarkdownHelper({ - value: linear, - userLogin, - systemName: "Linear", - systemResponseName: "Linear Tickets", - }); - textToWrite += generalMarkdownHelper({ - value: asana, - userLogin, - systemName: "Asana", - systemResponseName: "Asana Tasks", - }); - textToWrite += countMarkdown({ - count, - isPrivateRepo: repository.private, - repoName: repo, - }); + textToWrite += generalMarkdownHelper({ + value: github, + userLogin, + systemName: "GitHub", + systemResponseName: "GitHub PRs", + }); + textToWrite += generalMarkdownHelper({ + value: jira, + userLogin, + systemName: "Jira", + systemResponseName: "Jira Tickets", + }); + textToWrite += generalMarkdownHelper({ + value: confluence, + userLogin, + systemName: "Confluence", + systemResponseName: "Confluence Docs", + }); + textToWrite += generalMarkdownHelper({ + value: slack, + userLogin, + systemName: "Slack", + systemResponseName: "Slack Threads", + }); + textToWrite += generalMarkdownHelper({ + value: notion, + userLogin, + systemName: "Notion", + systemResponseName: "Notion Pages", + }); + textToWrite += generalMarkdownHelper({ + value: linear, + userLogin, + systemName: "Linear", + systemResponseName: "Linear Tickets", + }); + textToWrite += generalMarkdownHelper({ + value: asana, + userLogin, + systemName: "Asana", + systemResponseName: "Asana Tasks", + }); + textToWrite += countMarkdown({ + count, + isPrivateRepo: repository.private, + repoName: repo, + }); - // Make Watermelon Review the PR's business logic here by comparing the title with the AI-generated summary - await labelPullRequest({ - prTitle: title, - businessLogicSummary, - repo, - owner, - issue_number: number, - installationId, - reqUrl: request.url, - reqEmail: req.email - }); + // Make Watermelon Review the PR's business logic here by comparing the title with the AI-generated summary + await labelPullRequest({ + prTitle: title, + businessLogicSummary, + repo, + owner, + issue_number: number, + installationId, + reqUrl: request.url, + reqEmail: req.email, + }); - await addActionLog({ - randomWords, - github, - jira, - slack, - notion, - linear, - asana, - textToWrite, - businessLogicSummary, - owner, - repo, - number, - payload: req, - count, - watermelon_user, - }); - // Fetch all comments on the PR - const comments = await octokit.request( - "GET /repos/{owner}/{repo}/issues/{issue_number}/comments?sort=created&direction=desc", - { + await addActionLog({ + randomWords, + github, + jira, + slack, + notion, + linear, + asana, + textToWrite, + businessLogicSummary, owner, repo, - issue_number: number, - headers: { - "X-GitHub-Api-Version": "2022-11-28", - }, - } - ); - console.info("comments.data.length", comments.data.length); - // Find our bot's comment - let botComment = comments.data.find((comment) => { - return comment.user.login.includes("watermelon-context"); - }); - if (botComment?.id) { - // Update the existing comment - await octokit.request( - "PATCH /repos/{owner}/{repo}/issues/comments/{comment_id}", + number, + payload: req, + count, + watermelon_user, + }); + // Fetch all comments on the PR + const comments = await octokit.request( + "GET /repos/{owner}/{repo}/issues/{issue_number}/comments?sort=created&direction=desc", { owner, repo, - comment_id: botComment.id, - body: textToWrite, + issue_number: number, + headers: { + "X-GitHub-Api-Version": "2022-11-28", + }, } ); - } else { - // Post a new comment if no existing comment was found - await octokit - .request( - "POST /repos/{owner}/{repo}/issues/{issue_number}/comments", + console.info("comments.data.length", comments.data.length); + // Find our bot's comment + let botComment = comments.data.find((comment) => { + return comment.user.login.includes("watermelon-context"); + }); + if (botComment?.id) { + // Update the existing comment + await octokit.request( + "PATCH /repos/{owner}/{repo}/issues/comments/{comment_id}", { owner, - issue_number: number, repo, + comment_id: botComment.id, body: textToWrite, } - ) - .then((response) => { - successPosthogTracking({ - url: request.url, - email: user_email, - data: { - repo, + ); + } else { + // Post a new comment if no existing comment was found + await octokit + .request( + "POST /repos/{owner}/{repo}/issues/{issue_number}/comments", + { owner, - number, - action: req.action, - textToWrite, - }, - }); - }) - .catch((error) => { - failedPosthogTracking({ - url: request.url, - error: error.message, - email: req.email, + issue_number: number, + repo, + body: textToWrite, + } + ) + .then((response) => { + successPosthogTracking({ + url: request.url, + email: user_email, + data: { + repo, + owner, + number, + action: req.action, + textToWrite, + }, + }); + }) + .catch((error) => { + failedPosthogTracking({ + url: request.url, + error: error.message, + email: req.email, + }); + return console.error("posting comment error", error); }); - return console.error("posting comment error", error); - }); + } + } else { + textToWrite = `Your team has surpassed the free monthly usage. [Please click here](https://calendly.com/evargas-14/watermelon-business) to upgrade.` + + const comments = await octokit.request( + "GET /repos/{owner}/{repo}/issues/{issue_number}/comments?sort=created&direction=desc", + { + owner, + repo, + issue_number: number, + headers: { + "X-GitHub-Api-Version": "2022-11-28", + }, + } + ); + + // Find our bot's comment + let botComment = comments.data.find((comment) => { + return comment.user.login.includes("watermelon-context"); + }); + + // Update the existing comment + await octokit.request( + "PATCH /repos/{owner}/{repo}/issues/comments/{comment_id}", + { + owner, + repo, + comment_id: botComment.id, + body: textToWrite, + } + ); } + successPosthogTracking({ url: request.url, email: user_email, From 7e1ad3da85576bd4fe99afb471f0ff26fc9abf1d Mon Sep 17 00:00:00 2001 From: baristaGeek Date: Mon, 25 Sep 2023 14:19:26 -0500 Subject: [PATCH 3/5] Remove the logic from the markdown helper --- utils/actions/markdownHelpers/count.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/utils/actions/markdownHelpers/count.ts b/utils/actions/markdownHelpers/count.ts index f6160b8eb..b4502a48a 100644 --- a/utils/actions/markdownHelpers/count.ts +++ b/utils/actions/markdownHelpers/count.ts @@ -11,10 +11,8 @@ const countMarkdown = ({ if (count.error) { return `\n We're sorry, we ran into an error: ${count.error}`; } else { - if (count.name && (count.github_app_uses <= 500)) { + if (count.name && count.github_app_uses) { return `\n Your team ${count.name} has used Watermelon ${count.github_app_uses} times.`; - } else { - return `\n Your team has surpassed the free monthly usage. [Please click here](https://calendly.com/evargas-14/watermelon-business) to upgrade.`; } } } else { From 9fdaa47badc5677d853909c25bea7f9c94baf89d Mon Sep 17 00:00:00 2001 From: baristaGeek Date: Tue, 26 Sep 2023 11:29:24 -0500 Subject: [PATCH 4/5] Remove console log --- app/api/actions/github/route.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/api/actions/github/route.ts b/app/api/actions/github/route.ts index 530f4231e..e0a06d00c 100644 --- a/app/api/actions/github/route.ts +++ b/app/api/actions/github/route.ts @@ -324,8 +324,6 @@ export async function POST(request: Request) { } const count = await addActionCount({ watermelon_user }); - console.log("count: ", count.github_app_uses); - if (count.github_app_uses <= 500) { textToWrite += `### WatermelonAI Summary \n`; From e20efd1ade6a6bac416aded7aa977b4fa3870a3d Mon Sep 17 00:00:00 2001 From: baristaGeek Date: Tue, 26 Sep 2023 12:51:13 -0500 Subject: [PATCH 5/5] Unwrapp comenting logic from being below the threshold. Replace comment with billing link with an if statement that doesn't wrap the commenting logic. --- app/api/actions/github/route.ts | 299 ++++++++++++++++---------------- 1 file changed, 149 insertions(+), 150 deletions(-) diff --git a/app/api/actions/github/route.ts b/app/api/actions/github/route.ts index e0a06d00c..b67e6ba39 100644 --- a/app/api/actions/github/route.ts +++ b/app/api/actions/github/route.ts @@ -324,176 +324,175 @@ export async function POST(request: Request) { } const count = await addActionCount({ watermelon_user }); - if (count.github_app_uses <= 500) { - textToWrite += `### WatermelonAI Summary \n`; - - let businessLogicSummary; - if (AISummary) { - businessLogicSummary = await getOpenAISummary({ - commitList, - values: { - github: github?.data, - jira: jira?.data, - confluence: confluence?.data, - slack: slack?.data, - notion: notion?.data, - linear: linear?.data, - asana: asana?.data, - }, - title, - body, - }); + let businessLogicSummary; + if (AISummary) { + businessLogicSummary = await getOpenAISummary({ + commitList, + values: { + github: github?.data, + jira: jira?.data, + confluence: confluence?.data, + slack: slack?.data, + notion: notion?.data, + linear: linear?.data, + asana: asana?.data, + }, + title, + body, + }); - if (businessLogicSummary) { - textToWrite += businessLogicSummary + "\n"; - } else { - textToWrite += - "Error getting summary" + businessLogicSummary?.error + "\n"; - } + if (businessLogicSummary) { + textToWrite += businessLogicSummary + "\n"; } else { - textToWrite += `AI Summary deactivated by ${userLogin} \n`; + textToWrite += + "Error getting summary" + businessLogicSummary?.error + "\n"; } + } else { + textToWrite += `AI Summary deactivated by ${userLogin} \n`; + } - textToWrite += generalMarkdownHelper({ - value: github, - userLogin, - systemName: "GitHub", - systemResponseName: "GitHub PRs", - }); - textToWrite += generalMarkdownHelper({ - value: jira, - userLogin, - systemName: "Jira", - systemResponseName: "Jira Tickets", - }); - textToWrite += generalMarkdownHelper({ - value: confluence, - userLogin, - systemName: "Confluence", - systemResponseName: "Confluence Docs", - }); - textToWrite += generalMarkdownHelper({ - value: slack, - userLogin, - systemName: "Slack", - systemResponseName: "Slack Threads", - }); - textToWrite += generalMarkdownHelper({ - value: notion, - userLogin, - systemName: "Notion", - systemResponseName: "Notion Pages", - }); - textToWrite += generalMarkdownHelper({ - value: linear, - userLogin, - systemName: "Linear", - systemResponseName: "Linear Tickets", - }); - textToWrite += generalMarkdownHelper({ - value: asana, - userLogin, - systemName: "Asana", - systemResponseName: "Asana Tasks", - }); - textToWrite += countMarkdown({ - count, - isPrivateRepo: repository.private, - repoName: repo, - }); + textToWrite += generalMarkdownHelper({ + value: github, + userLogin, + systemName: "GitHub", + systemResponseName: "GitHub PRs", + }); + textToWrite += generalMarkdownHelper({ + value: jira, + userLogin, + systemName: "Jira", + systemResponseName: "Jira Tickets", + }); + textToWrite += generalMarkdownHelper({ + value: confluence, + userLogin, + systemName: "Confluence", + systemResponseName: "Confluence Docs", + }); + textToWrite += generalMarkdownHelper({ + value: slack, + userLogin, + systemName: "Slack", + systemResponseName: "Slack Threads", + }); + textToWrite += generalMarkdownHelper({ + value: notion, + userLogin, + systemName: "Notion", + systemResponseName: "Notion Pages", + }); + textToWrite += generalMarkdownHelper({ + value: linear, + userLogin, + systemName: "Linear", + systemResponseName: "Linear Tickets", + }); + textToWrite += generalMarkdownHelper({ + value: asana, + userLogin, + systemName: "Asana", + systemResponseName: "Asana Tasks", + }); + textToWrite += countMarkdown({ + count, + isPrivateRepo: repository.private, + repoName: repo, + }); - // Make Watermelon Review the PR's business logic here by comparing the title with the AI-generated summary - await labelPullRequest({ - prTitle: title, - businessLogicSummary, - repo, - owner, - issue_number: number, - installationId, - reqUrl: request.url, - reqEmail: req.email, - }); + // Make Watermelon Review the PR's business logic here by comparing the title with the AI-generated summary + await labelPullRequest({ + prTitle: title, + businessLogicSummary, + repo, + owner, + issue_number: number, + installationId, + reqUrl: request.url, + reqEmail: req.email, + }); - await addActionLog({ - randomWords, - github, - jira, - slack, - notion, - linear, - asana, - textToWrite, - businessLogicSummary, + await addActionLog({ + randomWords, + github, + jira, + slack, + notion, + linear, + asana, + textToWrite, + businessLogicSummary, + owner, + repo, + number, + payload: req, + count, + watermelon_user, + }); + // Fetch all comments on the PR + const comments = await octokit.request( + "GET /repos/{owner}/{repo}/issues/{issue_number}/comments?sort=created&direction=desc", + { owner, repo, - number, - payload: req, - count, - watermelon_user, - }); - // Fetch all comments on the PR - const comments = await octokit.request( - "GET /repos/{owner}/{repo}/issues/{issue_number}/comments?sort=created&direction=desc", + issue_number: number, + headers: { + "X-GitHub-Api-Version": "2022-11-28", + }, + } + ); + console.info("comments.data.length", comments.data.length); + // Find our bot's comment + let botComment = comments.data.find((comment) => { + return comment.user.login.includes("watermelon-context"); + }); + if (botComment?.id) { + // Update the existing comment + await octokit.request( + "PATCH /repos/{owner}/{repo}/issues/comments/{comment_id}", { owner, repo, - issue_number: number, - headers: { - "X-GitHub-Api-Version": "2022-11-28", - }, + comment_id: botComment.id, + body: textToWrite, } ); - console.info("comments.data.length", comments.data.length); - // Find our bot's comment - let botComment = comments.data.find((comment) => { - return comment.user.login.includes("watermelon-context"); - }); - if (botComment?.id) { - // Update the existing comment - await octokit.request( - "PATCH /repos/{owner}/{repo}/issues/comments/{comment_id}", + } else { + // Post a new comment if no existing comment was found + await octokit + .request( + "POST /repos/{owner}/{repo}/issues/{issue_number}/comments", { owner, + issue_number: number, repo, - comment_id: botComment.id, body: textToWrite, } - ); - } else { - // Post a new comment if no existing comment was found - await octokit - .request( - "POST /repos/{owner}/{repo}/issues/{issue_number}/comments", - { - owner, - issue_number: number, + ) + .then((response) => { + successPosthogTracking({ + url: request.url, + email: user_email, + data: { repo, - body: textToWrite, - } - ) - .then((response) => { - successPosthogTracking({ - url: request.url, - email: user_email, - data: { - repo, - owner, - number, - action: req.action, - textToWrite, - }, - }); - }) - .catch((error) => { - failedPosthogTracking({ - url: request.url, - error: error.message, - email: req.email, - }); - return console.error("posting comment error", error); + owner, + number, + action: req.action, + textToWrite, + }, }); - } - } else { + }) + .catch((error) => { + failedPosthogTracking({ + url: request.url, + error: error.message, + email: req.email, + }); + return console.error("posting comment error", error); + }); + } + + // If the count is surpassed, we replace the + if (count.github_app_uses > 500) { textToWrite = `Your team has surpassed the free monthly usage. [Please click here](https://calendly.com/evargas-14/watermelon-business) to upgrade.` const comments = await octokit.request(