Elffuss BraidHub

kikocis/continue public

main · 2.3 KiBRawPermalink
1import {
2 ContextItem,
3 ContextProviderDescription,
4 ContextProviderExtras,
5 ContextSubmenuItem,
6 LoadSubmenuItemsArgs,
7} from "../../../index.js";
8import { BaseContextProvider } from "../../index.js";
9
10import { JiraClient } from "./JiraClient.js";
11
12class JiraIssuesContextProvider extends BaseContextProvider {
13 static description: ContextProviderDescription = {
14 title: "jira",
15 displayTitle: "Jira Issues",
16 description: "Reference Jira issues",
17 type: "submenu",
18 };
19
20 get deprecationMessage() {
21 return "The Jira issues context provider is now deprecated and will be removed in a later version. Please consider using the official Atlassian MCP server atlassian.com/platform/remote-mcp-server.";
22 }
23
24 private getApi() {
25 return new JiraClient({
26 domain: this.options.domain,
27 username: this.options.email,
28 password: this.options.token,
29 issueQuery: this.options.issueQuery,
30 apiVersion: this.options.apiVersion,
31 requestOptions: this.options.requestOptions,
32 maxResults: this.options.maxResults,
33 });
34 }
35
36 async getContextItems(
37 query: string,
38 extras: ContextProviderExtras,
39 ): Promise<ContextItem[]> {
40 const api = this.getApi();
41 const issue = await api.issue(query, extras.fetch);
42
43 const parts = [
44 `# Jira Issue ${issue.key}: ${issue.summary}`,
45 "## Description",
46 issue.description ?? "No description",
47 ];
48
49 if (issue.comments.length > 0) {
50 parts.push("## Comments");
51
52 parts.push(
53 ...issue.comments.map((comment) => {
54 return `### ${comment.author.displayName} on ${comment.created}\n\n${comment.body}`;
55 }),
56 );
57 }
58
59 const content = parts.join("\n\n");
60
61 return [
62 {
63 name: `${issue.key}: ${issue.summary}`,
64 content,
65 description: issue.key,
66 },
67 ];
68 }
69
70 async loadSubmenuItems(
71 args: LoadSubmenuItemsArgs,
72 ): Promise<ContextSubmenuItem[]> {
73 const api = await this.getApi();
74
75 try {
76 const issues = await api.listIssues(args.fetch);
77
78 return issues.map((issue) => ({
79 id: issue.id,
80 title: `${issue.key}: ${issue.summary}`,
81 description: "",
82 }));
83 } catch (ex) {
84 console.error(`Unable to get jira tickets: ${ex}`);
85 return [];
86 }
87 }
88}
89
90export default JiraIssuesContextProvider;