diff --git a/core/context/providers/JiraIssuesContextProvider.ts b/core/context/providers/JiraIssuesContextProvider.ts new file mode 100644 index 000000000..a6cf4fc59 --- /dev/null +++ b/core/context/providers/JiraIssuesContextProvider.ts @@ -0,0 +1,136 @@ +import { BaseContextProvider } from ".."; +import { + ContextItem, + ContextProviderDescription, + ContextProviderExtras, + ContextSubmenuItem, + LoadSubmenuItemsArgs, +} from "../.."; +import type { AxiosInstance } from "axios"; + +interface JiraComment { + id: string; + created: string; + updated: string; + author: { + emailAddress: string; + displayName: string; + }; + body: object; +} + +interface JiraIssue { + id: string; + key: string; + fields: { + summary: string; + description: object; + comment: { + total: number; + comments: Array; + }; + }; +} + +interface QueryResults { + issues: JiraIssue[]; +} + +class JiraIssuesContextProvider extends BaseContextProvider { + static description: ContextProviderDescription = { + title: "jira", + displayTitle: "Jira Issues", + description: "Reference Jira issues", + type: "submenu", + }; + + private async createApi(): Promise { + const { default: Axios } = await import("axios"); + + return Axios.create({ + baseURL: `https://${this.options.domain}/rest/api/3/`, + auth: { + username: this.options.email, + password: this.options.token, + }, + }); + } + + async getContextItems( + query: string, + extras: ContextProviderExtras + ): Promise { + const issueId = query; + + const api = await this.createApi(); + + const issue = await api + .get(`/issue/${issueId}`, { + params: { + fields: "description,comment,summary", + }, + }) + .then((result) => result.data); + + // @ts-ignore + const adf2md = await import("adf2md/dist/adf2md.min.js"); + + const parts = [ + `# Jira Issue ${issue.key}: ${issue.fields.summary}`, + "## Description", + issue.fields.description + ? adf2md.convert(issue.fields.description).result + : "No description", + ]; + + if (issue.fields.comment.comments.length > 0) { + parts.push("## Comments"); + + parts.push( + ...issue.fields.comment.comments.map((comment) => { + const commentText = adf2md.convert(comment.body).result; + + return `### ${comment.author.displayName} on ${comment.created}\n\n${commentText}`; + }) + ); + } + + const content = parts.join("\n\n"); + + return [ + { + name: `${issue.key}: ${issue.fields.summary}`, + content, + description: issue.key, + }, + ]; + } + + async loadSubmenuItems( + args: LoadSubmenuItemsArgs + ): Promise { + const api = await this.createApi(); + + try { + const results = await api.get("/search", { + params: { + jql: + this.options.issueQuery ?? + `assignee = currentUser() AND resolution = Unresolved order by updated DESC`, + fields: "summary", + }, + }); + + return results.data.issues.map((issue) => ({ + id: issue.id, + title: `${issue.key}: ${issue.fields.summary}`, + description: "", + })); + } catch (ex) { + console.error(`Unable to get jira tickets: ${ex}`); + return []; + } + } +} + +export default JiraIssuesContextProvider; diff --git a/core/context/providers/index.ts b/core/context/providers/index.ts index e335a8363..2017e1738 100644 --- a/core/context/providers/index.ts +++ b/core/context/providers/index.ts @@ -15,6 +15,7 @@ import ProblemsContextProvider from "./ProblemsContextProvider"; import SearchContextProvider from "./SearchContextProvider"; import TerminalContextProvider from "./TerminalContextProvider"; import URLContextProvider from "./URLContextProvider"; +import JiraIssuesContextProvider from "./JiraIssuesContextProvider"; const Providers: (typeof BaseContextProvider)[] = [ DiffContextProvider, @@ -32,6 +33,7 @@ const Providers: (typeof BaseContextProvider)[] = [ DocsContextProvider, CodeHighlightsContextProvider, CodeOutlineContextProvider, + JiraIssuesContextProvider, ]; export function contextProviderClassFromName( diff --git a/core/index.d.ts b/core/index.d.ts index 6f1a47ee1..261081593 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -414,7 +414,8 @@ type ContextProviderName = | "http" | "codebase" | "problems" - | "folder"; + | "folder" + | "jira"; type TemplateType = | "llama2" diff --git a/core/package-lock.json b/core/package-lock.json index 6ea8b6f89..61bc32c9d 100644 --- a/core/package-lock.json +++ b/core/package-lock.json @@ -12,6 +12,8 @@ "@octokit/rest": "^20.0.2", "@types/node-fetch": "^2.6.11", "@xenova/transformers": "^2.14.0", + "adf2md": "^2.0.0", + "axios": "^1.6.7", "cheerio": "^1.0.0-rc.12", "dotenv": "^16.3.1", "fastest-levenshtein": "^1.0.16", @@ -2029,6 +2031,11 @@ "node": ">=6.5" } }, + "node_modules/adf2md": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/adf2md/-/adf2md-2.0.0.tgz", + "integrity": "sha512-QZvKkozgbIu3QfU1CtAEhAdgJ9h5q61pz6txOEqgjktjEsjer+EnFJ+Prhi+94+5Jl+50OD8eo7m/ardxYe00Q==" + }, "node_modules/agent-base": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", @@ -2188,9 +2195,9 @@ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "node_modules/axios": { - "version": "1.6.5", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.5.tgz", - "integrity": "sha512-Ii012v05KEVuUoFWmMW/UQv9aRIc3ZwkWDcM+h5Il8izZCtRVpDUfwpoFf7eOtajT3QiGR4yDUx7lPqHJULgbg==", + "version": "1.6.7", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.7.tgz", + "integrity": "sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA==", "dependencies": { "follow-redirects": "^1.15.4", "form-data": "^4.0.0", diff --git a/core/package.json b/core/package.json index ad5a07f81..15b1148f7 100644 --- a/core/package.json +++ b/core/package.json @@ -21,6 +21,8 @@ "@octokit/rest": "^20.0.2", "@types/node-fetch": "^2.6.11", "@xenova/transformers": "^2.14.0", + "adf2md": "^2.0.0", + "axios": "^1.6.7", "cheerio": "^1.0.0-rc.12", "dotenv": "^16.3.1", "fastest-levenshtein": "^1.0.16", diff --git a/core/yarn.lock b/core/yarn.lock index 295c042b7..dfbe639cb 100644 --- a/core/yarn.lock +++ b/core/yarn.lock @@ -321,10 +321,10 @@ resolved "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== -"@esbuild/darwin-arm64@0.19.11": +"@esbuild/linux-x64@0.19.11": version "0.19.11" - resolved "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.19.11.tgz" - integrity sha512-ETp87DRWuSt9KdDVkqSoKoLFHYTrkyz2+65fj9nfXsaV3bMhTCjtQfw3y+um88vGRKRiF7erPrh/ZuIdLUIVxQ== + resolved "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.19.11.tgz" + integrity sha512-grbyMlVCvJSfxFQUndw5mCtWs5LO1gUlwP4CDi4iJBbVpZcqLVT29FxgGuBJGSzyOxotFG4LoO5X+M1350zmPA== "@gar/promisify@^1.0.1": version "1.1.3" @@ -576,10 +576,10 @@ "@jridgewell/resolve-uri" "^3.1.0" "@jridgewell/sourcemap-codec" "^1.4.14" -"@lancedb/vectordb-darwin-arm64@0.4.3": +"@lancedb/vectordb-linux-x64-gnu@0.4.3": version "0.4.3" - resolved "https://registry.npmjs.org/@lancedb/vectordb-darwin-arm64/-/vectordb-darwin-arm64-0.4.3.tgz" - integrity sha512-47CvvSaV1EdUsFEpXUJApTk+hMzAhCxVizipCFUlXCgcmzpCDL86wNgJij/X9a+j6zADhIX//Lsu0qd/an/Bpw== + resolved "https://registry.npmjs.org/@lancedb/vectordb-linux-x64-gnu/-/vectordb-linux-x64-gnu-0.4.3.tgz" + integrity sha512-OBx3WF3pK0xNfFJeErmuD9R2QWLa3XdeZspyTsIrQmBDeKj3HKh8y7Scpx4NH5Y09+9JNqRRKRZN7OqWTYhITg== "@neon-rs/load@^0.0.74": version "0.0.74" @@ -967,6 +967,11 @@ abort-controller@^3.0.0: dependencies: event-target-shim "^5.0.0" +adf2md@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/adf2md/-/adf2md-2.0.0.tgz" + integrity sha512-QZvKkozgbIu3QfU1CtAEhAdgJ9h5q61pz6txOEqgjktjEsjer+EnFJ+Prhi+94+5Jl+50OD8eo7m/ardxYe00Q== + agent-base@^6.0.2, agent-base@6: version "6.0.2" resolved "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz" @@ -1079,10 +1084,10 @@ asynckit@^0.4.0: resolved "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz" integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q== -axios@^1.4.0, axios@^1.6.2: - version "1.6.5" - resolved "https://registry.npmjs.org/axios/-/axios-1.6.5.tgz" - integrity sha512-Ii012v05KEVuUoFWmMW/UQv9aRIc3ZwkWDcM+h5Il8izZCtRVpDUfwpoFf7eOtajT3QiGR4yDUx7lPqHJULgbg== +axios@^1.4.0, axios@^1.6.2, axios@^1.6.7: + version "1.6.7" + resolved "https://registry.npmjs.org/axios/-/axios-1.6.7.tgz" + integrity sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA== dependencies: follow-redirects "^1.15.4" form-data "^4.0.0" @@ -1918,11 +1923,6 @@ fs.realpath@^1.0.0: resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz" integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== -fsevents@^2.3.2: - version "2.3.3" - resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz" - integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw== - function-bind@^1.1.2: version "1.1.2" resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz" diff --git a/docs/docs/customization/context-providers.md b/docs/docs/customization/context-providers.md index d976eac8e..77c54fb97 100644 --- a/docs/docs/customization/context-providers.md +++ b/docs/docs/customization/context-providers.md @@ -112,6 +112,32 @@ Type '@issue' to reference the conversation in a GitHub issue. Make sure to incl } ``` +### Jira Issues + +Type '@jira' to reference the conversation in a Jira issue. Make sure to include your own [Atlassian API Token](https://id.atlassian.com/manage-profile/security/api-tokens). + +```json +{ + "name": "issue", + "params": { + "domain": "company.atlassian.net", + "email": "someone@somewhere.com", + "token ": "ATATT..." + } +} +``` + +#### Issue Query + +By default, the following query will be used to find issues: + +```jql +assignee = currentUser() AND resolution = Unresolved order by updated DESC +``` + +You can override this query by setting the `issueQuery` parameter. + + ### Code Outline Type '@outline' to reference the outline of all currently open files. The outline of a files consists of only the function and class definitions in the file. Supported file extensions are '.js', '.mjs', '.go', '.c', '.cc', '.cs', '.cpp', '.el', '.ex', '.elm', '.java', '.ml', '.php', '.ql', '.rb', '.rs', '.ts' diff --git a/docs/static/schemas/config.json b/docs/static/schemas/config.json index b82858588..81aaade3f 100644 --- a/docs/static/schemas/config.json +++ b/docs/static/schemas/config.json @@ -1121,6 +1121,41 @@ "required": ["params"] } }, + { + "if": { + "properties": { + "name": { + "enum": ["jira"] + } + } + }, + "then": { + "properties": { + "params": { + "properties": { + "domain": { + "type": "string", + "description": "Your Jira domain, for example company.atlassian.net." + }, + "email": { + "type": "string", + "description": "The email that you log into Jira with" + }, + "token": { + "type": "string", + "description": "Your atlassian API token from https://id.atlassian.com/manage-profile/security/api-tokens" + }, + "issueQuery": { + "type": "string", + "description": "Customize the query used to find Jira issues" + } + }, + "required": ["domain", "email", "token"] + } + }, + "required": ["params"] + } + }, { "if": { "properties": { diff --git a/extensions/vscode/config_schema.json b/extensions/vscode/config_schema.json index 4c29894b7..0f68ebbb0 100644 --- a/extensions/vscode/config_schema.json +++ b/extensions/vscode/config_schema.json @@ -76,8 +76,15 @@ "title": "Ca Bundle Path", "description": "Path to a custom CA bundle to use when making the HTTP request", "anyOf": [ - { "type": "string" }, - { "type": "array", "items": { "type": "string" } } + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } ] }, "proxy": { @@ -376,7 +383,9 @@ "llama2-13b" ] }, - { "type": "string" } + { + "type": "string" + } ] }, "markdownDescription": "Select a pre-defined option, or find an exact model ID from Replicate [here](https://replicate.com/collections/streaming-language-models)." @@ -462,7 +471,9 @@ "AUTODETECT" ] }, - { "type": "string" } + { + "type": "string" + } ] } } @@ -481,8 +492,12 @@ "properties": { "model": { "anyOf": [ - { "enum": ["claude-2", "claude-instant-1"] }, - { "type": "string" } + { + "enum": ["claude-2", "claude-instant-1"] + }, + { + "type": "string" + } ] } } @@ -531,7 +546,9 @@ "phind-codellama-34b" ] }, - { "type": "string" } + { + "type": "string" + } ], "markdownDescription": "Select a pre-defined option, or find an exact model string from Together AI [here](https://docs.together.ai/docs/inference-models)." } @@ -599,7 +616,9 @@ "starcoder-3b" ] }, - { "type": "string" } + { + "type": "string" + } ] } } @@ -644,7 +663,9 @@ "AUTODETECT" ] }, - { "type": "string" } + { + "type": "string" + } ], "markdownDescription": "Select a pre-defined option, or find the exact model tag for an Ollama model [here](https://ollama.ai/library)." } @@ -827,7 +848,9 @@ "starcoder-3b" ] }, - { "type": "string" } + { + "type": "string" + } ] } } @@ -892,7 +915,9 @@ "Generate a commit message for the current changes" ] }, - { "type": "string" } + { + "type": "string" + } ] }, "description": { @@ -1025,7 +1050,9 @@ ], "type": "string" }, - { "type": "string" } + { + "type": "string" + } ] }, "params": { @@ -1126,6 +1153,41 @@ "required": ["params"] } }, + { + "if": { + "properties": { + "name": { + "enum": ["jira"] + } + } + }, + "then": { + "properties": { + "params": { + "properties": { + "domain": { + "type": "string", + "description": "Your Jira domain, for example company.atlassian.net." + }, + "email": { + "type": "string", + "description": "The email that you log into Jira with" + }, + "token": { + "type": "string", + "description": "Your atlassian API token from https://id.atlassian.com/manage-profile/security/api-tokens" + }, + "issueQuery": { + "type": "string", + "description": "Customize the query used to find Jira issues" + } + }, + "required": ["domain", "email", "token"] + } + }, + "required": ["params"] + } + }, { "if": { "properties": { diff --git a/extensions/vscode/continue_rc_schema.json b/extensions/vscode/continue_rc_schema.json index 7f5146d5b..93474b544 100644 --- a/extensions/vscode/continue_rc_schema.json +++ b/extensions/vscode/continue_rc_schema.json @@ -1287,6 +1287,49 @@ ] } }, + { + "if": { + "properties": { + "name": { + "enum": [ + "jira" + ] + } + } + }, + "then": { + "properties": { + "params": { + "properties": { + "domain": { + "type": "string", + "description": "Your Jira domain, for example company.atlassian.net." + }, + "email": { + "type": "string", + "description": "The email that you log into Jira with" + }, + "token": { + "type": "string", + "description": "Your atlassian API token from https://id.atlassian.com/manage-profile/security/api-tokens" + }, + "issueQuery": { + "type": "string", + "description": "Customize the query used to find Jira issues" + } + }, + "required": [ + "domain", + "email", + "token" + ] + } + }, + "required": [ + "params" + ] + } + }, { "if": { "properties": { diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 31a0096fc..91d58aff4 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -88,6 +88,8 @@ "@octokit/rest": "^20.0.2", "@types/node-fetch": "^2.6.11", "@xenova/transformers": "^2.14.0", + "adf2md": "^2.0.0", + "axios": "^1.6.7", "cheerio": "^1.0.0-rc.12", "dotenv": "^16.3.1", "fastest-levenshtein": "^1.0.16", diff --git a/extensions/vscode/yarn.lock b/extensions/vscode/yarn.lock index 0e7c5a885..6ff138bc3 100644 --- a/extensions/vscode/yarn.lock +++ b/extensions/vscode/yarn.lock @@ -368,15 +368,15 @@ tar "^6.0.5" yargs "^17.0.1" -"@esbuild/darwin-arm64@0.17.19": +"@esbuild/linux-x64@0.17.19": version "0.17.19" - resolved "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.17.19.tgz" - integrity sha512-80wEoCfF/hFKM6WE1FyBHc9SfUblloAWx6FJkFWTWiCoht9Mc0ARGEM47e67W9rI09YoUxJL68WHfDRYEAvOhg== + resolved "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.17.19.tgz" + integrity sha512-68ngA9lg2H6zkZcyp22tsVt38mlhWde8l3eJLWkyLrp4HwMUr3c1s/M2t7+kHIhvMjglIBrFpncX1SzMckomGw== -"@esbuild/darwin-arm64@0.18.20": +"@esbuild/linux-x64@0.18.20": version "0.18.20" - resolved "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.18.20.tgz" - integrity sha512-bxRHW5kHU38zS2lPTPOyuyTm+S+eobPUnTNkdJEfAddYgEcll4xkT8DB9d2008DtTbl7uJag2HuE5NZAZgnNEA== + resolved "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.18.20.tgz" + integrity sha512-UYqiqemphJcNsFEskc73jQ7B9jgwjWrSayxawS6UVFZGWrAAtkzjxSqnoclCXxWtfwLdzU+vTpcNYhpn43uP1w== "@eslint-community/eslint-utils@^4.2.0": version "4.4.0" @@ -2315,6 +2315,8 @@ core-util-is@1.0.2: "@octokit/rest" "^20.0.2" "@types/node-fetch" "^2.6.11" "@xenova/transformers" "^2.14.0" + adf2md "^2.0.0" + axios "^1.6.7" cheerio "^1.0.0-rc.12" dotenv "^16.3.1" fastest-levenshtein "^1.0.16" @@ -3348,11 +3350,6 @@ fs.realpath@^1.0.0: resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz" integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== -fsevents@^2.3.2, fsevents@~2.3.2: - version "2.3.3" - resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz" - integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw== - function-bind@^1.1.2: version "1.1.2" resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz" diff --git a/gui/package-lock.json b/gui/package-lock.json index f1f681629..4449f7aba 100644 --- a/gui/package-lock.json +++ b/gui/package-lock.json @@ -76,6 +76,8 @@ "@octokit/rest": "^20.0.2", "@types/node-fetch": "^2.6.11", "@xenova/transformers": "^2.14.0", + "adf2md": "^2.0.0", + "axios": "^1.6.7", "cheerio": "^1.0.0-rc.12", "dotenv": "^16.3.1", "fastest-levenshtein": "^1.0.16",