Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Add conditional if the count passes 500 #311

Merged
merged 5 commits into from
Sep 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions app/api/actions/github/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -295,7 +295,6 @@ export async function POST(request: Request) {
} = serviceAnswers;
if (error) {
return failedToFetchResponse({

url: request.url,
error: error.message,
email: req.email,
Expand Down Expand Up @@ -324,7 +323,6 @@ export async function POST(request: Request) {
}
}
const count = await addActionCount({ watermelon_user });
textToWrite += `### WatermelonAI Summary \n`;

let businessLogicSummary;
if (AISummary) {
Expand Down Expand Up @@ -410,7 +408,7 @@ export async function POST(request: Request) {
issue_number: number,
installationId,
reqUrl: request.url,
reqEmail: req.email
reqEmail: req.email,
});

await addActionLog({
Expand Down Expand Up @@ -492,6 +490,40 @@ export async function POST(request: Request) {
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.`
baristaGeek marked this conversation as resolved.
Show resolved Hide resolved

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,
Expand Down