| 1 | import { |
| 2 | ContextItem, |
| 3 | ContextProviderDescription, |
| 4 | ContextProviderExtras, |
| 5 | ContextSubmenuItem, |
| 6 | LoadSubmenuItemsArgs, |
| 7 | } from "../../index.js"; |
| 8 | import { BaseContextProvider } from "../index.js"; |
| 9 | |
| 10 | class GitHubIssuesContextProvider extends BaseContextProvider { |
| 11 | static description: ContextProviderDescription = { |
| 12 | title: "issue", |
| 13 | displayTitle: "GitHub Issues", |
| 14 | description: "Reference GitHub issues", |
| 15 | type: "submenu", |
| 16 | }; |
| 17 | |
| 18 | get deprecationMessage() { |
| 19 | return "The GitHub issues context provider is now deprecated and will be removed in a later version. Please consider using the GitHub MCP server (https://hub.continue.dev/anthropic/github-mcp) instead."; |
| 20 | } |
| 21 | |
| 22 | async getContextItems( |
| 23 | query: string, |
| 24 | extras: ContextProviderExtras, |
| 25 | ): Promise<ContextItem[]> { |
| 26 | const issueId = query; |
| 27 | const { Octokit } = await import("@octokit/rest"); |
| 28 | |
| 29 | const octokit = new Octokit({ |
| 30 | auth: this.options?.githubToken, |
| 31 | baseUrl: this.options?.domain |
| 32 | ? `https://${this.options.domain}/api/v3` |
| 33 | : undefined, |
| 34 | request: { |
| 35 | fetch: extras.fetch, |
| 36 | }, |
| 37 | }); |
| 38 | |
| 39 | const { owner, repo, issue_number } = JSON.parse(issueId); |
| 40 | |
| 41 | const issue = await octokit.issues.get({ |
| 42 | owner, |
| 43 | repo, |
| 44 | issue_number, |
| 45 | }); |
| 46 | |
| 47 | let content = `# GitHub Issue #${issue.data.number.toString()} in ${owner}/${repo}`; |
| 48 | |
| 49 | const comments = await octokit.issues.listComments({ |
| 50 | owner, |
| 51 | repo, |
| 52 | issue_number, |
| 53 | }); |
| 54 | |
| 55 | const parts = [ |
| 56 | issue.data.body || "No description", |
| 57 | ...comments.data.map((comment) => comment.body), |
| 58 | ]; |
| 59 | content += `\n\n${parts.join("\n\n---\n\n")}`; |
| 60 | |
| 61 | return [ |
| 62 | { |
| 63 | name: issue.data.title, |
| 64 | content, |
| 65 | description: `#${issue.data.number.toString()}`, |
| 66 | }, |
| 67 | ]; |
| 68 | } |
| 69 | |
| 70 | async loadSubmenuItems( |
| 71 | args: LoadSubmenuItemsArgs, |
| 72 | ): Promise<ContextSubmenuItem[]> { |
| 73 | const { Octokit } = await import("@octokit/rest"); |
| 74 | |
| 75 | const octokit = new Octokit({ |
| 76 | auth: this.options?.githubToken, |
| 77 | request: { |
| 78 | fetch: args.fetch, |
| 79 | }, |
| 80 | }); |
| 81 | |
| 82 | const allIssues = []; |
| 83 | |
| 84 | for (const repo of this.options?.repos) { |
| 85 | const issues = await octokit.issues.listForRepo({ |
| 86 | owner: repo.owner, |
| 87 | repo: repo.repo, |
| 88 | state: repo.type || "open", |
| 89 | }); |
| 90 | allIssues.push( |
| 91 | ...issues.data.map((issue) => ({ |
| 92 | title: issue.title, |
| 93 | description: `#${issue.number.toString()}`, |
| 94 | id: JSON.stringify({ |
| 95 | owner: repo.owner, |
| 96 | repo: repo.repo, |
| 97 | issue_number: issue.number, |
| 98 | }), |
| 99 | })), |
| 100 | ); |
| 101 | } |
| 102 | |
| 103 | return allIssues; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | export default GitHubIssuesContextProvider; |