From 218c46418697233e2899b320119f53b0db436699 Mon Sep 17 00:00:00 2001 From: Vanesa Ortiz Date: Thu, 23 May 2019 16:53:59 -0700 Subject: [PATCH 1/9] cleanup code, update comments and readme, use URL API for repo extraction --- README.md | 22 ++++++------- src/handler.ts | 19 ++++++----- src/test/extension.test.ts | 46 +++++++++++++------------- src/test/handler.test.ts | 67 ++++++++++++++++++-------------------- 4 files changed, 76 insertions(+), 78 deletions(-) diff --git a/README.md b/README.md index 91b218c0..da77dcaf 100644 --- a/README.md +++ b/README.md @@ -37,16 +37,16 @@ Set the following configurations in your settings: "projectId": "[Sentry project ID, e.g. "1334031"]", "linePatterns": [ // List of RegExp patterns that match error handling code, e.g. "throw new Error+\\(['\"]([^'\"]+)['\"]\\)", - // !! Make sure to capture the error message in a RegExp group !! + // !! Make sure to capture the error message in a RegExp group and escape special characters to ensure compatability with JSON Schema!! ] "filters": { [ "repositories": [ - // List of RegExp repo names asociated with this Sentry project + // List of RegExp repo names asociated with this Sentry project. ], "files": [ // List of RegExp that matches file format, e.g. "\\.tsx?", - // or for more specific matching, folder matching, e.g. "(?:web|shared|src)\/.*\\.tsx?" + // or for more specific matching, folder matching, e.g. "(?:web|shared|src)/.*\\.tsx?" ], } } @@ -59,7 +59,7 @@ File patterns can also be narrowed down to certain folders by specifying this in ``` ... -"files": ["(?:web|shared|src)\/.*\\.tsx?"] +"files": ["(?:web|shared|src)/.*\\.tsx?"] ... ``` @@ -78,15 +78,15 @@ File patterns can also be narrowed down to certain folders by specifying this in "projectId": "1334031", "linePatterns": [ "throw new Error+\\(['\"]([^'\"]+)['\"]\\)", - "console\\.(warn|debug|info|error)\\(['\"`]([^'\"`]+)['\"`]\\)" + "console\\.(?:warn|debug|info|error)\\(['\"`]([^'\"`]+)['\"`]\\)" ] "filters": [ { - "repositories": "sourcegraph\/sourcegraph", - "files": ["web\/.*\\.ts?"], + "repositories": "sourcegraph/sourcegraph", + "files": ["web/.*\\.ts?"], }, { - "files": ["sourcegraph-subfolder\/.*\\.tsx?"] + "files": ["sourcegraph-subfolder/.*\\.tsx?"] } ] @@ -111,11 +111,11 @@ Configuration: "linePatterns": ["errors\\.New\\(['\"`](.*)['\"`]\\)"], "filters": [ { - "repositories": ["sourcegraph\/sourcegraph", "sourcegraph\/dev-repo"], - "files": ["/auth\/.*.go?/"], + "repositories": ["sourcegraph/sourcegraph", "sourcegraph/dev-repo"], + "files": ["auth/.*\\.go?"], }, { - "repositories": ["/dev-env/"] + "repositories": ["/dev-env"] } ], ] diff --git a/src/handler.ts b/src/handler.ts index c2106017..09ab2471 100644 --- a/src/handler.ts +++ b/src/handler.ts @@ -18,15 +18,18 @@ export interface LineDecorationText { * @returns repo and file part of URI. */ export function getParamsFromUriPath(textDocumentURI: string): Params { - // TODO: Support more than just GitHub & Gitlab. - // TODO: Safeguard for cases where repo/fileMatch are null. - const repoPattern = /(github\.com|gitlab\.com)\/([^\?\#\/]+\/[^\?\#\/]*)/gi - const filePattern = /#(.*\.(.*))$/gi - const repoMatch = repoPattern.exec(textDocumentURI) - const fileMatch = filePattern.exec(textDocumentURI) + if (textDocumentURI) { + const paramsRepo = new URL(textDocumentURI).pathname + const filePattern = /#(.*\.(.*))$/gi + const fileMatch = filePattern.exec(textDocumentURI) + return { + repo: paramsRepo, + file: fileMatch && fileMatch[1], + } + } return { - repo: repoMatch && repoMatch[2], - file: fileMatch && fileMatch[1], + repo: '', + file: null, } } diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts index 2d6ab393..e3ff1deb 100644 --- a/src/test/extension.test.ts +++ b/src/test/extension.test.ts @@ -16,21 +16,19 @@ describe('activation', () => { }) }) -const asString = (re: RegExp): string => re.source - const projects: SentryProject[] = [ { name: 'Webapp typescript errors', projectId: '1334031', linePatterns: [ - /throw new Error+\(['"]([^'"]+)['"]\)/, - /console\.(warn|debug|info|error|log)\(['"`]([^'"`]+)['"`]\)/, - /log\.(Printf|Print|Println)\(['"]([^'"]+)['"]\)/, - ].map(asString), + 'throw new Error+\\([\'"]([^\'"]+)[\'"]\\)', + 'console\\.(?:warn|debug|info|error|log)\\([\'"`]([^\'"`]+)[\'"`]\\)', + 'log\\.(?:Printf|Print|Println)\\([\'"]([^\'"]+)[\'"]\\)', + ], filters: [ { - repositories: [/sourcegraph\/sourcegraph/, /bucket/].map(asString), - files: [/(web|shared|src)\/.*\.tsx?/, /\/.*\\.ts?/].map(asString), + repositories: ['sourcegraph/sourcegraph', '/bucket'], + files: ['(?:web|shared|src)/.*\\.tsx?', '\\.ts?'], }, ], }, @@ -38,11 +36,11 @@ const projects: SentryProject[] = [ { name: 'Dev env errors', projectId: '213332', - linePatterns: [/log\.(Printf|Print|Println)\(['"]([^'"]+)['"]\)/].map(asString), + linePatterns: ['log\\.(Printf|Print|Println)\\([\'"]([^\'"]+)[\'"]\\)'], filters: [ { - repositories: [/dev-repo/].map(asString), - files: [/(dev)\/.*\\.go?/].map(asString), + repositories: ['/dev-repo'], + files: ['dev/.*\\.go?'], }, ], }, @@ -64,25 +62,25 @@ describe('resolveSettings()', () => { projectId: '1334031', name: 'Webapp typescript errors', linePatterns: [ - /throw new Error+\(['"]([^'"]+)['"]\)/, - /console\.(warn|debug|info|error|log)\(['"`]([^'"`]+)['"`]\)/, - /log\.(Printf|Print|Println)\(['"]([^'"]+)['"]\)/, - ].map(asString), + 'throw new Error+\\([\'"]([^\'"]+)[\'"]\\)', + 'console\\.(?:warn|debug|info|error|log)\\([\'"`]([^\'"`]+)[\'"`]\\)', + 'log\\.(?:Printf|Print|Println)\\([\'"]([^\'"]+)[\'"]\\)', + ], filters: [ { - repositories: [/sourcegraph\/sourcegraph/, /bucket/].map(asString), - files: [/(web|shared|src)\/.*\.tsx?/, /\/.*\\.ts?/].map(asString), + repositories: ['sourcegraph/sourcegraph', '/bucket'], + files: ['(?:web|shared|src)/.*\\.tsx?', '\\.ts?'], }, ], }, { projectId: '213332', name: 'Dev env errors', - linePatterns: [/log\.(Printf|Print|Println)\(['"]([^'"]+)['"]\)/].map(asString), + linePatterns: ['log\\.(Printf|Print|Println)\\([\'"]([^\'"]+)[\'"]\\)'], filters: [ { - repositories: [/dev-repo/].map(asString), - files: [/(dev)\/.*\\.go?/].map(asString), + repositories: ['/dev-repo'], + files: ['dev/.*\\.go?'], }, ], }, @@ -460,8 +458,8 @@ describe('buildDecorations()', () => { it('should not render anything due to missing code ', () => expect(buildDecorations([], '')).toEqual([])) // set linePatterns back to original state for the other tests projects[0].linePatterns = [ - /throw new Error+\(['"]([^'"]+)['"]\)/, - /console\.(warn|debug|info|error|log)\(['"`]([^'"`]+)['"`]\)/, - /log\.(Printf|Print|Println)\(['"]([^'"]+)['"]\)/, - ].map(asString) + 'throw new Error+\\([\'"]([^\'"]+)[\'"]\\)', + 'console\\.(?:warn|debug|info|error|log)\\([\'"`]([^\'"`]+)[\'"`]\\)', + 'log\\.(?:Printf|Print|Println)\\([\'"]([^\'"]+)[\'"]\\)', + ] }) diff --git a/src/test/handler.test.ts b/src/test/handler.test.ts index 35a9adee..f2c59d94 100644 --- a/src/test/handler.test.ts +++ b/src/test/handler.test.ts @@ -9,52 +9,50 @@ mock('sourcegraph', sourcegraph) import { createDecoration, findEmptyConfigs, getParamsFromUriPath, matchSentryProject } from '../handler' import { SentryProject } from '../settings' -const asString = (re: RegExp): string => re.source - const projects: SentryProject[] = [ { name: 'Webapp typescript errors', projectId: '1334031', linePatterns: [ - /throw new Error+\(['"]([^'"]+)['"]\)/, - /console\.(warn|debug|info|error|log)\(['"`]([^'"`]+)['"`]\)/, - /log\.(Printf|Print|Println)\(['"]([^'"]+)['"]\)/, - ].map(asString), + 'throw new Error+\\([\'"]([^\'"]+)[\'"]\\)', + 'console\\.(?:warn|debug|info|error|log)\\([\'"`]([^\'"`]+)[\'"`]\\)', + 'log\\.(Printf|Print|Println)\\([\'"]([^\'"]+)[\'"]\\)', + ], filters: [ { - repositories: [/sourcegraph\/sourcegraph/, /bucket/].map(asString), - files: [/(web|shared|src)\/.*\.tsx?/, /\/.*\\.ts?/].map(asString), + repositories: ['sourcegraph/sourcegraph', '/bucket'], + files: ['(?:web|shared|src)/.*\\.tsx?', '\\.ts?'], }, ], }, { name: 'Dev env errors', projectId: '213332', - linePatterns: [/log\.(Printf|Print|Println)\(['"]([^'"]+)['"]\)/].map(asString), + linePatterns: ['log\\.(?:Printf|Print|Println)\\([\'"]([^\'"]+)[\'"]\\)'], filters: [ { - repositories: [/dev-repo/].map(asString), - files: [/dev\/.*.go?/].map(asString), + repositories: ['/dev-repo'], + files: ['dev/.*\\.go?'], }, ], }, { name: 'docs pages errors', projectId: '544533', - linePatterns: [/throw new Error+\(['"]([^'"]+)['"]\)/].map(asString), + linePatterns: ['throw new Error+\\([\'"]([^\'"]+)[\'"]\\)'], filters: [ { - repositories: [/sourcegraph\/docs/].map(asString), + repositories: ['sourcegraph/docs'], }, ], }, { name: 'dot com errors', projectId: '242677', - linePatterns: [/throw new Error+\(['"]([^'"]+)['"]\)/].map(asString), + linePatterns: ['throw new Error+\\([\'"]([^\'"]+)[\'"]\\)'], filters: [ { - files: [/\.tsx?/].map(asString), + files: ['\\.tsx?'], }, ], }, @@ -66,10 +64,9 @@ const setDefaults = async () => { } describe('getParamsFromUriPath', () => { - beforeEach(setDefaults) it('extracts repo and file params from root folder', () => expect(getParamsFromUriPath('git://github.com/sourcegraph/sourcegraph?264...#index.tsx')).toEqual({ - repo: 'sourcegraph/sourcegraph', + repo: '/sourcegraph/sourcegraph', file: 'index.tsx', })) @@ -77,19 +74,19 @@ describe('getParamsFromUriPath', () => { expect( getParamsFromUriPath('git://github.com/sourcegraph/sourcegraph?264...#web/src/e2e/index.e2e.test.tsx') ).toEqual({ - repo: 'sourcegraph/sourcegraph', + repo: '/sourcegraph/sourcegraph', file: 'web/src/e2e/index.e2e.test.tsx', })) - it('return empty repo if host is not GitHub', () => - expect(getParamsFromUriPath('git://unknownhost.com/sourcegraph/testrepo#http/req/main.go')).toEqual({ - repo: null, - file: 'http/req/main.go', + it('return null if URI is corupt', () => + expect(getParamsFromUriPath('git://thisisnotavaliduri')).toEqual({ + repo: '', + file: null, })) it('return empty file if document has no file format', () => - expect(getParamsFromUriPath('git://github.com/sourcegraph/sourcegraph/testrepo#formatless')).toEqual({ - repo: 'sourcegraph/sourcegraph', + expect(getParamsFromUriPath('git://github.com/sourcegraph/testrepo#formatless')).toEqual({ + repo: '/sourcegraph/testrepo', file: null, })) }) @@ -98,7 +95,7 @@ const paramsInput = [ { goal: 'returns a web project that matches the repo and file patterns', params: { - repo: 'sourcegraph/sourcegraph', + repo: '/sourcegraph/sourcegraph', file: 'web/src/storm/index.tsx', }, expected: { project: projects[0], missingConfigs: [] }, @@ -106,7 +103,7 @@ const paramsInput = [ { goal: 'returns a dev project that matches the repo and file patterns', params: { - repo: 'sourcegraph/dev-repo', + repo: '/sourcegraph/dev-repo', file: 'dev/backend/main.go', }, expected: { project: projects[1], missingConfigs: [] }, @@ -114,7 +111,7 @@ const paramsInput = [ { goal: 'returns file false for not matching file patterns', params: { - repo: 'sourcegraph/dev-repo', + repo: '/sourcegraph/dev-repo', file: 'dev/test/start.rb', }, expected: null, @@ -122,7 +119,7 @@ const paramsInput = [ { goal: 'returns undefined for not matching repo and false for not matching file patterns', params: { - repo: 'sourcegraph/test-repo', + repo: '/sourcegraph/test-repo', file: 'dev/test/start.rb', }, expected: null, @@ -130,7 +127,7 @@ const paramsInput = [ { goal: 'returns undefined for not matching repo and file patterns', params: { - repo: 'sourcegraph/test-repo', + repo: '/sourcegraph/test-repo', file: 'dev/test/start.rb', }, expected: null, @@ -138,7 +135,7 @@ const paramsInput = [ { goal: 'returns project for matching repo and undefined for not having file patterns', params: { - repo: 'sourcegraph/docs', + repo: '/sourcegraph/docs', file: 'src/development/tutorial.tsx', }, expected: { project: projects[2], missingConfigs: [] }, @@ -146,7 +143,7 @@ const paramsInput = [ { goal: 'returns project for matching file patterns', params: { - repo: 'sourcegraph/website', + repo: '/sourcegraph/website', file: 'web/search/start.tsx', }, expected: { project: projects[3], missingConfigs: [] }, @@ -166,11 +163,11 @@ const incompleteConfigs: { goal: string; settings: SentryProject; expected: stri settings: { name: 'sourcegraph', projectId: '1334031', - linePatterns: [/logger\.debug\(['"`]([^'"`]+)['"`]\);/].map(asString), + linePatterns: ['logger\\.debug\\([\'"`]([^\'"`]+)[\'"`]\\);'], filters: [ { repositories: undefined, - files: [/(web|shared|src).*\.java?/, /(dev|src).*\.java?/, /.java?/].map(asString), + files: ['(?:web|shared|src)/.*\\.java?', '(?:dev|src)/.*\\.java?', '\\.java?'], }, ], }, @@ -181,11 +178,11 @@ const incompleteConfigs: { goal: string; settings: SentryProject; expected: stri settings: { name: 'sourcegraph', projectId: '', - linePatterns: [/logger\.debug\(['"`]([^'"`]+)['"`]\);/].map(asString), + linePatterns: ['logger\\.debug\\([\'"`]([^\'"`]+)[\'"`]\\);'], filters: [ { repositories: undefined, - files: [/(web|shared|src).*\.java?/, /(dev|src).*\.java?/, /.java?/].map(asString), + files: ['(?:web|shared|src)/.*\\.java?', '(?:dev|src)/.*\\.java?', '\\.java?'], }, ], }, From 24b488bdd48c73d50416e976ac648b26bee2d42b Mon Sep 17 00:00:00 2001 From: Vanesa Date: Thu, 23 May 2019 22:26:14 -0700 Subject: [PATCH 2/9] Update README.md Co-Authored-By: Loic Guychard --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index da77dcaf..a23d12a6 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Set the following configurations in your settings: "projectId": "[Sentry project ID, e.g. "1334031"]", "linePatterns": [ // List of RegExp patterns that match error handling code, e.g. "throw new Error+\\(['\"]([^'\"]+)['\"]\\)", - // !! Make sure to capture the error message in a RegExp group and escape special characters to ensure compatability with JSON Schema!! + // !! Make sure to capture the error message in a RegExp group and escape special characters to ensure compatibility with JSON Schema!! ] "filters": { [ From c09fade1823855926825b37741fc6cb962764df6 Mon Sep 17 00:00:00 2001 From: Vanesa Ortiz Date: Thu, 23 May 2019 22:37:27 -0700 Subject: [PATCH 3/9] fix comments --- src/test/handler.test.ts | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/test/handler.test.ts b/src/test/handler.test.ts index f2c59d94..9cf82b20 100644 --- a/src/test/handler.test.ts +++ b/src/test/handler.test.ts @@ -78,13 +78,13 @@ describe('getParamsFromUriPath', () => { file: 'web/src/e2e/index.e2e.test.tsx', })) - it('return null if URI is corupt', () => + it('returns null if URI is corrupted', () => expect(getParamsFromUriPath('git://thisisnotavaliduri')).toEqual({ repo: '', file: null, })) - it('return empty file if document has no file format', () => + it('returns empty file if document has no file format', () => expect(getParamsFromUriPath('git://github.com/sourcegraph/testrepo#formatless')).toEqual({ repo: '/sourcegraph/testrepo', file: null, @@ -93,7 +93,7 @@ describe('getParamsFromUriPath', () => { const paramsInput = [ { - goal: 'returns a web project that matches the repo and file patterns', + goal: 'returns a web project that matches the repo and file patterns and an empty missingConfigs list', params: { repo: '/sourcegraph/sourcegraph', file: 'web/src/storm/index.tsx', @@ -101,7 +101,7 @@ const paramsInput = [ expected: { project: projects[0], missingConfigs: [] }, }, { - goal: 'returns a dev project that matches the repo and file patterns', + goal: 'returns a dev project that matches the repo and file patterns and an empty missingConfigs list', params: { repo: '/sourcegraph/dev-repo', file: 'dev/backend/main.go', @@ -109,7 +109,7 @@ const paramsInput = [ expected: { project: projects[1], missingConfigs: [] }, }, { - goal: 'returns file false for not matching file patterns', + goal: 'returns null for not matching file patterns', params: { repo: '/sourcegraph/dev-repo', file: 'dev/test/start.rb', @@ -117,7 +117,7 @@ const paramsInput = [ expected: null, }, { - goal: 'returns undefined for not matching repo and false for not matching file patterns', + goal: 'returns null for not matching repo and file patterns', params: { repo: '/sourcegraph/test-repo', file: 'dev/test/start.rb', @@ -125,15 +125,7 @@ const paramsInput = [ expected: null, }, { - goal: 'returns undefined for not matching repo and file patterns', - params: { - repo: '/sourcegraph/test-repo', - file: 'dev/test/start.rb', - }, - expected: null, - }, - { - goal: 'returns project for matching repo and undefined for not having file patterns', + goal: 'returns project for matching repo despite not having a files config and an empty missingConfigs list', params: { repo: '/sourcegraph/docs', file: 'src/development/tutorial.tsx', @@ -141,7 +133,8 @@ const paramsInput = [ expected: { project: projects[2], missingConfigs: [] }, }, { - goal: 'returns project for matching file patterns', + goal: + 'returns project for matching file patterns despite not having a repositories config and an empty missingConfigs list', params: { repo: '/sourcegraph/website', file: 'web/search/start.tsx', From bec2f21f4cf8ded64d81831dd5b1f3ea7287f978 Mon Sep 17 00:00:00 2001 From: Vanesa Ortiz Date: Wed, 29 May 2019 18:13:47 -0700 Subject: [PATCH 4/9] catch errors when getting params from URI --- src/extension.ts | 2 +- src/handler.ts | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 95f21a5b..33458237 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -84,7 +84,7 @@ export function getDecorations( documentText: string, sentryProjects?: SentryProject[] ): sourcegraph.TextDocumentDecoration[] { - const params: Params = getParamsFromUriPath(documentUri) + const params: Params | null = getParamsFromUriPath(documentUri) const matched = sentryProjects && matchSentryProject(params, sentryProjects) // Do not decorate lines if the document file format does not match the diff --git a/src/handler.ts b/src/handler.ts index 09ab2471..7d0f7ccc 100644 --- a/src/handler.ts +++ b/src/handler.ts @@ -17,19 +17,19 @@ export interface LineDecorationText { * @param textDocumentURI A document URI. * @returns repo and file part of URI. */ -export function getParamsFromUriPath(textDocumentURI: string): Params { - if (textDocumentURI) { - const paramsRepo = new URL(textDocumentURI).pathname - const filePattern = /#(.*\.(.*))$/gi - const fileMatch = filePattern.exec(textDocumentURI) - return { - repo: paramsRepo, - file: fileMatch && fileMatch[1], - } +export function getParamsFromUriPath(textDocumentURI: string): Params | null { + let paramsRepo + let fileMatch + const filePattern = /#(.*\.(.*))$/gi + try { + paramsRepo = new URL(textDocumentURI).pathname + fileMatch = filePattern.exec(textDocumentURI) + } catch (err) { + return null } return { - repo: '', - file: null, + repo: paramsRepo, + file: fileMatch && fileMatch[1], } } @@ -45,8 +45,8 @@ interface Matched { * @param projects Sentry extension projects configurations. * @return Sentry projectID this document reports to. */ -export function matchSentryProject(params: Params, projects: SentryProject[]): Matched | null { - if (!projects || !params.repo || !params.file) { +export function matchSentryProject(params: Params | null, projects: SentryProject[]): Matched | null { + if (!projects || !params || !params.repo || !params.file) { return null } // Check if a Sentry project is associated with this document's repository and/or file and retrieve the project. From efc8b4c90e75e36e6d432efdfb52a03c69c0e81e Mon Sep 17 00:00:00 2001 From: Vanesa Date: Mon, 3 Jun 2019 12:49:33 -0700 Subject: [PATCH 5/9] Update src/extension.ts Co-Authored-By: Loic Guychard --- src/extension.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index 33458237..813cf316 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -84,7 +84,7 @@ export function getDecorations( documentText: string, sentryProjects?: SentryProject[] ): sourcegraph.TextDocumentDecoration[] { - const params: Params | null = getParamsFromUriPath(documentUri) + const params = getParamsFromUriPath(documentUri) const matched = sentryProjects && matchSentryProject(params, sentryProjects) // Do not decorate lines if the document file format does not match the From 2317f1e757e8d142a3d175bfb5f9fac0f7d69064 Mon Sep 17 00:00:00 2001 From: Vanesa Ortiz Date: Mon, 3 Jun 2019 13:38:05 -0700 Subject: [PATCH 6/9] remove Params struct --- src/extension.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 813cf316..4a5d8046 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -4,14 +4,6 @@ import * as sourcegraph from 'sourcegraph' import { createDecoration, getParamsFromUriPath, matchSentryProject } from './handler' import { resolveSettings, SentryProject, Settings } from './settings' -/** - * Params derived from the document's URI. - */ -interface Params { - repo: string | null - file: string | null -} - /** * Common error log patterns to use in case no line matching regexes * are set in the sentry extension settings. From 4b76ad77086851a4d58d6222606ed0f806ae9bf4 Mon Sep 17 00:00:00 2001 From: Vanesa Ortiz Date: Mon, 3 Jun 2019 13:46:28 -0700 Subject: [PATCH 7/9] match any throw new TypeError() --- src/extension.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index 4a5d8046..9a5b2e24 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -10,7 +10,7 @@ import { resolveSettings, SentryProject, Settings } from './settings' */ const COMMON_ERRORLOG_PATTERNS = [ // typescript/javascript - /throw new Error+\(['"]([^'"]+)['"]\)/gi, + /throw new ([A-Z][a-z]+)+\(['"]([^'"]+)['"]\)/gi, /console\.(error|info|warn)\(['"`]([^'"`]+)['"`]\)/gi, // go /log\.(Printf|Print|Println)\(['"]([^'"]+)['"]\)/gi, From c2e197ced4786e9e0d50905d6debb94374ac56eb Mon Sep 17 00:00:00 2001 From: Vanesa Ortiz Date: Mon, 3 Jun 2019 13:55:55 -0700 Subject: [PATCH 8/9] wrap query in double quotes --- src/extension.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index 9a5b2e24..f9603624 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -181,7 +181,8 @@ function buildUrl(errorQuery: string, sentryProjectId?: string): URL { if (sentryProjectId) { url.searchParams.set('project', sentryProjectId) - url.searchParams.set('query', 'is:unresolved ' + errorQuery) + // Query must be wrapped in double quotes to be used as a search query in Sentry + url.searchParams.set('query', 'is:unresolved ' + '"' + errorQuery + '"') url.searchParams.set('statsPeriod', '14d') } From 345e593ed486557183c9e747da30b1f250197eae Mon Sep 17 00:00:00 2001 From: Vanesa Ortiz Date: Mon, 3 Jun 2019 13:59:31 -0700 Subject: [PATCH 9/9] update tests --- src/test/extension.test.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts index e3ff1deb..e952b464 100644 --- a/src/test/extension.test.ts +++ b/src/test/extension.test.ts @@ -106,7 +106,7 @@ const decorateLineInput = [ contentText: ' View logs in Sentry » ', hoverMessage: ' View logs in Sentry » ', linkURL: - 'https://sentry.io/organizations/sourcegraph/issues/?project=134412&query=is%3Aunresolved+cannot+determine+file+path&statsPeriod=14d', + 'https://sentry.io/organizations/sourcegraph/issues/?project=134412&query=is%3Aunresolved+%22cannot+determine+file+path%22&statsPeriod=14d', }, }, }, @@ -125,7 +125,7 @@ const decorateLineInput = [ contentText: ' View logs in Sentry (❕)» ', hoverMessage: ' Add this repository to your Sentry extension settings for project matching.', linkURL: - 'https://sentry.io/organizations/sourcegraph/issues/?project=134412&query=is%3Aunresolved+cannot+determine+file+path&statsPeriod=14d', + 'https://sentry.io/organizations/sourcegraph/issues/?project=134412&query=is%3Aunresolved+%22cannot+determine+file+path%22&statsPeriod=14d', }, }, }, @@ -144,7 +144,7 @@ const decorateLineInput = [ contentText: ' View logs in Sentry (❕)» ', hoverMessage: ' Add this repository to your Sentry extension settings for project matching.', linkURL: - 'https://sentry.io/organizations/sourcegraph/issues/?project=134412&query=is%3Aunresolved+cannot+determine+file+path&statsPeriod=14d', + 'https://sentry.io/organizations/sourcegraph/issues/?project=134412&query=is%3Aunresolved+%22cannot+determine+file+path%22&statsPeriod=14d', }, }, }, @@ -224,7 +224,7 @@ const getDecorationsInput = [ contentText: ' View logs in Sentry » ', hoverMessage: ' View logs in Sentry » ', linkURL: - 'https://sentry.io/organizations/sourcegraph/issues/?project=1334031&query=is%3Aunresolved+cannot+determine+file+path&statsPeriod=14d', + 'https://sentry.io/organizations/sourcegraph/issues/?project=1334031&query=is%3Aunresolved+%22cannot+determine+file+path%22&statsPeriod=14d', }, }, { @@ -236,7 +236,7 @@ const getDecorationsInput = [ contentText: ' View logs in Sentry » ', hoverMessage: ' View logs in Sentry » ', linkURL: - 'https://sentry.io/organizations/sourcegraph/issues/?project=1334031&query=is%3Aunresolved+cannot+determine+delta+info&statsPeriod=14d', + 'https://sentry.io/organizations/sourcegraph/issues/?project=1334031&query=is%3Aunresolved+%22cannot+determine+delta+info%22&statsPeriod=14d', }, }, ], @@ -260,7 +260,7 @@ const getDecorationsInput = [ contentText: ' View logs in Sentry » ', hoverMessage: ' View logs in Sentry » ', linkURL: - 'https://sentry.io/organizations/sourcegraph/issues/?project=1334031&query=is%3Aunresolved+cannot+determine+file+path&statsPeriod=14d', + 'https://sentry.io/organizations/sourcegraph/issues/?project=1334031&query=is%3Aunresolved+%22cannot+determine+file+path%22&statsPeriod=14d', }, }, ], @@ -314,7 +314,7 @@ of(codeView).pipe( contentText: ' View logs in Sentry » ', hoverMessage: ' View logs in Sentry » ', linkURL: - 'https://sentry.io/organizations/sourcegraph/issues/?project=1334031&query=is%3Aunresolved+cannot+determine+file+path&statsPeriod=14d', + 'https://sentry.io/organizations/sourcegraph/issues/?project=1334031&query=is%3Aunresolved+%22cannot+determine+file+path%22&statsPeriod=14d', }, }, ],