Skip to content

Commit

Permalink
protocol: add meta.mentions.label (#152)
Browse files Browse the repository at this point in the history
The intention behind this field is this is the placeholder label that is
shown when a user selects a provider for mentioning, but before they
have searched anything.

Part of
https://linear.app/sourcegraph/issue/CODY-2275/add-all-the-right-labels-for-provider-mentions-query-stats
  • Loading branch information
keegancsmith authored Jun 18, 2024
1 parent 6e30381 commit ba1d9e6
Show file tree
Hide file tree
Showing 27 changed files with 100 additions and 47 deletions.
2 changes: 1 addition & 1 deletion lib/protocol/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openctx/protocol",
"version": "0.0.13",
"version": "0.0.14",
"description": "OpenCtx client/provider protocol",
"license": "Apache-2.0",
"repository": {
Expand Down
4 changes: 4 additions & 0 deletions lib/protocol/src/openctx-protocol.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@
"type": "object",
"additionalProperties": false,
"properties": {
"label": {
"description": "The label that is shown when a user wants to query mentions. For example `Search...` or `Paste Linear URL`.",
"type": "string"
},
"selectors": {
"description": "The list of regex patterns for triggering mentions for the provider when users directly types a matching text, for example a url, allowing the user to bypass choosing the provider manually.",
"type": "array",
Expand Down
4 changes: 4 additions & 0 deletions lib/protocol/src/openctx-protocol.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export interface MetaResult {
* Configuration for the mentions feature.
*/
mentions?: {
/**
* The label that is shown when a user wants to query mentions. For example `Search...` or `Paste Linear URL`.
*/
label?: string
/**
* The list of regex patterns for triggering mentions for the provider when users directly types a matching text, for example a url, allowing the user to bypass choosing the provider manually.
*/
Expand Down
5 changes: 4 additions & 1 deletion provider/azure-devops-workitems/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ const wiToItem = (workItem: SimpleWorkItem): Item => ({

const azureDevOps: Provider = {
meta(): MetaResult {
return { name: 'Azure DevOps Work Items', mentions: {} }
return {
name: 'Azure DevOps Work Items',
mentions: { label: 'Search by title, description or id...' },
}
},

async mentions(params: MentionsParams, settings: Settings): Promise<MentionsResult> {
Expand Down
2 changes: 1 addition & 1 deletion provider/azure-devops-workitems/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@openctx/provider-azure-devops-workitems",
"private": false,
"version": "0.0.1",
"version": "0.0.2",
"description": "Azure DevOps Work Items (OpenCtx provider)",
"license": "Apache-2.0",
"homepage": "https://openctx.org/docs/providers/azure-devops-workitems",
Expand Down
2 changes: 1 addition & 1 deletion provider/confluence/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const checkSettings = (settings: Settings) => {

const confluenceProvider: Provider = {
meta(params: MetaParams, settings: Settings): MetaResult {
return { name: 'Confluence Pages', mentions: {} }
return { name: 'Confluence Pages', mentions: { label: 'Search by page title...' } }
},

async mentions(params: MentionsParams, settings: Settings): Promise<MentionsResult> {
Expand Down
8 changes: 5 additions & 3 deletions provider/confluence/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@openctx/provider-confluence",
"private": false,
"version": "0.0.2",
"version": "0.0.3",
"description": "Confluence (OpenCtx provider)",
"license": "Apache-2.0",
"homepage": "https://openctx.org/docs/providers/confluence",
Expand All @@ -13,7 +13,10 @@
"type": "module",
"main": "dist/bundle.js",
"types": "dist/index.d.ts",
"files": ["dist/bundle.js", "dist/index.d.ts"],
"files": [
"dist/bundle.js",
"dist/index.d.ts"
],
"sideEffects": false,
"scripts": {
"bundle": "tsc --build && esbuild --log-level=error --bundle --format=esm --outfile=dist/bundle.js index.ts",
Expand All @@ -24,4 +27,3 @@
"@openctx/provider": "workspace:*"
}
}

47 changes: 47 additions & 0 deletions provider/devdocs/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,53 @@ import devdocs, { type Settings } from './index.js'
const INTEGRATION = !!process.env.INTEGRATION

describe('devdocs', () => {
test('meta', () => {
expect(devdocs.meta({}, {})).toEqual({
name: 'DevDocs',
mentions: { label: 'Search docs... (css, html, http, javascript, dom)' },
})

expect(
devdocs.meta(
{},
{
urls: [
'https://devdocs.io/angular~16/',
'https://devdocs.io/css/',
'https://devdocs.io/typescript/',
],
}
)
).toEqual({
name: 'DevDocs',
mentions: { label: 'Search docs... (angular~16, css, typescript)' },
})

expect(devdocs.meta({}, { urls: ['https://devdocs.io/go/'] })).toEqual({
name: 'DevDocs',
mentions: { label: 'Search docs... (go)' },
})
})

test('meta malformed', () => {
expect(
devdocs.meta(
{},
{
urls: [
'https://devdocs.io/go',
'https://github.com/sourcegraph/openctx/pull/152',
'hello world',
'',
],
}
)
).toEqual({
name: 'DevDocs',
mentions: { label: 'Search docs... (go, 152)' },
})
})

test('test page type', async () => {
const fixturesDir = path.join(__dirname, '__fixtures__')
const settings = {
Expand Down
7 changes: 5 additions & 2 deletions provider/devdocs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
ItemsResult,
MentionsParams,
MentionsResult,
MetaParams,
MetaResult,
Provider,
} from '@openctx/provider'
Expand Down Expand Up @@ -37,10 +38,12 @@ export type Settings = {
* An OpenCtx provider that fetches the content of a [DevDocs](https://devdocs.io/) entry.
*/
const devdocs: Provider<Settings> = {
meta(): MetaResult {
meta(_params: MetaParams, settings: Settings): MetaResult {
const urls = settings.urls ?? DEFAULT_URLS
const slugs = urls.map(u => u.match(/\/([^/]*)\/?$/)?.at(1)).filter(Boolean)
return {
name: 'DevDocs',
mentions: {},
mentions: { label: `Search docs... (${slugs.join(', ')})` },
}
},

Expand Down
2 changes: 1 addition & 1 deletion provider/devdocs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openctx/provider-devdocs",
"version": "0.0.4",
"version": "0.0.5",
"description": "Use documentation from https://devdocs.io (OpenCtx provider)",
"license": "Apache-2.0",
"homepage": "https://openctx.org/docs/providers/devdocs",
Expand Down
2 changes: 1 addition & 1 deletion provider/github/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openctx/provider-github",
"version": "0.0.4",
"version": "0.0.5",
"description": "GitHub OpenCtx provider",
"license": "Apache-2.0",
"homepage": "https://openctx.org/docs/providers/github",
Expand Down
2 changes: 1 addition & 1 deletion provider/github/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const githubProvider: Provider<Settings> = {
meta(): MetaResult {
return {
name: 'Github PRs & Issues',
mentions: {},
mentions: { label: 'Search issues and pull requests...' },
}
},

Expand Down
4 changes: 2 additions & 2 deletions provider/google-docs/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ describe('googleDocs', () => {
}

test('meta', async () => {
expect(await googleDocs.meta({}, SETTINGS)).toEqual({
expect(await googleDocs.meta({}, SETTINGS)).toStrictEqual({
name: 'Google Docs',
mentions: {},
mentions: { label: 'Search by title or paste a URL...' },
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion provider/google-docs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const NUMBER_OF_DOCUMENTS_TO_FETCH = 10
*/
const googleDocs: Provider<Settings> = {
meta(): MetaResult {
return { name: 'Google Docs', mentions: {} }
return { name: 'Google Docs', mentions: { label: 'Search by title or paste a URL...' } }
},

async mentions(params: MentionsParams, settings: Settings): Promise<MentionsResult> {
Expand Down
7 changes: 5 additions & 2 deletions provider/google-docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openctx/provider-google-docs",
"version": "0.0.10",
"version": "0.0.11",
"description": "Google Docs context for code AI and editors (OpenCtx provider)",
"license": "Apache-2.0",
"repository": {
Expand All @@ -11,7 +11,10 @@
"type": "module",
"main": "dist/bundle.js",
"types": "dist/index.d.ts",
"files": ["dist/bundle.js", "dist/index.d.ts"],
"files": [
"dist/bundle.js",
"dist/index.d.ts"
],
"sideEffects": false,
"scripts": {
"bundle": "tsc --build && esbuild --log-level=error --platform=node --bundle --format=esm --outfile=dist/bundle.js index.ts",
Expand Down
2 changes: 1 addition & 1 deletion provider/jira/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const issueToItem = (issue: Issue): Item => ({

const jiraProvider: Provider = {
meta(params: MetaParams, settings: Settings): MetaResult {
return { name: 'Jira Issues', mentions: {} }
return { name: 'Jira Issues', mentions: { label: 'Search by name, id or paste a URL...' } }
},

async mentions(params: MentionsParams, settings: Settings): Promise<MentionsResult> {
Expand Down
7 changes: 5 additions & 2 deletions provider/jira/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@openctx/provider-jira",
"private": false,
"version": "0.0.8",
"version": "0.0.9",
"description": "Jira (OpenCtx provider)",
"license": "Apache-2.0",
"homepage": "https://openctx.org/docs/providers/jira",
Expand All @@ -13,7 +13,10 @@
"type": "module",
"main": "dist/bundle.js",
"types": "dist/index.d.ts",
"files": ["dist/bundle.js", "dist/index.d.ts"],
"files": [
"dist/bundle.js",
"dist/index.d.ts"
],
"sideEffects": false,
"scripts": {
"bundle": "tsc --build && esbuild --log-level=error --bundle --format=esm --outfile=dist/bundle.js index.ts",
Expand Down
3 changes: 1 addition & 2 deletions provider/semgrep/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ describe('Semgrep provider', () => {
test('meta', () => {
const meta = semgrep.meta({}, settings)

expect(meta).toBeDefined()
expect(meta).toEqual({ name: 'Semgrep', mentions: {} })
expect(meta).toStrictEqual({ name: 'Semgrep', mentions: { label: 'Paste a URL...' } })
})

test('items', async () => {
Expand Down
2 changes: 1 addition & 1 deletion provider/semgrep/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function aiPrompt(finding: Finding): string {

const semgrep: Provider = {
meta(params: MetaParams, settings: Settings): MetaResult {
return { name: 'Semgrep', mentions: {} }
return { name: 'Semgrep', mentions: { label: 'Paste a URL...' } }
},

items(params: ItemsParams, settings: Settings): ItemsResult {
Expand Down
2 changes: 1 addition & 1 deletion provider/semgrep/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openctx/provider-semgrep",
"version": "0.0.2",
"version": "0.0.3",
"description": "Semgrep OpenCtx provider",
"license": "Apache-2.0",
"homepage": "https://openctx.org/docs/providers/semgrep",
Expand Down
2 changes: 1 addition & 1 deletion provider/sentry/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openctx/provider-sentry",
"version": "0.0.2",
"version": "0.0.3",
"description": "Use information from Sentry.io issues (OpenCtx provider)",
"license": "Apache-2.0",
"homepage": "https://openctx.org/docs/providers/sentry",
Expand Down
19 changes: 2 additions & 17 deletions provider/sentry/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,27 +158,12 @@ Logger: N/A`
describe('provider.meta', () => {
test('returns expected meta result', async () => {
const metaResult = providerImplementation.meta()
expect(metaResult).toEqual({
expect(metaResult).toStrictEqual({
name: 'Sentry Issues',
mentions: {},
mentions: { label: 'Paste a URL...' },
annotations: { selectors: [] },
})
})

test('returns empty selector', async () => {
const metaResult = providerImplementation.meta()
expect(metaResult.annotations?.selectors).toHaveLength(0)
})

test('returns correct name', async () => {
const metaResult = providerImplementation.meta()
expect(metaResult.name).toBe('Sentry Issues')
})

test('returns correct features', async () => {
const metaResult = providerImplementation.meta()
expect(metaResult.mentions).toEqual({})
})
})

describe('provider.items', () => {
Expand Down
2 changes: 1 addition & 1 deletion provider/sentry/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const providerImplementation = {
return {
// We don't provide any annotations for now.
name: 'Sentry Issues',
mentions: {},
mentions: { label: 'Paste a URL...' },
annotations: {
selectors: [],
},
Expand Down
2 changes: 1 addition & 1 deletion provider/slack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let slackClient: undefined | SlackClient = undefined

const slackContext = {
meta(): MetaResult {
return { name: 'Slack', mentions: {} }
return { name: 'Slack', mentions: { label: 'Search by channel name...' } }
},

async initializeSlackClient(settingsInput: Settings) {
Expand Down
2 changes: 1 addition & 1 deletion provider/slack/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openctx/provider-slack",
"version": "0.0.4",
"version": "0.0.5",
"description": "Slack context for code AI and editors (OpenCtx provider)",
"license": "Apache-2.0",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion provider/web/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const urlFetcher: Provider = {
meta(): MetaResult {
return {
name: 'Web URLs',
mentions: {},
mentions: { label: 'Paste a URL...' },
annotations: { selectors: [] },
}
},
Expand Down
2 changes: 1 addition & 1 deletion provider/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openctx/provider-web",
"version": "0.0.6",
"version": "0.0.7",
"description": "Use information from web pages (OpenCtx provider)",
"license": "Apache-2.0",
"homepage": "https://openctx.org/docs/providers/web",
Expand Down

0 comments on commit ba1d9e6

Please sign in to comment.