Skip to content

Commit

Permalink
Merge pull request #155 from open-sauced/beta
Browse files Browse the repository at this point in the history
v1.4.0-beta.2 -> main
  • Loading branch information
bdougie committed Jun 3, 2023
2 parents c94523b + 4b08cee commit c338075
Show file tree
Hide file tree
Showing 27 changed files with 599 additions and 84 deletions.
3 changes: 3 additions & 0 deletions .env.development
@@ -0,0 +1,3 @@
VITE_OPEN_SAUCED_INSIGHTS_DOMAIN = "beta.insights.opensauced.pizza"
VITE_OPEN_SAUCED_API_ENDPOINT = "https://beta.api.opensauced.pizza/v1"
VITE_OPEN_SAUCED_SUPABASE_ID = "fcqqkxwlntnrtjfbcioz"
3 changes: 3 additions & 0 deletions .env.production
@@ -0,0 +1,3 @@
VITE_OPEN_SAUCED_INSIGHTS_DOMAIN = "insights.opensauced.pizza"
VITE_OPEN_SAUCED_API_ENDPOINT = "https://api.opensauced.pizza/v1"
VITE_OPEN_SAUCED_SUPABASE_ID = "ibcwmlhcimymasokhgvn"
3 changes: 1 addition & 2 deletions .github/workflows/triage.yml
Expand Up @@ -12,9 +12,8 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: disable take an issue
- name: take an issue
uses: bdougie/take-action@main
with:
message: The auto-take issues workflow is not enabled here, we can only assign issues to @open-sauced/triage, @open-sauced/committers, @open-sauced/maintainers in this repo for now. We suggest folks not on the team open issues and take a look at the [Bugs](https://github.com/orgs/open-sauced/projects/6) or [Papercuts](https://github.com/open-sauced/insights/issues?q=is%3Aopen+is%3Aissue+milestone%3APapercuts). If you would like to find good first issues, please check out the companion project to this, [open-sauced/hot](https://github.com/open-sauced/hot).
issueCurrentlyAssignedMessage: Thanks for being interested in this issue. It looks like this ticket is already assigned to a contributor.
token: ${{ secrets.GITHUB_TOKEN }}
50 changes: 50 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,56 @@

> All notable changes to this project will be documented in this file
## [1.4.0-beta.2](https://github.com/open-sauced/ai/compare/v1.4.0-beta.1...v1.4.0-beta.2) (2023-06-03)


### 🍕 Features

* uses username on highlight instead of full name ([#162](https://github.com/open-sauced/ai/issues/162)) ([801fe5a](https://github.com/open-sauced/ai/commit/801fe5a2fdfa69268b46bc9bdf7ef00ffadf5fdb))

## [1.4.0-beta.1](https://github.com/open-sauced/ai/compare/v1.3.1-beta.5...v1.4.0-beta.1) (2023-06-03)


### 🍕 Features

* latest highlights ([#154](https://github.com/open-sauced/ai/issues/154)) ([0ccd0e7](https://github.com/open-sauced/ai/commit/0ccd0e778c7d290e9ab2c9fbe97fc3c04f3be878))

## [1.3.1-beta.5](https://github.com/open-sauced/ai/compare/v1.3.1-beta.4...v1.3.1-beta.5) (2023-06-03)


### 🐛 Bug Fixes

* undefined config during build ([#158](https://github.com/open-sauced/ai/issues/158)) ([c986086](https://github.com/open-sauced/ai/commit/c986086f0b819746bd330fe17e3c94537633e6f4))

## [1.3.1-beta.4](https://github.com/open-sauced/ai/compare/v1.3.1-beta.3...v1.3.1-beta.4) (2023-05-29)


### 🐛 Bug Fixes

* Post a highlight ([#101](https://github.com/open-sauced/ai/issues/101)) ([e3b7051](https://github.com/open-sauced/ai/commit/e3b7051826f016bbd64c8d0b6a37ae2c48865879))

## [1.3.1-beta.3](https://github.com/open-sauced/ai/compare/v1.3.1-beta.2...v1.3.1-beta.3) (2023-05-29)


### ✅ Tests

* add tests for checkAuth.ts ([#149](https://github.com/open-sauced/ai/issues/149)) ([3a79fac](https://github.com/open-sauced/ai/commit/3a79facf2196537b4cfc0ce763ed74934c7b268f))

## [1.3.1-beta.2](https://github.com/open-sauced/ai/compare/v1.3.1-beta.1...v1.3.1-beta.2) (2023-05-27)


### ✅ Tests

* add tests for utils/urlMatchers.ts ([#143](https://github.com/open-sauced/ai/issues/143)) ([26702e6](https://github.com/open-sauced/ai/commit/26702e689641138a791f3c8cb935ddc99540a19e))

## [1.3.1-beta.1](https://github.com/open-sauced/ai/compare/v1.3.0...v1.3.1-beta.1) (2023-05-27)


### 🐛 Bug Fixes

* remove auto-take message from triage.yml ([258a828](https://github.com/open-sauced/ai/commit/258a8284d294d01b4228ca17d3b4d591692a890b))
* rename triage.yml ([3b9a14b](https://github.com/open-sauced/ai/commit/3b9a14bab991c739b9e57b1d0d829100695f47fb))

## [1.3.0](https://github.com/open-sauced/ai/compare/v1.2.0...v1.3.0) (2023-05-27)


Expand Down
11 changes: 11 additions & 0 deletions README.md
Expand Up @@ -38,12 +38,23 @@ To install the project dependencies:
npm ci
```


To run a local instance of the project:

### On development environment

```shell
npm run dev
```

### On Production environment

```shell
npm run build
npm run preview
```


## Installing the local build on a Chromium based browser:
After running the above commands,
1. Navigate to `chrome://extensions`.
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Expand Up @@ -20,6 +20,6 @@
"48": "src/assets/os-icons/os-icon-48.png",
"128": "src/assets/os-icons/os-icon-128.png"
},
"host_permissions": ["https://github.com/*", "https://insights.opensauced.pizza/*"],
"host_permissions": ["https://github.com/*", "https://*.insights.opensauced.pizza/*"],
"permissions": ["storage", "tabs", "cookies"]
}
4 changes: 2 additions & 2 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "opensauced-browser-extension",
"private": true,
"version": "1.3.0",
"version": "1.4.0-beta.2",
"files": [
"dist"
],
Expand Down
23 changes: 14 additions & 9 deletions src/constants.ts
@@ -1,18 +1,23 @@
// OpenSauced constants
export const SUPABASE_LOGIN_URL = "https://ibcwmlhcimymasokhgvn.supabase.co/auth/v1/authorize?provider=github&redirect_to=https://insights.opensauced.pizza/";
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 SUPABASE_LOGIN_URL = `https://${import.meta.env.VITE_OPEN_SAUCED_SUPABASE_ID}.supabase.co/auth/v1/authorize?provider=github&redirect_to=https://${OPEN_SAUCED_INSIGHTS_DOMAIN}/`;


export const SUPABASE_AUTH_COOKIE_NAME = "supabase-auth-token";
export const OPEN_SAUCED_AUTH_TOKEN_KEY = "os-access-token";
export const OPEN_SAUCED_OPTED_LOG_OUT_KEY = "opted-log-out";
export const OPEN_SAUCED_INSIGHTS_DOMAIN = "insights.opensauced.pizza";
export const AI_PR_DESCRIPTION_CONFIG_KEY = "ai-pr-description-config";

// API endpoints
export const OPEN_SAUCED_USERS_ENDPOINT = "https://api.opensauced.pizza/v1/users";
export const OPEN_SAUCED_REPOS_ENDPOINT = "https://api.opensauced.pizza/v1/repos";
export const OPEN_SAUCED_SESSION_ENDPOINT = "https://api.opensauced.pizza/v1/auth/session";
export const OPEN_SAUCED_USER_INSIGHTS_ENDPOINT = "https://api.opensauced.pizza/v1/user/insights";
export const OPEN_SAUCED_AI_PR_DESCRIPTION_ENDPOINT = "https://api.opensauced.pizza/v1/prs/description/generate";
export const OPEN_SAUCED_AI_CODE_REFACTOR_ENDPOINT = "https://api.opensauced.pizza/v1/prs/suggestion/generate";

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_HIGHLIGHTS_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/highlights/list`;

// GitHub constants/selectors
export const GITHUB_PROFILE_MENU_SELECTOR = ".p-nickname.vcard-username.d-block";
Expand Down
@@ -1,5 +1,6 @@
import { createHtmlElement } from "../../../utils/createHtmlElement";
import openSaucedLogoIcon from "../../../assets/opensauced-icon.svg";
import { OPEN_SAUCED_INSIGHTS_DOMAIN } from "../../../constants";

export const AddPRToHighlightsButton = () => {
const addPRToHighlightsButton = createHtmlElement("a", {
Expand All @@ -9,7 +10,7 @@ export const AddPRToHighlightsButton = () => {
openSaucedLogoIcon,
)}>
<details-menu id="details-menu-os" class="dropdown-menu hidden dropdown-menu-sw color-fg-default w-48 mt-2">
<a href="https://insights.opensauced.pizza/feed?prurl=${encodeURIComponent(window.location.href)}" class="dropdown-item" target="_blank">
<a href="https://${OPEN_SAUCED_INSIGHTS_DOMAIN}/feed?prurl=${encodeURIComponent(window.location.href)}" class="dropdown-item" target="_blank">
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-plus">
<path d="M7.75 2a.75.75 0 0 1 .75.75V7h4.25a.75.75 0 0 1 0 1.5H8.5v4.25a.75.75 0 0 1-1.5 0V8.5H2.75a.75.75 0 0 1 0-1.5H7V2.75A.75.75 0 0 1 7.75 2Z"></path>
</svg> Add PR to Highlights
Expand Down
Expand Up @@ -23,56 +23,69 @@ export const DescriptionGeneratorButton = () => {
};

const handleSubmit = async () => {
const logo = document.getElementById("ai-description-button-logo") ?? null;

try {
if (!(await isLoggedIn())) {
return window.open(SUPABASE_LOGIN_URL, "_blank");
}
const logo = document.getElementById("ai-description-button-logo");

if (!logo) {
return;
}
const url = getPullRequestAPIURL(window.location.href);
const descriptionConfig = await getAIDescriptionConfig();

if (!descriptionConfig) {
return;
}
if (!descriptionConfig.enabled) {
return alert("AI PR description is disabled!");
}
logo.classList.toggle("animate-spin");
const [diff, commitMessages] = await getDescriptionContext(url, descriptionConfig.config.source);

if (!diff && !commitMessages) {
logo.classList.toggle("animate-spin");
return alert(`No input context was generated.`);
}
if (isOutOfContextBounds([diff, commitMessages], descriptionConfig.config.maxInputLength)) {
logo.classList.toggle("animate-spin");
return alert(`Max input length exceeded. Try setting the description source to commit-messages.`);
}
const token = await getAuthToken();
const descriptionStream = await generateDescription(
token,
descriptionConfig.config.language,
descriptionConfig.config.length,
descriptionConfig.config.temperature / 10,
descriptionConfig.config.tone,
diff,
commitMessages,
);
const descriptionStream = await getAiDescription();

logo.classList.toggle("animate-spin");
if (!descriptionStream) {
return console.error("No description was generated!");
}

const textArea = document.getElementsByName(GITHUB_PR_COMMENT_TEXT_AREA_SELECTOR)[0] as HTMLTextAreaElement;

insertTextAtCursor(textArea, descriptionStream);
} catch (error: unknown) {
logo?.classList.toggle("animate-spin");

if (error instanceof Error) {
alert(error.message);
console.error("Description generation error:", error.message);
}
}
};

export const getAiDescription = async () => {
const url = getPullRequestAPIURL(window.location.href);
const descriptionConfig = await getAIDescriptionConfig();

if (!descriptionConfig) {
throw new Error("Configuration file is empty!");
}

if (!descriptionConfig.enabled) {
throw new Error("AI PR description is disabled!");
}

const [diff, commitMessages] = await getDescriptionContext(url, 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 descriptionStream = await generateDescription(
token,
descriptionConfig.config.language,
descriptionConfig.config.length,
descriptionConfig.config.temperature / 10,
descriptionConfig.config.tone,
diff,
commitMessages,
);

if (!descriptionStream) {
throw new Error("No description was generated!");
}

return descriptionStream;
};

Expand Up @@ -3,6 +3,7 @@ import { createHtmlElement } from "../../../utils/createHtmlElement";
import { getAuthToken } from "../../../utils/checkAuthentication";
import { getUserInsightsData, getRepoData, updateInsight } from "../../../utils/fetchOpenSaucedApiData";
import { IInsight } from "../../../ts/InsightDto";
import { OPEN_SAUCED_INSIGHTS_DOMAIN } from "../../../constants";

export const InsightsSelectDropdown = async (ownerName: string, repoName: string) => {
const insightsDropdown = createHtmlElement("div", {
Expand Down Expand Up @@ -105,7 +106,7 @@ export const InsightsSelectDropdown = async (ownerName: string, repoName: string

addInsightBtn.addEventListener("click", () => {
window.open(
"https://insights.opensauced.pizza/hub/insights/new",
`https://${OPEN_SAUCED_INSIGHTS_DOMAIN}/hub/insights/new`,
"_blank",
);
});
Expand Down
Expand Up @@ -3,6 +3,7 @@ import { createHtmlElement } from "../../../utils/createHtmlElement";
import emailSocialIcon from "../../../assets/mail-icon.svg";
import twitterSocialIcon from "../../../assets/twitter-icon.svg";
import linkedInSocailIcon from "../../../assets/linkedin-icon.svg";
import { OPEN_SAUCED_INSIGHTS_DOMAIN } from "../../../constants";

interface Socials {
emailAddress?: string | null;
Expand Down Expand Up @@ -76,7 +77,7 @@ export const InviteToOpenSaucedModal = (
className:
"mt-2 min-w-[33%] relative top-60 mx-auto p-4 border w-96 rounded-md shadow-button border-solid border-orange bg-slate-800",
innerHTML: `
<h3 class="text-2xl leading-6 font-bold text-white">Invite ${username} to <a href="https://insights.opensauced.pizza/start"><span class="hover:text-orange hover:underline">OpenSauced!</span></a></h3>
<h3 class="text-2xl leading-6 font-bold text-white">Invite ${username} to <a href="https://${OPEN_SAUCED_INSIGHTS_DOMAIN}/start"><span class="hover:text-orange hover:underline">OpenSauced!</span></a></h3>
<div class="mt-2">
<p class="text-md text-white">
Use the links below to invite them.
Expand Down
@@ -1,11 +1,12 @@
import logoIcon from "../../../assets/opensauced-icon.svg";
import "../../content-scripts.css";
import { createHtmlElement } from "../../../utils/createHtmlElement";
import { OPEN_SAUCED_INSIGHTS_DOMAIN } from "../../../constants";

export const ViewOnOpenSaucedButton = (username: string) => {
const viewOnOpenSaucedButton = createHtmlElement("a", {
id: "view-on-opensauced-button",
href: `https://insights.opensauced.pizza/user/${username}/contributions`,
href: `https://${OPEN_SAUCED_INSIGHTS_DOMAIN}/user/${username}/contributions`,
className:
"inline-block mt-4 text-black bg-gh-white dark:bg-gh-gray dark:text-white rounded-md p-2 text-sm font-semibold text-center select-none w-full border hover:shadow-button hover:no-underline",
target: "_blank",
Expand Down
25 changes: 25 additions & 0 deletions src/content-scripts/github.ts
Expand Up @@ -16,6 +16,7 @@ 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 { getAiDescription } from "./components/GenerateAIDescription/DescriptionGeneratorButton";

const processGithubPage = async () => {
if (prefersDarkMode(document.cookie)) {
Expand Down Expand Up @@ -55,3 +56,27 @@ const processGithubPage = async () => {
};

void processGithubPage();

chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
switch (msg.type) {
case "get_highlight": {
const title = (document.querySelector(".js-issue-title.markdown-title") as HTMLHeadingElement).innerText;

sendResponse(title);
break;
}
case "get_ai_description": {
const asyncRequest = async () => {
const aiText = await getAiDescription();

sendResponse(aiText);
};

asyncRequest().catch((e: Error | undefined) => {
sendResponse(e?.toString());
console.error(e);
});
return true;
}
}
});
13 changes: 13 additions & 0 deletions src/pages/help.tsx
Expand Up @@ -7,6 +7,7 @@ import {
} from "react-icons/hi2";
import { goBack } from "react-chrome-extension-router";
import { VscIssues } from "react-icons/vsc";
import { version } from "../../package.json";

const Help = () => (
<div className="p-4 bg-slate-800">
Expand All @@ -27,7 +28,19 @@ const Help = () => (
className="w-[100%]"
src={OpenSaucedLogo}
/>

</div>

<div className="flex justify-center flex-col">
<a
href={`https://github.com/open-sauced/ai/releases/tag/v${version}`}
rel="noreferrer"
target="_blank"
>
{version}
</a>
</div>

</header>

<main className="main-content text-white">
Expand Down

0 comments on commit c338075

Please sign in to comment.