From cea4891a2479f3770e081d3e90d3cf7a5538c241 Mon Sep 17 00:00:00 2001 From: Esteban Dalel R Date: Tue, 20 Jun 2023 15:03:00 -0500 Subject: [PATCH] Add non-registered user response --- pages/api/actions/github.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/pages/api/actions/github.ts b/pages/api/actions/github.ts index f33c60908..1e21eccf4 100644 --- a/pages/api/actions/github.ts +++ b/pages/api/actions/github.ts @@ -66,6 +66,28 @@ export default async (req, res) => { user_email, watermelon_user, } = wmUserData; + if (!watermelon_user) { + { + // 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, + body: "[Please login to Watermelon to see the results](https://app.watermelontools.com/)", + } + ) + .then((response) => { + console.log("post comment", response.data); + }) + .catch((error) => { + return console.error("posting comment error", error); + }); + return res.status(401).send("User not registered"); + } + } let octoCommitList = await octokit.request( "GET /repos/{owner}/{repo}/pulls/{pull_number}/commits", { @@ -78,7 +100,6 @@ export default async (req, res) => { } ); let commitList: string[] = []; - for (let index = 0; index < octoCommitList?.data?.length; index++) { commitList.push(octoCommitList.data[index].commit.message); }