Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: oss-gpt with the new loading mechanism #639

Merged
merged 5 commits into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ You can find these dashboards in:
- **Developer's Most Participated Repos**: Developer's Most Participated Repos shows the active projects of developers in a given time period. From this graph you can find out the most active repositories for a given developer.
- **Developer's Activity & OpenRank Trend**:The Developer Activity and OpenRank Trend chart presents how the two metrics evolve since 2015. In the chart, you can zoom and drag using your mouse or touchpad, and you can toggle either of the data by clicking the legend buttons as well.

## OSS-GPT

OSS-GPT is an open source project document answering robot integrated with [DocsGPT](https://github.com/arc53/docsgpt) capabilities. For an already supported project, simply open the corresponding project repository home page and ask any questions you have about that repository. You can get OSS-GPT support for your open source projects through [issue#609](https://github.com/hypertrons/hypertrons-crx/issues/609).
<img
src="https://user-images.githubusercontent.com/104072573/228414906-9c219b36-8872-41a1-b681-91f7d8d74a63.png"
/>

## Contributing

Please read [CONTRIBUTING](./CONTRIBUTING.md) if you are new here or not familiar with the basic rules of Git/GitHub world.
Expand Down
8 changes: 8 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ Language : [English](./README.md) | 中文
- **活跃仓库网络图**: 活跃仓库网络图展示了在给定的时间段内,开发者的活跃项目,***用于开发者行为的追踪与挖掘***。从该网络图中,可以找出该开发者在哪些项目中活跃。
- **开发者活跃度&OpenRank趋势图**:开发者活跃度和OpenRank趋势图显示了项目成立至今的活跃度和OpenRank这两个指标的变化。您可以利用鼠标或触控板在图表内缩放和拖拽,此外,您还可以点击Legend按钮来控制图例的显示和隐藏。

## OSS-GPT

OSS-GPT是集成了[DocsGPT](https://github.com/arc53/docsgpt)能力的开源项目文档问答机器人。对已经支持的项目,只需打开对应的项目仓库主页,即可询问有关于该仓库的任何问题。你可以通过[issue#609](https://github.com/hypertrons/hypertrons-crx/issues/609)以使你的开源项目获得OSS-GPT的支持。

<img
src="https://user-images.githubusercontent.com/104072573/228415232-cc81eab2-5566-4775-bf27-c385881deb20.png"
/>

## 参与贡献

如果你初来乍到或对 Git/GitHub 的基本操作不熟悉,请阅读[CONTRIBUTING](./CONTRIBUTING.md)。
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hypercrx",
"version": "1.8.4",
"version": "1.8.8",
"type": "module",
"private": true,
"description": "Hypertrons Chromium Extension",
Expand Down Expand Up @@ -33,6 +33,7 @@
"jquery": "^3.6.0",
"office-ui-fabric-react": "^7.183.0",
"react": "^17.0.2",
"react-chat-widget": "^3.1.4",
"react-dom": "^17.0.2",
"react-hot-loader": "^4.13.0",
"react-modal": "3.15.1",
Expand Down
6 changes: 3 additions & 3 deletions publish/update_information.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"chrome": {
"latest_version": "1.8.4",
"latest_version": "1.8.8",
"url": "https://chrome.google.com/webstore/detail/hypercrx/ijchfbpdgeljmhnhokmekkecpbdkgabc"
},
"edge": {
"latest_version": "1.8.4",
"latest_version": "1.8.8",
"url": "https://microsoftedge.microsoft.com/addons/detail/hypercrx/lbbajaehiibofpconjgdjonmkidpcome"
},
"develop": {
"latest_version": "1.8.4",
"latest_version": "1.8.8",
"url": "https://github.com/hypertrons/hypertrons-crx/releases"
}
}
15 changes: 15 additions & 0 deletions src/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -316,5 +316,20 @@
},
"merged_lines_popup_title": {
"message": "Merged Addition & Deletion Code Lines"
},
"docs_gpt_chat_widget": {
"message": "OSS-GPT Chat Bot"
},
"OSS_GPT_subtitle": {
"message": "Ask anything about %v"
},
"OSS_GPT_subtitle_notAvailable": {
"message": "NOT AVAILABLE for %v"
},
"OSS_GPT_welcome": {
"message": "Hi, I'm an assistant powered by [DocsGPT](https://github.com/arc53/docsgpt) and [X-lab](https://github.com/X-lab2017). Ask me anything about %v!"
},
"OSS_GPT_notAvailable": {
"message": "OSS-GPT currently is **NOT AVAILABLE** for %v. If you want docs support for the repository, please check [this issue](https://github.com/hypertrons/hypertrons-crx/issues/609) and make a request there :)\n\nSee [all available docs](https://oss.x-lab.info/hypercrx/docsgpt_active_docs.json)\n\nThis chat widget can also be enabled/disabled in the extension options page whenever you want."
}
}
15 changes: 15 additions & 0 deletions src/locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -316,5 +316,20 @@
},
"merged_lines_popup_title": {
"message": "通过 PR 合入增加和删除的代码行数"
},
"docs_gpt_chat_widget": {
"message": "OSS-GPT 聊天机器人"
},
"OSS_GPT_subtitle": {
"message": "询问任何有关 %v 的问题"
},
"OSS_GPT_subtitle_notAvailable": {
"message": "暂未支持 %v "
},
"OSS_GPT_welcome": {
"message": "您好,我是一个由 [DocsGPT](https://github.com/arc53/docsgpt) 和 [X-lab](https://github.com/X-lab2017) 提供支持的开源项目文档问答机器人。您可以向我询问有关 %v 的任何问题!"
},
"OSS_GPT_notAvailable": {
"message": "OSS-GPT 暂未支持 %v。如果您想使此仓库得到文档问答支持,请前往[该 issue](https://github.com/hypertrons/hypertrons-crx/issues/609) 提交需求 :)\n\n查看[所有已支持文档](https://oss.x-lab.info/hypercrx/docsgpt_active_docs.json)\n\n您也可以随时在扩展选项页面中启用/禁用此聊天小部件。"
}
}
6 changes: 3 additions & 3 deletions src/mock/background.data.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
export const updateInformation = {
chrome: {
latest_version: '1.8.4',
latest_version: '1.8.8',
url: 'https://github.com/hypertrons/hypertrons-crx/releases',
},
edge: {
latest_version: '1.8.4',
latest_version: '1.8.8',
url: 'https://github.com/hypertrons/hypertrons-crx/releases',
},
develop: {
latest_version: '1.8.4',
latest_version: '1.8.8',
url: 'https://github.com/hypertrons/hypertrons-crx/releases',
},
};
Expand Down
84 changes: 84 additions & 0 deletions src/pages/ContentScripts/features/oss-gpt/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import React from 'react';
import { render, Container } from 'react-dom';
import $ from 'jquery';

import features from '../../../../feature-manager';
import { isPublicRepo, getGithubTheme } from '../../../../utils/utils';
import { getRepoName } from '../../../../helpers/get-repo-info';
import View from './view';

interface DocsMetaItem {
type: 'repo' | 'org';
name: string; // GitHub repo name or org name
key: string; // corresponding docs name
}

const DOCS_META_DATA_URL =
'https://oss.x-lab.info/hypercrx/docsgpt_active_docs.json';
const featureId = features.getFeatureID(import.meta.url);
let repoName: string;
let docsMetaData: DocsMetaItem[];

const getData = async () => {
const response = await fetch(DOCS_META_DATA_URL);
if (response.ok) {
docsMetaData = await response.json();
} else {
throw new Error('Failed to fetch docs meta data');
}
};

const getCurrentDocsName = (repoName: string): string | null => {
const orgName = repoName.split('/')[0];
let result = null;
for (const item of docsMetaData) {
if (item.type === 'repo' && item.name === repoName) {
result = item.key;
break;
} else if (item.type === 'org' && item.name === orgName) {
result = item.key;
break;
}
}
return result;
};

const renderTo = (container: Container) => {
render(
<View
theme={getGithubTheme() as 'light' | 'dark'}
currentRepo={repoName}
currentDocsName={getCurrentDocsName(repoName)}
/>,
container
);
};

const init = async (): Promise<void> => {
repoName = getRepoName();
await getData();

const container = document.createElement('div');
container.id = featureId;
container.dataset.repo = repoName; // mark current repo by data-repo
renderTo(container);
$('body').append(container);

// TODO need a mechanism to remove extra listeners like this one
document.addEventListener('turbo:load', async () => {
if (await isPublicRepo()) {
if (repoName !== getRepoName()) {
repoName = getRepoName();
renderTo($(`#${featureId}`)[0]);
}
} else {
$(`#${featureId}`).remove();
}
});
};

features.add(featureId, {
include: [isPublicRepo],
awaitDomReady: false,
init,
});
Loading