From a3efbb1c43cf03439d040332f75ee98117608413 Mon Sep 17 00:00:00 2001 From: Brian Douglas Date: Thu, 15 Aug 2024 17:16:25 -0700 Subject: [PATCH 1/3] Remove PR description generator Related to #307 --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/open-sauced/ai/issues/307?shareId=XXXX-XXXX-XXXX-XXXX). --- src/constants.ts | 4 - .../AICodeReview/AICodeReviewMenu.ts | 14 +- .../DescriptionGeneratorButton.ts | 99 -------- src/content-scripts/github.ts | 7 +- src/popup/pages/aiprdescription.tsx | 218 ------------------ src/popup/pages/settings.tsx | 6 +- src/utils/ai-utils/descriptionconfig.ts | 58 ----- .../dom-utils/addDescriptionGenerator.ts | 35 --- src/worker/background.ts | 3 - 9 files changed, 5 insertions(+), 439 deletions(-) delete mode 100644 src/content-scripts/components/GenerateAIDescription/DescriptionGeneratorButton.ts delete mode 100644 src/popup/pages/aiprdescription.tsx delete mode 100644 src/utils/ai-utils/descriptionconfig.ts delete mode 100644 src/utils/dom-utils/addDescriptionGenerator.ts diff --git a/src/constants.ts b/src/constants.ts index 68fe569e..717686ad 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,4 +1,3 @@ -// OpenSauced constants export const OPEN_SAUCED_INSIGHTS_DOMAIN = import.meta.env.VITE_OPEN_SAUCED_INSIGHTS_DOMAIN; export const OPEN_SAUCED_API_ENDPOINT = import.meta.env.VITE_OPEN_SAUCED_API_ENDPOINT; export const REPO_QUERY_API_ENDPOINT = "https://opensauced.tools"; @@ -12,14 +11,11 @@ export const SUPABASE_AUTH_COOKIE_NAME = `sb-${import.meta.env.VITE_OPEN_SAUCED_ export const SUPABASE_PKCE_VERIFIER_COOKIE_NAME = `sb-${import.meta.env.VITE_OPEN_SAUCED_SUPABASE_ID}-auth-token-code-verifier`; export const OPEN_SAUCED_AUTH_TOKEN_KEY = "os-access-token"; export const OPEN_SAUCED_OPTED_LOG_OUT_KEY = "opted-log-out"; -export const AI_PR_DESCRIPTION_CONFIG_KEY = "ai-pr-description-config"; - export const OPEN_SAUCED_USERS_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/users`; export const OPEN_SAUCED_REPOS_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/repos`; export const OPEN_SAUCED_SESSION_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/auth/session`; export const OPEN_SAUCED_USER_INSIGHTS_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/user/insights`; -export const OPEN_SAUCED_AI_PR_DESCRIPTION_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/prs/description/generate`; export const OPEN_SAUCED_USER_HIGHLIGHTS_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/user/highlights`; export const OPEN_SAUCED_AI_CODE_REFACTOR_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/prs/suggestion/generate`; export const OPEN_SAUCED_AI_CODE_EXPLANATION_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/prs/explanation/generate`; diff --git a/src/content-scripts/components/AICodeReview/AICodeReviewMenu.ts b/src/content-scripts/components/AICodeReview/AICodeReviewMenu.ts index dc5c05a2..7df148f8 100644 --- a/src/content-scripts/components/AICodeReview/AICodeReviewMenu.ts +++ b/src/content-scripts/components/AICodeReview/AICodeReviewMenu.ts @@ -1,9 +1,5 @@ import { GITHUB_PR_SUGGESTION_TEXT_AREA_Attribute } from "../../../constants"; import { insertTextAtCursor } from "../../../utils/ai-utils/cursorPositionInsert"; -import { - DescriptionConfig, - getAIDescriptionConfig, -} from "../../../utils/ai-utils/descriptionconfig"; import { getAuthToken, isLoggedIn, optLogIn } from "../../../utils/checkAuthentication"; import { createHtmlElement } from "../../../utils/createHtmlElement"; import { isOutOfContextBounds } from "../../../utils/fetchGithubAPIData"; @@ -11,7 +7,6 @@ import { isOutOfContextBounds } from "../../../utils/fetchGithubAPIData"; type SuggestionGenerator = ( token: string, code: string, - config: DescriptionConfig ) => Promise; export const AICodeReviewMenu = (items: HTMLLIElement[]) => { @@ -77,12 +72,6 @@ const handleSubmit = async ( return; } - const descriptionConfig = await getAIDescriptionConfig(); - - if (!descriptionConfig) { - return; - } - logo.classList.toggle("animate-spin"); button.classList.toggle("pointer-events-none"); @@ -109,7 +98,7 @@ const handleSubmit = async ( if ( isOutOfContextBounds( [selectedCode, [] ], - descriptionConfig.config.maxInputLength, + 3900, ) ) { logo.classList.toggle("animate-spin"); @@ -121,7 +110,6 @@ const handleSubmit = async ( const suggestionStream = await suggestionGenerator( token, selectedCode, - descriptionConfig, ); logo.classList.toggle("animate-spin"); diff --git a/src/content-scripts/components/GenerateAIDescription/DescriptionGeneratorButton.ts b/src/content-scripts/components/GenerateAIDescription/DescriptionGeneratorButton.ts deleted file mode 100644 index 12803465..00000000 --- a/src/content-scripts/components/GenerateAIDescription/DescriptionGeneratorButton.ts +++ /dev/null @@ -1,99 +0,0 @@ -import { createHtmlElement } from "../../../utils/createHtmlElement"; -import openSaucedLogoIcon from "../../../assets/opensauced-icon.svg"; -import { getPullRequestAPIURL } from "../../../utils/urlMatchers"; -import { getDescriptionContext, isOutOfContextBounds } from "../../../utils/fetchGithubAPIData"; -import { generateDescription } from "../../../utils/ai-utils/openai"; -import { insertTextAtCursor } from "../../../utils/ai-utils/cursorPositionInsert"; -import { getAIDescriptionConfig } from "../../../utils/ai-utils/descriptionconfig"; -import { getAuthToken, isLoggedIn, optLogIn } from "../../../utils/checkAuthentication"; - -export const DescriptionGeneratorButton = (number: number) => { - const descriptionGeneratorButton = createHtmlElement("a", { - id: `ai-description-button-${number}`, - innerHTML: ` - - - Generate PR description`, - onclick: handleSubmit, - }); - - return descriptionGeneratorButton; -}; - -const handleSubmit = async (event: Event) => { - const button = event.currentTarget as HTMLElement; - const logo = button.querySelector("#ai-description-button-logo"); - - - try { - if (!(await isLoggedIn())) { - return void optLogIn(); - } - - const descriptionConfig = await getAIDescriptionConfig(); - - if (!descriptionConfig) { - return; - } - - logo?.classList.toggle("animate-spin"); - button.classList.toggle("pointer-events-none"); - - - const { protocol, hostname, pathname } = window.location; - const descriptionStream = await getAiDescription(`${protocol}//${hostname}${pathname}`); - - logo?.classList.toggle("animate-spin"); - button.classList.toggle("pointer-events-none"); - const textArea = button.closest(".Box.CommentBox")?.querySelector("textarea"); - - if (textArea) { - insertTextAtCursor(textArea, descriptionStream); - } - } catch (error: unknown) { - logo?.classList.toggle("animate-spin"); - button.classList.toggle("pointer-events-none"); - - if (error instanceof Error) { - alert(error.message); - console.error("Description generation error:", error.message); - } - } -}; - -export const getAiDescription = async (prUrl: string) => { - const prApiUrl = await getPullRequestAPIURL(prUrl); - - const descriptionConfig = await getAIDescriptionConfig(); - - if (!descriptionConfig) { - throw new Error("Configuration file is empty!"); - } - - const [diff, commitMessages] = await getDescriptionContext(prApiUrl, descriptionConfig.config.source); - - if (!diff && !commitMessages) { - throw new Error(`No input context was generated.`); - } - if (isOutOfContextBounds([diff, commitMessages], descriptionConfig.config.maxInputLength)) { - throw new Error(`Max input length exceeded. Try setting the description source to commit-messages.`); - } - const token = await getAuthToken(); - const description = await generateDescription( - token, - descriptionConfig.config.language, - descriptionConfig.config.length, - descriptionConfig.config.temperature / 10, - descriptionConfig.config.tone, - diff, - commitMessages, - ); - - if (!description) { - throw new Error("No description was generated!"); - } - - return description; -}; - - diff --git a/src/content-scripts/github.ts b/src/content-scripts/github.ts index 26fcc681..8113ce74 100644 --- a/src/content-scripts/github.ts +++ b/src/content-scripts/github.ts @@ -14,7 +14,6 @@ import injectAddPRToHighlightsButton from "../utils/dom-utils/addPRToHighlights" // import injectRepoVotingButtons from "../utils/dom-utils/repoVotingButtons"; import domUpdateWatch from "../utils/dom-utils/domUpdateWatcher"; -import injectDescriptionGeneratorButton from "../utils/dom-utils/addDescriptionGenerator"; import injectChangeSuggestorButton from "../utils/dom-utils/changeSuggestorButton"; import prEditWatch, { prReviewWatch } from "../utils/dom-utils/prWatcher"; import injectChatDialog from "../utils/dom-utils/addChatDialog"; @@ -25,12 +24,12 @@ const processGithubPage = async () => { document.documentElement.classList.add("dark"); } if (isPullRequestCreatePage(window.location.href)) { - void injectDescriptionGeneratorButton(); + // void injectDescriptionGeneratorButton(); } else if (isPullRequestFilesChangedPage(window.location.href)) { prReviewWatch(injectChangeSuggestorButton, 500); } else if (isGithubPullRequestPage(window.location.href)) { - prEditWatch(injectDescriptionGeneratorButton, 500); - void injectDescriptionGeneratorButton(); + prEditWatch(injectChangeSuggestorButton, 500); + // void injectDescriptionGeneratorButton(); void injectAddPRToHighlightsButton(); } else if (isGithubProfilePage(window.location.href)) { const username = getGithubUsername(window.location.href); diff --git a/src/popup/pages/aiprdescription.tsx b/src/popup/pages/aiprdescription.tsx deleted file mode 100644 index 1dcc352d..00000000 --- a/src/popup/pages/aiprdescription.tsx +++ /dev/null @@ -1,218 +0,0 @@ -import React, { useEffect, useReducer } from "react"; -import { FaChevronLeft } from "react-icons/fa"; -import OpenSaucedLogo from "../../assets/opensauced-logo.svg"; -import toast, { Toaster } from "react-hot-toast"; - -import { - getAIDescriptionConfig, - DescriptionTone, - DescriptionSource, - DescriptionLanguage, - setAIDescriptionConfig, - getDefaultDescriptionConfig, -} from "../../utils/ai-utils/descriptionconfig"; -import { configurationReducer } from "../../utils/ai-utils/configurationReducer"; -import { goBack } from "react-chrome-extension-router"; - -const AIPRDescription = () => { - const [config, dispatch] = useReducer(configurationReducer, getDefaultDescriptionConfig()); - - const tones: DescriptionTone[] = ["exciting", "persuasive", "informative", "humorous", "formal"]; - const sources: DescriptionSource[] = ["diff", "commitMessage", "both"]; - const languages: DescriptionLanguage[] = ["english", "spanish", "french", "german", "italian", "portuguese", "dutch", "russian", "chinese", "korean"]; - - - useEffect(() => { - const descriptionConfig = async () => { - const configData = await getAIDescriptionConfig(); - - dispatch({ type: "SET", value: configData }); - }; - - void descriptionConfig(); - }, []); - - const handleFormSubmit = (e: React.FormEvent) => { - e.preventDefault(); - void setAIDescriptionConfig(config); - toast.success("Configuration updated!"); - }; - - return ( - - <> - - -
-
-
-
- - - OpenSauced logo -
-
- -
-
-
-

- AI Configuration: -

- -
-
-

- Description Length [ - - {config.config.length} - - ] -

- - dispatch({ type: "SET_LENGTH", value: parseInt(e.target.value) })} - /> -
- -
-

- Temperature [ - - {config.config.temperature / 10} - - ] -

- - dispatch({ type: "SET_TEMPERATURE", value: parseInt(e.target.value) })} - /> -
- -
-

- Max Input Length [ - - {config.config.maxInputLength} - - ] -

- - dispatch({ type: "SET_MAX_INPUT_LENGTH", value: parseInt(e.target.value) })} - /> -
- -
-

Description Language

- - -
- -
-

Description Tone

- - -
- -
-

Description Source

- - -
-
- - -
-
-
-
-
- - ); -}; - -export default AIPRDescription; diff --git a/src/popup/pages/settings.tsx b/src/popup/pages/settings.tsx index 8d6606d7..cadb2a6e 100644 --- a/src/popup/pages/settings.tsx +++ b/src/popup/pages/settings.tsx @@ -1,11 +1,9 @@ import Toggle from "../components/ToggleSwitch"; -import AIPRDescription from "./aiprdescription"; import { useEffect, useState } from "react"; export type SettingsConfig = Record; const settingLabels: Record = { - aiPrDescription: "AI PR Description", codeRefactor: "AI Code Review", }; @@ -17,7 +15,7 @@ const Settings = () => { const settingsConfig = await chrome.storage.sync.get("osSettingsConfig"); if (settingsConfig.osSettingsConfig === undefined) { - const defaultSettings = { aiPrDescription: true, codeRefactor: true }; + const defaultSettings = { codeRefactor: true }; await chrome.storage.sync.set({ osSettingsConfig: defaultSettings }); setSettingsConfig(defaultSettings); @@ -31,8 +29,6 @@ const Settings = () => { return (
- -
diff --git a/src/utils/ai-utils/descriptionconfig.ts b/src/utils/ai-utils/descriptionconfig.ts deleted file mode 100644 index bfb9c2a9..00000000 --- a/src/utils/ai-utils/descriptionconfig.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { AI_PR_DESCRIPTION_CONFIG_KEY } from "../../constants"; - -export type DescriptionTone = "exciting" | "persuasive" | "informative" | "humorous" | "formal"; -export type DescriptionSource = "diff" | "commitMessage" | "both"; -export type DescriptionLanguage = - | "english" - | "spanish" - | "french" - | "german" - | "italian" - | "portuguese" - | "dutch" - | "russian" - | "chinese" - | "korean"; - -export interface DescriptionConfig { - config: { - length: number; - maxInputLength: number; - temperature: number; - language: DescriptionLanguage; - tone: DescriptionTone; - source: DescriptionSource; - }; - [key: string]: any; -} - -export const getAIDescriptionConfig = async (): Promise< -DescriptionConfig | undefined -> => { - const response: DescriptionConfig | undefined = ( - await chrome.storage.local.get(AI_PR_DESCRIPTION_CONFIG_KEY) - )[AI_PR_DESCRIPTION_CONFIG_KEY]; - - return response; -}; - -export const setAIDescriptionConfig = async (data: DescriptionConfig): Promise => { - await chrome.storage.local.set({ [AI_PR_DESCRIPTION_CONFIG_KEY]: data }); -}; - -export const getDefaultDescriptionConfig = (): DescriptionConfig => ({ - config: { - length: 500, - maxInputLength: 3900, - temperature: 7, - language: "english", - tone: "formal", - source: "diff", - }, -}); - -export const setDefaultDescriptionConfig = () => { - const defaultConfig = getDefaultDescriptionConfig(); - - void setAIDescriptionConfig(defaultConfig); -}; diff --git a/src/utils/dom-utils/addDescriptionGenerator.ts b/src/utils/dom-utils/addDescriptionGenerator.ts deleted file mode 100644 index 22534a46..00000000 --- a/src/utils/dom-utils/addDescriptionGenerator.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { DescriptionGeneratorButton } from "../../content-scripts/components/GenerateAIDescription/DescriptionGeneratorButton"; -import { isPublicRepository } from "../fetchGithubAPIData"; -import { SettingsConfig } from "../../popup/pages/settings"; - -const injectDescriptionGeneratorButton = async () => { - if (document.getElementById("ai-description-button") || !(await isPublicRepository(window.location.href))) { - return; - } - - const settingsConfig = await new Promise(resolve => { - chrome.storage.sync.get("osSettingsConfig", result => { - resolve(result.osSettingsConfig); - }); - }); - - if (settingsConfig) { - const { aiPrDescription } = settingsConfig as SettingsConfig; - - if (!aiPrDescription) { - return; - } - } - - const firstPrDescription = document.querySelectorAll(".ActionBar-item-container"); - - firstPrDescription.forEach((item, index) => { - if (!item.querySelector(`#ai-description-button-${index}`)) { - const addGeneratorButton = DescriptionGeneratorButton(index); - - item.insertBefore(addGeneratorButton, item.firstChild); - } - }); -}; - -export default injectDescriptionGeneratorButton; diff --git a/src/worker/background.ts b/src/worker/background.ts index 8520430c..e959ccc0 100644 --- a/src/worker/background.ts +++ b/src/worker/background.ts @@ -1,10 +1,7 @@ import { LINKEDIN_PROJECT_FORM_SELECTOR } from "../constants"; import { Message, MessageType } from "../ts/types"; -import { setDefaultDescriptionConfig } from "../utils/ai-utils/descriptionconfig"; import { getRepoAPIURL } from "../utils/urlMatchers"; -chrome.runtime.onInstalled.addListener(setDefaultDescriptionConfig); - chrome.runtime.onMessage.addListener(async (message: Message) => { // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (message.type === MessageType.LinkedInProject) { From 292534b808388774bf910ad847d1adbfffe2d66c Mon Sep 17 00:00:00 2001 From: Brian 'bdougie' Douglas Date: Thu, 15 Aug 2024 18:51:20 -0700 Subject: [PATCH 2/3] removes all generative AI features --- .../AICodeReview/AICodeReviewButton.ts | 49 ---- .../AICodeReview/AICodeReviewMenu.ts | 133 ---------- src/content-scripts/github.ts | 41 +-- src/popup/pages/posthighlight.tsx | 239 ++++++++---------- src/popup/pages/settings.tsx | 77 +++--- src/utils/ai-utils/configurationReducer.ts | 35 --- src/utils/ai-utils/openai.ts | 144 ----------- src/utils/dom-utils/changeSuggestorButton.ts | 9 - src/utils/fetchGithubAPIData.ts | 16 -- 9 files changed, 144 insertions(+), 599 deletions(-) delete mode 100644 src/content-scripts/components/AICodeReview/AICodeReviewButton.ts delete mode 100644 src/content-scripts/components/AICodeReview/AICodeReviewMenu.ts delete mode 100644 src/utils/ai-utils/configurationReducer.ts delete mode 100644 src/utils/ai-utils/openai.ts diff --git a/src/content-scripts/components/AICodeReview/AICodeReviewButton.ts b/src/content-scripts/components/AICodeReview/AICodeReviewButton.ts deleted file mode 100644 index 273ed1f0..00000000 --- a/src/content-scripts/components/AICodeReview/AICodeReviewButton.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { createHtmlElement } from "../../../utils/createHtmlElement"; -import openSaucedLogoIcon from "../../../assets/opensauced-icon.svg"; -import { generateCodeExplanation, generateCodeSuggestion, generateCodeTest } from "../../../utils/ai-utils/openai"; -import { - AICodeReviewMenu, - AICodeReviewMenuItem, -} from "./AICodeReviewMenu"; - - -export const AICodeReviewButton = (commentNode: HTMLElement) => { - const changeSuggestorButton = createHtmlElement("a", { - innerHTML: ` - - `, - onclick: (event: MouseEvent) => { - event.stopPropagation(); - menu.classList.toggle("hidden"); - }, - id: "os-ai-change-gen", - }); - - const refactorCode = AICodeReviewMenuItem( - "Refactor Code", - "Generate a code refactor", - generateCodeSuggestion, - commentNode, - ); - const testCode = AICodeReviewMenuItem( - "Test Code", - "Generate a test for the code", - generateCodeTest, - commentNode, - ); - const explainCode = AICodeReviewMenuItem( - "Explain Code", - "Generate an explanation for the code", - generateCodeExplanation, - commentNode, - ); - - const menu = AICodeReviewMenu([refactorCode, testCode, explainCode]); - - changeSuggestorButton.append(menu); - return changeSuggestorButton; -}; - - diff --git a/src/content-scripts/components/AICodeReview/AICodeReviewMenu.ts b/src/content-scripts/components/AICodeReview/AICodeReviewMenu.ts deleted file mode 100644 index 7df148f8..00000000 --- a/src/content-scripts/components/AICodeReview/AICodeReviewMenu.ts +++ /dev/null @@ -1,133 +0,0 @@ -import { GITHUB_PR_SUGGESTION_TEXT_AREA_Attribute } from "../../../constants"; -import { insertTextAtCursor } from "../../../utils/ai-utils/cursorPositionInsert"; -import { getAuthToken, isLoggedIn, optLogIn } from "../../../utils/checkAuthentication"; -import { createHtmlElement } from "../../../utils/createHtmlElement"; -import { isOutOfContextBounds } from "../../../utils/fetchGithubAPIData"; - -type SuggestionGenerator = ( - token: string, - code: string, -) => Promise; - -export const AICodeReviewMenu = (items: HTMLLIElement[]) => { - const menu = createHtmlElement("div", { - className: "SelectMenu js-slash-command-menu hidden mt-6", - innerHTML: `
-
-
- - OpenSauced.ai -
-
AI
- - Give feedback - -
-
-
    -
-
-
`, - }); - - menu.querySelector("ul")?.append(...items); - - document.addEventListener("click", event => { - if (event.target instanceof HTMLElement) { - menu.classList.add("hidden"); - } - }); - return menu; -}; - -export const AICodeReviewMenuItem = (title: string, description: string, suggestionGenerator: SuggestionGenerator, commentNode: HTMLElement) => { - const menuItem = createHtmlElement("li", { - className: "SelectMenu-item d-block slash-command-menu-item", - role: "option", - onclick: () => { - void handleSubmit(suggestionGenerator, commentNode); - }, - innerHTML: `
${title}
- ${description}`, - }); - - return menuItem; -}; - -const handleSubmit = async ( - suggestionGenerator: SuggestionGenerator, - commentNode: HTMLElement, -) => { - const logo = commentNode.querySelector("#ai-description-button-logo"); - const button = commentNode.querySelector("#os-ai-change-gen"); - - try { - if (!(await isLoggedIn())) { - return void optLogIn(); - } - - if (!logo || !button) { - return; - } - - logo.classList.toggle("animate-spin"); - button.classList.toggle("pointer-events-none"); - - const selectedLines = document.querySelectorAll( - ".code-review.selected-line", - ); - let selectedCode = Array.from(selectedLines) - .map(line => line.textContent) - .join("\n"); - - // find input with name="position" and get its value - if (!selectedCode) { - const positionElement = commentNode.querySelector( - "input[name=position]", - )!; - const position = positionElement.getAttribute("value")!; - - const codeDiv = document.querySelector(`[data-line-number="${position}"]`) - ?.nextSibling?.nextSibling as HTMLElement; - - selectedCode = - codeDiv.getElementsByClassName("blob-code-inner")[0].textContent!; - } - if ( - isOutOfContextBounds( - [selectedCode, [] ], - 3900, - ) - ) { - logo.classList.toggle("animate-spin"); - return alert( - `Max input length exceeded. Try reducing the number of selected lines to refactor.`, - ); - } - const token = await getAuthToken(); - const suggestionStream = await suggestionGenerator( - token, - selectedCode, - ); - - logo.classList.toggle("animate-spin"); - button.classList.toggle("pointer-events-none"); - if (!suggestionStream) { - return console.error("No description was generated!"); - } - const textArea = commentNode.querySelector( - GITHUB_PR_SUGGESTION_TEXT_AREA_Attribute, - )!; - - insertTextAtCursor(textArea as HTMLTextAreaElement, suggestionStream); - } catch (error: unknown) { - logo?.classList.toggle("animate-spin"); - button?.classList.toggle("pointer-events-none"); - - if (error instanceof Error) { - console.error("Description generation error:", error.message); - } - } -}; diff --git a/src/content-scripts/github.ts b/src/content-scripts/github.ts index 8113ce74..b60857f3 100644 --- a/src/content-scripts/github.ts +++ b/src/content-scripts/github.ts @@ -1,37 +1,19 @@ import { getGithubUsername, isGithubProfilePage, - isGithubPullRequestPage, - isGithubRepoPage, - isPullRequestCreatePage, - isPullRequestFilesChangedPage, } from "../utils/urlMatchers"; import { isOpenSaucedUser } from "../utils/fetchOpenSaucedApiData"; import injectViewOnOpenSauced from "../utils/dom-utils/viewOnOpenSauced"; import injectInviteToOpenSauced from "../utils/dom-utils/inviteToOpenSauced"; import { prefersDarkMode } from "../utils/colorPreference"; -import injectAddPRToHighlightsButton from "../utils/dom-utils/addPRToHighlights"; -// import injectRepoVotingButtons from "../utils/dom-utils/repoVotingButtons"; import domUpdateWatch from "../utils/dom-utils/domUpdateWatcher"; -import injectChangeSuggestorButton from "../utils/dom-utils/changeSuggestorButton"; -import prEditWatch, { prReviewWatch } from "../utils/dom-utils/prWatcher"; -import injectChatDialog from "../utils/dom-utils/addChatDialog"; -import { pageUrlWatch } from "../utils/dom-utils/pageUrlWatcher"; const processGithubPage = async () => { if (prefersDarkMode(document.cookie)) { document.documentElement.classList.add("dark"); } - if (isPullRequestCreatePage(window.location.href)) { - // void injectDescriptionGeneratorButton(); - } else if (isPullRequestFilesChangedPage(window.location.href)) { - prReviewWatch(injectChangeSuggestorButton, 500); - } else if (isGithubPullRequestPage(window.location.href)) { - prEditWatch(injectChangeSuggestorButton, 500); - // void injectDescriptionGeneratorButton(); - void injectAddPRToHighlightsButton(); - } else if (isGithubProfilePage(window.location.href)) { + if (isGithubProfilePage(window.location.href)) { const username = getGithubUsername(window.location.href); if (!username) { @@ -42,29 +24,8 @@ const processGithubPage = async () => { } else { injectInviteToOpenSauced(username); } - } else if (isGithubRepoPage(window.location.href)) { - const ownerName = getGithubUsername(window.location.href) ?? ""; - const repoName = window.location.href.split("/").pop() ?? ""; - - await injectChatDialog(ownerName, repoName); - - pageUrlWatch(() => { - if (document.getElementById("repo-query-root")) { - document.getElementById("repo-query-root")?.remove(); - } - }, 50); } - /* - * commenting out repo voting because it's not ready yet // issue #106 - * } else if (isGithubRepoPage(window.location.href)) { - * const ownerName = getGithubUsername(window.location.href) ?? ""; - * const repoName = window.location.href.split("/").pop() ?? ""; - * - * await injectRepoVotingButtons(ownerName, repoName); - * } - */ - domUpdateWatch(processGithubPage, 50); }; diff --git a/src/popup/pages/posthighlight.tsx b/src/popup/pages/posthighlight.tsx index 0498ff7e..16ecc07a 100644 --- a/src/popup/pages/posthighlight.tsx +++ b/src/popup/pages/posthighlight.tsx @@ -6,138 +6,119 @@ import toast, { Toaster } from "react-hot-toast"; import { createHighlight } from "../../utils/fetchOpenSaucedApiData"; import { goBack, goTo } from "react-chrome-extension-router"; import { OPEN_SAUCED_INSIGHTS_DOMAIN } from "../../constants"; -import { getAiDescription } from "../../content-scripts/components/GenerateAIDescription/DescriptionGeneratorButton"; import Home from "./home"; -const PostOnHighlight = ({ prUrl, prTitle }: { prUrl: string, prTitle: string }) => { - const { authToken, user } = useAuth(); - const [pageURL, setPageURL] = useState(""); - const [highlightTitle, setHighlightTitle] = useState(""); - const [highlightContent, setHighlightContent] = useState(""); - const [isSendButtonEnabled, enableSendButton] = useState(true); - - const generateAiDescription = () => { - enableSendButton(false); - const description = getAiDescription(prUrl); - - toast.promise(description, { - loading: "Generating summary...", - success: data => { - enableSendButton(true); - setHighlightContent(data); - - return "Successfully Generated Summary"; - }, - error: e => { - enableSendButton(true); - return `Uh oh, there was an error! ${e.message}`; - }, - }).catch(console.error); - }; - - - // post highlight function - const postHighlight = () => { - enableSendButton(false); - const postHighlightAPI = createHighlight((authToken ?? ""), pageURL, highlightTitle, highlightContent); - - toast.promise(postHighlightAPI, { - loading: "Loading ...", - success: data => { - enableSendButton(true); - if (!data.ok) { - throw new Error(`Status code ${data.status}`); - } - goTo(Home, { forceRefresh: true }); - return ( - - - See the highlight live - - - ); - }, - error: e => { - enableSendButton(true); - return `Uh oh, there was an error! ${e.message}`; - }, - }).catch(console.error); - }; - - useEffect(() => { - setPageURL(prUrl); - setHighlightTitle(prTitle); - }, []); - - return ( -
- - -
- -
-
- - - OpenSauced logo -
-
- -
- - setHighlightTitle(e.target.value)} - /> - -