diff --git a/.eslintrc.js b/.eslintrc.js index b94604ec..1b64c89c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -42,7 +42,6 @@ module.exports = { ignorePatterns: ["test", "dist", "build", "public", "/**/node_modules/*", ".eslintrc.js", "vite.config.ts", "vite-env.d.ts", "postcss.config.js", "tailwind.config.js", "vitest.config.ts", "playwright.config.ts", "e2e"], rules: { "indent": "off", - "@typescript-eslint/indent": "error", // eslint:recommended "arrow-body-style": ["error", "as-needed"], curly: ["error", "all"], @@ -82,7 +81,7 @@ module.exports = { }, ], "no-useless-rename": "error", - "no-useless-return": "error", + "no-useless-return": "warn", "no-var": "error", "object-shorthand": "error", "one-var": ["error", "never"], @@ -122,15 +121,7 @@ module.exports = { }, ], "array-bracket-newline": ["error", "consistent"], - "array-bracket-spacing": [ - "error", - "never", - { - arraysInArrays: true, - }, - ], "array-element-newline": ["error", "consistent"], - "arrow-parens": ["error", "as-needed"], "arrow-spacing": "error", "block-spacing": ["error", "always"], "brace-style": ["error", "1tbs"], @@ -148,7 +139,6 @@ module.exports = { "eol-last": ["error", "always"], "func-call-spacing": ["error", "never"], "function-call-argument-newline": ["error", "consistent"], - "function-paren-newline": ["error", "multiline-arguments"], "jsx-quotes": ["error", "prefer-double"], "key-spacing": [ "error", @@ -164,14 +154,6 @@ module.exports = { after: true, }, ], - "line-comment-position": [ - "error", - { - position: "above", - ignorePattern: "pragma", - applyDefaultIgnorePatterns: false, - }, - ], "linebreak-style": ["error", "unix"], "lines-around-comment": [ "error", @@ -196,24 +178,10 @@ module.exports = { exceptAfterSingleLine: true, }, ], - "multiline-ternary": ["error", "always-multiline"], - "new-parens": ["error", "never"], - "newline-per-chained-call": [ - "error", - { - ignoreChainWithDepth: 2, - }, - ], "no-multi-spaces": "error", "no-multiple-empty-lines": "error", "no-trailing-spaces": "error", "no-whitespace-before-property": "error", - "object-curly-newline": [ - "error", - { - multiline: true, - }, - ], "object-curly-spacing": [ "error", "always", @@ -228,16 +196,6 @@ module.exports = { allowAllPropertiesOnSameLine: true, }, ], - "operator-linebreak": [ - "error", - "after", - { - overrides: { - "?": "before", - ":": "before", - }, - }, - ], "padded-blocks": ["error", "never"], "padding-line-between-statements": [ "error", @@ -276,7 +234,6 @@ module.exports = { ], "semi-style": ["error", "last"], "space-before-blocks": ["error", "always"], - "space-before-function-paren": ["error", "always"], "space-infix-ops": [ "error", { @@ -307,7 +264,6 @@ module.exports = { functionPrototypeMethods: true, }, ], - "wrap-regex": "error", // plugin:react/recommended "react/destructuring-assignment": [ @@ -338,23 +294,10 @@ module.exports = { "react/jsx-closing-bracket-location": "error", "react/jsx-closing-tag-location": "error", "react/jsx-curly-brace-presence": ["error", "never"], - "react/jsx-curly-newline": ["error", "consistent"], "react/jsx-equals-spacing": ["error", "never"], "react/jsx-first-prop-new-line": ["error", "multiline-multiprop"], "react/jsx-fragments": ["error", "syntax"], "react/jsx-indent-props": "off", - "react/jsx-max-props-per-line": [ - "error", - { - maximum: 1, - }, - ], - "react/jsx-newline": [ - "error", - { - prevent: false, - }, - ], // "react/jsx-no-leaked-render": ["error", { // "validStrategies": ["coerce"] // }], @@ -364,22 +307,7 @@ module.exports = { allowExpressions: true, }, ], - "react/jsx-one-expression-per-line": [ - "error", - { - allow: "literal", - }, - ], "react/jsx-props-no-multi-spaces": "error", - "react/jsx-sort-props": [ - "error", - { - callbacksLast: true, - shorthandFirst: true, - multiline: "last", - reservedFirst: true, - }, - ], "react/jsx-tag-spacing": [ "error", { diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bf2ee412..2b995784 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -57,10 +57,18 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 10 steps: + - name: Generate token + id: generate_token + uses: tibdex/github-app-token@v1 + with: + app_id: ${{ secrets.OS_GITHUB_APP_ID }} + private_key: ${{ secrets.OS_GITHUB_APP_PRIVATE_KEY }} + - name: "☁️ checkout repository" uses: actions/checkout@v3 with: fetch-depth: 0 + token: ${{ steps.generate_token.outputs.token }} - name: "📂 download build artifacts" uses: actions/download-artifact@v2 @@ -70,9 +78,9 @@ jobs: - name: "🚀 release" id: semantic-release - uses: open-sauced/release@v2.1.1 + uses: open-sauced/release@v2 env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} cleanup: name: Cleanup actions diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..573d4c58 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "trailingComma": "all", + "tabWidth": 4, + "singleQuote": false +} diff --git a/CHANGELOG.md b/CHANGELOG.md index 79871743..e314c7e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,21 @@ > All notable changes to this project will be documented in this file +## [1.16.0-beta.1](https://github.com/open-sauced/ai/compare/v1.15.0...v1.16.0-beta.1) (2024-08-20) + + +### 🍕 Features + +* adds .prettierrc ([#310](https://github.com/open-sauced/ai/issues/310)) ([c1f0d1e](https://github.com/open-sauced/ai/commit/c1f0d1e8ab968d379ee3789f74529536a2bc2114)) +* Remove PR description generator ([#308](https://github.com/open-sauced/ai/issues/308)) ([e342847](https://github.com/open-sauced/ai/commit/e342847f2dadfaaca5ce5d52a5b1fe48e01e9d58)), closes [#307](https://github.com/open-sauced/ai/issues/307) +* Replaces velocity with OSCR ([#309](https://github.com/open-sauced/ai/issues/309)) ([5a0172d](https://github.com/open-sauced/ai/commit/5a0172d22074c935a5b516daea8daf8c6c716a41)) + + +### 🐛 Bug Fixes + +* Generates a token so the open-sauce bot can push to beta ([#313](https://github.com/open-sauced/ai/issues/313)) ([985b482](https://github.com/open-sauced/ai/commit/985b48232330cb3bbe3fef61936f62a526263882)) +* test driftage ([#311](https://github.com/open-sauced/ai/issues/311)) ([83c2415](https://github.com/open-sauced/ai/commit/83c24159a7e2c33bf93bceeda424e59ced494448)) + ## [1.15.0](https://github.com/open-sauced/ai/compare/v1.14.2...v1.15.0) (2024-01-30) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 8b3f0485..22dea8c4 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,12 +1,12 @@ { "name": "opensauced-browser-extension", - "version": "1.15.0", + "version": "1.16.0-beta.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "opensauced-browser-extension", - "version": "1.15.0", + "version": "1.16.0-beta.1", "dependencies": { "date-fns": "^2.30.0", "gpt-tokenizer": "^1.0.5", diff --git a/package.json b/package.json index 7919d72b..1d783f31 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "opensauced-browser-extension", "private": true, - "version": "1.15.0", + "version": "1.16.0-beta.1", "files": [ "dist" ], diff --git a/src/constants.ts b/src/constants.ts index 68fe569e..bab999a8 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,6 +1,8 @@ // 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 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"; export const SUPABASE_LOGIN_URL = `https://${import.meta.env.VITE_OPEN_SAUCED_SUPABASE_ID}.supabase.co/auth/v1/authorize`; @@ -12,14 +14,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`; @@ -29,12 +28,17 @@ export const OPEN_SAUCED_HIGHLIGHTS_LIST_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT} export const OPEN_SAUCED_EMOJIS_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/emojis`; // Content-scripts selectors -export const GITHUB_PROFILE_MENU_SELECTOR = ".p-nickname.vcard-username.d-block"; -export const GITHUB_PROFILE_EDIT_MENU_CLASS = "button.js-profile-editable-edit-button"; -export const GITHUB_PR_COMMENT_HEADER_CLASS = "timeline-comment-header clearfix d-flex"; -export const GITHUB_REVIEW_SUGGESTION_CLASS = "js-suggestion-button-placeholder"; +export const GITHUB_PROFILE_MENU_SELECTOR = + ".p-nickname.vcard-username.d-block"; +export const GITHUB_PROFILE_EDIT_MENU_CLASS = + "button.js-profile-editable-edit-button"; +export const GITHUB_PR_COMMENT_HEADER_CLASS = + "timeline-comment-header clearfix d-flex"; +export const GITHUB_REVIEW_SUGGESTION_CLASS = + "js-suggestion-button-placeholder"; export const GITHUB_REPO_ACTIONS_SELECTOR = ".pagehead-actions"; -export const GITHUB_PR_SUGGESTION_TEXT_AREA_Attribute = "[name='comment[body]']"; +export const GITHUB_PR_SUGGESTION_TEXT_AREA_Attribute = + "[name='comment[body]']"; export const GITHUB_PR_BASE_BRANCH_CLASS = "css-truncate css-truncate-target"; export const LINKEDIN_PROJECT_FORM_SELECTOR = ".artdeco-text-input--input"; 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 dc5c05a2..00000000 --- a/src/content-scripts/components/AICodeReview/AICodeReviewMenu.ts +++ /dev/null @@ -1,145 +0,0 @@ -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"; - -type SuggestionGenerator = ( - token: string, - code: string, - config: DescriptionConfig -) => 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; - } - - const descriptionConfig = await getAIDescriptionConfig(); - - if (!descriptionConfig) { - 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, [] ], - descriptionConfig.config.maxInputLength, - ) - ) { - 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, - descriptionConfig, - ); - - 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/components/AddPRToHighlights/AddPRToHighlightsButton.ts b/src/content-scripts/components/AddPRToHighlights/AddPRToHighlightsButton.ts index b5acc441..d1dc67d8 100644 --- a/src/content-scripts/components/AddPRToHighlights/AddPRToHighlightsButton.ts +++ b/src/content-scripts/components/AddPRToHighlights/AddPRToHighlightsButton.ts @@ -11,8 +11,8 @@ export const AddPRToHighlightsButton = () => { )}>