✨ GitHub Issues Context Provider
This commit is contained in:
parent
e13412f1ad
commit
33eb24cb37
7 changed files with 92 additions and 19 deletions
|
|
@ -9,7 +9,7 @@ import {
|
|||
|
||||
class GitHubIssuesContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
title: "github",
|
||||
title: "issue",
|
||||
displayTitle: "GitHub Issues",
|
||||
description: "Reference GitHub issues",
|
||||
type: "submenu",
|
||||
|
|
@ -19,13 +19,75 @@ class GitHubIssuesContextProvider extends BaseContextProvider {
|
|||
query: string,
|
||||
extras: ContextProviderExtras
|
||||
): Promise<ContextItem[]> {
|
||||
return [];
|
||||
const issueId = query;
|
||||
const { Octokit } = await import("@octokit/rest");
|
||||
|
||||
const octokit = new Octokit({
|
||||
auth: this.options?.githubToken,
|
||||
});
|
||||
|
||||
const { owner, repo, issue_number } = JSON.parse(issueId);
|
||||
|
||||
const issue = await octokit.issues.get({
|
||||
owner,
|
||||
repo,
|
||||
issue_number,
|
||||
});
|
||||
|
||||
let content = `# GitHub Issue #${issue.data.number.toString()} in ${owner}/${repo}`;
|
||||
|
||||
const comments = await octokit.issues.listComments({
|
||||
owner,
|
||||
repo,
|
||||
issue_number,
|
||||
});
|
||||
|
||||
const parts = [
|
||||
issue.data.body || "No description",
|
||||
...comments.data.map((comment) => comment.body),
|
||||
];
|
||||
content += "\n\n" + parts.join("\n\n---\n\n");
|
||||
|
||||
return [
|
||||
{
|
||||
name: issue.data.title,
|
||||
content,
|
||||
description: `#${issue.data.number.toString()}`,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
async loadSubmenuItems(
|
||||
args: LoadSubmenuItemsArgs
|
||||
): Promise<ContextSubmenuItem[]> {
|
||||
return [];
|
||||
const { Octokit } = await import("@octokit/rest");
|
||||
|
||||
const octokit = new Octokit({
|
||||
auth: this.options?.githubToken,
|
||||
});
|
||||
|
||||
const allIssues = [];
|
||||
|
||||
for (const repo of this.options?.repos) {
|
||||
const issues = await octokit.issues.listForRepo({
|
||||
owner: repo.owner,
|
||||
repo: repo.repo,
|
||||
state: repo.type || "open",
|
||||
});
|
||||
allIssues.push(
|
||||
...issues.data.map((issue) => ({
|
||||
title: issue.title,
|
||||
description: `#${issue.number.toString()}`,
|
||||
id: JSON.stringify({
|
||||
owner: repo.owner,
|
||||
repo: repo.repo,
|
||||
issue_number: issue.number,
|
||||
}),
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
return allIssues;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -82,17 +82,21 @@ Type '@google' to reference the results of a Google search. For example, type "@
|
|||
|
||||
Note: You can get an API key for free at [serper.dev](https://serper.dev).
|
||||
|
||||
### GitHub
|
||||
### GitHub Issues
|
||||
|
||||
Type '@issue' to reference the title and contents of a GitHub issue.
|
||||
Type '@issue' to reference the conversation inside of a GitHub issue.
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "github",
|
||||
"name": "issue",
|
||||
"params": {
|
||||
// Change to whichever repo you want to use
|
||||
"repoName": "continuedev/continue",
|
||||
"authToken": "<my_github_auth_token>"
|
||||
"repos": [
|
||||
{
|
||||
"owner": "continuedev",
|
||||
"repo": "continue"
|
||||
}
|
||||
],
|
||||
"githubToken": "<my_github_auth_token>"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
|
|||
|
|
@ -1045,13 +1045,13 @@
|
|||
"type": "string",
|
||||
"description": "The type of issues to search for",
|
||||
"enum": ["open", "closed", "all"]
|
||||
},
|
||||
"required": ["owner", "repo"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["owner", "repo"]
|
||||
}
|
||||
},
|
||||
"required": ["repos"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["repos"]
|
||||
}
|
||||
},
|
||||
"required": ["params"]
|
||||
|
|
|
|||
1
extensions/vscode/package-lock.json
generated
1
extensions/vscode/package-lock.json
generated
|
|
@ -77,6 +77,7 @@
|
|||
"version": "1.0.0",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@octokit/rest": "^20.0.2",
|
||||
"@xenova/transformers": "^2.14.0",
|
||||
"cheerio": "^1.0.0-rc.12",
|
||||
"dotenv": "^16.3.1",
|
||||
|
|
|
|||
|
|
@ -2268,6 +2268,7 @@ core-util-is@~1.0.0, core-util-is@1.0.2:
|
|||
version "1.0.0"
|
||||
resolved "file:../../core"
|
||||
dependencies:
|
||||
"@octokit/rest" "^20.0.2"
|
||||
"@xenova/transformers" "^2.14.0"
|
||||
cheerio "^1.0.0-rc.12"
|
||||
dotenv "^16.3.1"
|
||||
|
|
|
|||
2
gui/package-lock.json
generated
2
gui/package-lock.json
generated
|
|
@ -65,6 +65,7 @@
|
|||
"version": "1.0.0",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@octokit/rest": "^20.0.2",
|
||||
"@xenova/transformers": "^2.14.0",
|
||||
"cheerio": "^1.0.0-rc.12",
|
||||
"dotenv": "^16.3.1",
|
||||
|
|
@ -7435,6 +7436,7 @@
|
|||
"core": {
|
||||
"version": "file:../core",
|
||||
"requires": {
|
||||
"@octokit/rest": "^20.0.2",
|
||||
"@types/handlebars": "^4.1.0",
|
||||
"@types/jest": "^29.5.11",
|
||||
"@types/jquery": "^3.5.29",
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ const ICONS_FOR_DROPDOWN: { [key: string]: any } = {
|
|||
problems: ExclamationTriangleIcon,
|
||||
folder: FolderIcon,
|
||||
docs: BookOpenIcon,
|
||||
issue: ExclamationCircleIcon,
|
||||
"/edit": PaintBrushIcon,
|
||||
"/clear": TrashIcon,
|
||||
"/test": BeakerIcon,
|
||||
|
|
@ -74,18 +75,19 @@ function DropdownIcon(props: {
|
|||
type: ComboBoxItemType;
|
||||
}) {
|
||||
const Icon = ICONS_FOR_DROPDOWN[props.provider];
|
||||
const iconClass = `${props.className} flex-shrink-0`;
|
||||
if (!Icon) {
|
||||
return props.type === "contextProvider" ? (
|
||||
<AtSymbolIcon className={props.className} height="1.2em" width="1.2em" />
|
||||
<AtSymbolIcon className={iconClass} height="1.2em" width="1.2em" />
|
||||
) : (
|
||||
<ChevronDoubleRightIcon
|
||||
className={props.className}
|
||||
className={iconClass}
|
||||
height="1.2em"
|
||||
width="1.2em"
|
||||
/>
|
||||
);
|
||||
}
|
||||
return <Icon className={props.className} height="1.2em" width="1.2em" />;
|
||||
return <Icon className={iconClass} height="1.2em" width="1.2em" />;
|
||||
}
|
||||
|
||||
const ItemsDiv = styled.div`
|
||||
|
|
@ -339,6 +341,7 @@ const MentionList = forwardRef((props: MentionListProps, ref) => {
|
|||
float: "right",
|
||||
textAlign: "right",
|
||||
opacity: index !== selectedIndex ? 0 : 1,
|
||||
minWidth: "30px",
|
||||
}}
|
||||
className="whitespace-nowrap overflow-hidden overflow-ellipsis ml-2 flex items-center"
|
||||
>
|
||||
|
|
@ -346,7 +349,7 @@ const MentionList = forwardRef((props: MentionListProps, ref) => {
|
|||
{item.type === "contextProvider" &&
|
||||
item.contextProvider?.type === "submenu" && (
|
||||
<ArrowRightIcon
|
||||
className="ml-2"
|
||||
className="ml-2 flex-shrink-0"
|
||||
width="1.2em"
|
||||
height="1.2em"
|
||||
/>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue