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

Commit 068101d

Browse files
committed
Feature/obey settings (#175)
* get all data at the same time * Remove unused code * Restore function * Fix data flow * Fix possible nulls * Remove whitespace * Added settings link * Obey settings amount * Respect AI summary * Prevent writing if other deactivated * fix typo * fix typo * Respect amount * Fix comment logging
1 parent e625559 commit 068101d

1 file changed

Lines changed: 90 additions & 51 deletions

File tree

pages/api/actions/github.ts

Lines changed: 90 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export default async (req, res) => {
5151
jira_refresh_token,
5252
slack_token,
5353
cloudId,
54+
AISummary,
55+
JiraTickets,
56+
GitHubPRs,
57+
SlackMessages,
5458
user_email,
5559
} = wmUserData;
5660
let octoCommitList = await octokit.request(
@@ -278,6 +282,7 @@ export default async (req, res) => {
278282
owner,
279283
github_token,
280284
randomWords,
285+
amount: GitHubPRs,
281286
}),
282287
getJira({
283288
user: user_email,
@@ -286,79 +291,112 @@ export default async (req, res) => {
286291
jira_token,
287292
jira_refresh_token,
288293
randomWords,
294+
amount: JiraTickets,
295+
}),
296+
getSlack({
297+
title,
298+
body,
299+
slack_token,
300+
randomWords,
301+
amount: SlackMessages,
289302
}),
290-
getSlack({ title, body, slack_token, randomWords }),
291303
]);
292-
293-
const businessLogicSummary = await getOpenAISummary({
294-
ghValue,
295-
commitList,
296-
jiraValue,
297-
slackValue,
298-
title,
299-
body,
300-
});
304+
let businessLogicSummary;
301305
let textToWrite = "";
302306

303307
textToWrite += "### WatermelonAI Summary (BETA)";
304308
textToWrite += `\n`;
305-
if (businessLogicSummary) {
306-
textToWrite += businessLogicSummary;
307-
textToWrite += `\n`;
309+
310+
if (AISummary) {
311+
businessLogicSummary = await getOpenAISummary({
312+
ghValue,
313+
commitList,
314+
jiraValue,
315+
slackValue,
316+
title,
317+
body,
318+
});
319+
320+
if (businessLogicSummary) {
321+
console.log(businessLogicSummary);
322+
textToWrite += businessLogicSummary;
323+
} else {
324+
textToWrite += "Error getting summary" + businessLogicSummary.error;
325+
}
308326
} else {
309-
textToWrite += "Error getting summary" + businessLogicSummary.error;
327+
textToWrite += `AI Summary deactivated by ${pull_request.user.login}`;
310328
}
329+
330+
textToWrite += `\n`;
311331
textToWrite += "### GitHub PRs";
312-
if (!Array.isArray(ghValue) && ghValue?.error === "no github token") {
313-
textToWrite += `\n No results found :(`;
314-
} else if (Array.isArray(ghValue) && ghValue?.length) {
315-
for (let index = 0; index < ghValue?.length; index++) {
316-
const element = ghValue[index];
317-
textToWrite += `\n - [#${element.number} - ${element.title}](${element.html_url})`;
318-
textToWrite += `\n`;
332+
if (GitHubPRs) {
333+
if (!Array.isArray(ghValue) && ghValue?.error === "no github token") {
334+
textToWrite += `\n No results found :(`;
335+
} else if (Array.isArray(ghValue) && ghValue?.length) {
336+
for (let index = 0; index < ghValue?.length; index++) {
337+
const element = ghValue[index];
338+
textToWrite += `\n - [#${element.number} - ${element.title}](${element.html_url})`;
339+
textToWrite += `\n`;
340+
}
319341
}
342+
} else {
343+
textToWrite += `GitHub PRs deactivated by ${pull_request.user.login}`;
344+
345+
textToWrite += `\n`;
320346
}
321347

322348
textToWrite += `\n`;
323349

324350
textToWrite += "### Jira Tickets";
325-
if (jiraValue?.error === "no jira token") {
326-
textToWrite += `\n [Click here to login to Jira](https://app.watermelontools.com)`;
327-
} else {
328-
if (jiraValue?.length) {
329-
for (let index = 0; index < jiraValue.length; index++) {
330-
const element = jiraValue[index];
331-
textToWrite += `\n - [${element.key} - ${element.fields.summary}](${element.serverInfo.baseUrl}/browse/${element.key})`;
332-
textToWrite += `\n`;
333-
}
351+
if (JiraTickets) {
352+
if (jiraValue?.error === "no jira token") {
353+
textToWrite += `\n [Click here to login to Jira](https://app.watermelontools.com)`;
334354
} else {
335-
textToWrite += `\n No results found :(`;
355+
if (jiraValue?.length) {
356+
for (let index = 0; index < jiraValue.length; index++) {
357+
const element = jiraValue[index];
358+
textToWrite += `\n - [${element.key} - ${element.fields.summary}](${element.serverInfo.baseUrl}/browse/${element.key})`;
359+
textToWrite += `\n`;
360+
}
361+
} else {
362+
textToWrite += `\n No results found :(`;
363+
}
336364
}
365+
} else {
366+
textToWrite += `Jira Tickets deactivated by ${pull_request.user.login}`;
367+
368+
textToWrite += `\n`;
337369
}
338370
textToWrite += `\n`;
339371

340372
textToWrite += "### Slack Threads";
341-
if (
342-
!Array.isArray(slackValue) &&
343-
slackValue?.error === "no slack token"
344-
) {
345-
textToWrite += `\n [Click here to login to Slack](https://app.watermelontools.com)`;
346-
} else if (Array.isArray(slackValue)) {
347-
if (slackValue?.length) {
348-
for (let index = 0; index < slackValue.length; index++) {
349-
const element = slackValue[index];
350-
textToWrite += `\n - [#${element.channel.name} - ${
351-
element.username
352-
}\n ${
353-
element.text.length > 100
354-
? element.text.substring(0, 100) + "..."
355-
: element.text
356-
}](${element.permalink})`;
357-
textToWrite += `\n`;
373+
if (SlackMessages) {
374+
if (
375+
!Array.isArray(slackValue) &&
376+
slackValue?.error === "no slack token"
377+
) {
378+
textToWrite += `\n [Click here to login to Slack](https://app.watermelontools.com)`;
379+
} else if (Array.isArray(slackValue)) {
380+
if (slackValue?.length) {
381+
for (let index = 0; index < slackValue.length; index++) {
382+
const element = slackValue[index];
383+
textToWrite += `\n - [#${element.channel.name} - ${
384+
element.username
385+
}\n ${
386+
element.text.length > 100
387+
? element.text.substring(0, 100) + "..."
388+
: element.text
389+
}](${element.permalink})`;
390+
textToWrite += `\n`;
391+
}
392+
} else {
393+
textToWrite += `\n No results found :(`;
358394
}
359-
} else {
360-
textToWrite += `\n No results found :(`;
361395
}
396+
} else {
397+
textToWrite += `Slack Threads deactivated by ${pull_request.user.login}`;
398+
399+
textToWrite += `\n`;
362400
}
363401

364402
// Fetch all comments on the PR
@@ -375,7 +413,8 @@ export default async (req, res) => {
375413
let botComment = comments.data.find((comment) =>
376414
comment.user.login.includes("watermelon-context")
377415
);
378-
console.log("bc", botComment.id);
416+
console.log("bc", botComment);
417+
console.log("bcID", botComment.id);
379418
if (botComment) {
380419
// Update the existing comment
381420
await octokit.request(

0 commit comments

Comments
 (0)