Skip to content

Commit 6fa41d1

Browse files
authored
add Codecov to the Sentry extension (#6)
Add Codecov to the Sentry extension repo. Part of https://github.com/sourcegraph/sourcegraph/issues/3177.
1 parent 4baf865 commit 6fa41d1

16 files changed

+650
-329
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
dist/
22
node_modules/
33
.cache/
4+
.DS_Store
5+
.nyc_output/
6+
coverage/

.prettierignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules/
2+
.git/
3+
coverage/
4+
.cache/
5+
lib/
6+
dist/
7+
package.json

.travis.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
language: node_js
2+
node_js: '10'
3+
cache: yarn
4+
env:
5+
global:
6+
- FORCE_COLOR=1
7+
jobs:
8+
include:
9+
- stage: test
10+
script:
11+
- npm run prettier-check
12+
- npm run tslint
13+
- npm run typecheck
14+
- npm run build
15+
- npm run cover
16+
- nyc report --reporter json
17+
- 'bash <(curl -s https://codecov.io/bash)'
18+
stages:
19+
- test
20+
branches:
21+
only:
22+
- master
23+
- /^renovate\//

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
[![codecov](https://codecov.io/gh/sourcegraph/sourcegraph-sentry/branch/master/graph/badge.svg)](https://codecov.io/gh/sourcegraph/sourcegraph-sentry)
2+
13
# WIP: Sentry Sourcegraph extension
24

35
Sentry helps devs track, organize and break down errors more efficiently, facilitating their debug process. We want to make it more convenient for developers to access Sentry's error tracking tools directly from the code that is doing the error handling, code such as `throw new Error(QUERY)`, `console.log(QUERY)`, `console.error(QUERY)` etc..
46

5-
In this first version, the Sentry extension will render a ```View logs in Sentry``` link on each line it detects such error handling code, leading the devs directly to the corresponding Sentry issues stream page.
7+
In this first version, the Sentry extension will render a `View logs in Sentry` link on each line it detects such error handling code, leading the devs directly to the corresponding Sentry issues stream page.
68

79
![image](https://user-images.githubusercontent.com/9110008/54014672-d7b4fe00-41c0-11e9-9b92-66d851401fa0.png)
810

codecov.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage:
2+
status:
3+
patch: off

package.json

+54-22
Original file line numberDiff line numberDiff line change
@@ -33,39 +33,41 @@
3333
"sentry.projects": {
3434
"type": "array",
3535
"items": {
36-
"name": { "type" : "string" },
37-
"type" : "object",
36+
"name": {
37+
"type": "string"
38+
},
39+
"type": "object",
3840
"description": "Sentry project receiving logs",
3941
"projectId": {
4042
"description": "Sentry project id, e.g. 12351512",
4143
"type": "string"
4244
},
43-
"patternProperties" : {
45+
"patternProperties": {
4446
"repoMatch": {
45-
"type" : "string",
47+
"type": "string",
4648
"description": "Regex to match repos associated to this Sentry project, e.g. github\\.com/sourcegraph/sourcegraph"
4749
},
4850
"fileMatch": {
49-
"type" : "string",
51+
"type": "string",
5052
"description": "Regex to match files associated with this project, e.g. (web|shared)/.*\\.tsx?$"
5153
},
5254
"lineMatch": {
53-
"type" : "string",
54-
"description" : "Regex to match lines associated with this project, e.g. throw new Error\\([\"']([^'\"]+)[\"']\\)"
55+
"type": "string",
56+
"description": "Regex to match lines associated with this project, e.g. throw new Error\\([\"']([^'\"]+)[\"']\\)"
5557
}
5658
},
57-
"additionalProperties" : {
59+
"additionalProperties": {
5860
"contentText": {
59-
"description" : "Text shown in Sentry link, e.g. View sourcegraph/sourcegraph_dot_com errors",
60-
"type" : "string"
61+
"description": "Text shown in Sentry link, e.g. View sourcegraph/sourcegraph_dot_com errors",
62+
"type": "string"
6163
},
6264
"hoverMessage": {
63-
"description" : "Hovertext shown on Sentry link, e.g. View errors matching '$1' in Sentry",
64-
"type" : "string"
65+
"description": "Hovertext shown on Sentry link, e.g. View errors matching '$1' in Sentry",
66+
"type": "string"
6567
},
6668
"query": {
67-
"description" : "Query derived from error handling code $1",
68-
"type" : "string"
69+
"description": "Query derived from error handling code $1",
70+
"type": "string"
6971
}
7072
}
7173
}
@@ -81,6 +83,8 @@
8183
"license": "Apache-2.0",
8284
"main": "dist/extension.js",
8385
"scripts": {
86+
"prettier-check": "npm run prettier -- --write=false",
87+
"prettier": "prettier \"**/*.{ts,js,json,md}\" --list-different --write",
8488
"tslint": "tslint -p tsconfig.json './src/**/*.ts'",
8589
"typecheck": "tsc -p tsconfig.json",
8690
"test": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' mocha --require ts-node/register --require source-map-support/register --opts mocha.opts",
@@ -92,6 +96,26 @@
9296
"watch:build": "tsc -p tsconfig.dist.json -w",
9397
"sourcegraph:prepublish": "npm run typecheck && npm run test && npm run build"
9498
},
99+
"mocha": {
100+
"spec": "src/test/**/*.test.ts"
101+
},
102+
"nyc": {
103+
"include": [
104+
"src/**/*.ts?(x)"
105+
],
106+
"exclude": [
107+
"**/*.test.ts?(x)",
108+
"**/*.d.ts"
109+
],
110+
"extension": [
111+
".tsx",
112+
".ts"
113+
],
114+
"reporter": [
115+
"text",
116+
"json"
117+
]
118+
},
95119
"browserslist": [
96120
"last 1 Chrome versions",
97121
"last 1 Firefox versions",
@@ -101,20 +125,28 @@
101125
"devDependencies": {
102126
"@sourcegraph/prettierrc": "^2.2.0",
103127
"@sourcegraph/tsconfig": "^4.0.0",
104-
"@sourcegraph/tslint-config": "^12.3.1",
105-
"@types/expect": "^1.20.4",
128+
"@sourcegraph/tslint-config": "^13.0.0",
129+
"@types/expect": "1.20.4",
130+
"@types/lodash": "4.14.123",
106131
"@types/mocha": "^5.2.6",
107-
"expect": "^24.4.0",
132+
"@types/mock-require": "2.0.0",
133+
"@types/node": "^11.13.3",
134+
"@types/sinon": "7.0.11",
135+
"expect": "24.1.0",
108136
"lnfs-cli": "^2.1.0",
137+
"lodash": "^4.17.11",
109138
"mkdirp": "^0.5.1",
110-
"mocha": "^6.0.2",
139+
"mocha": "^6.1.2",
140+
"mock-require": "^3.0.3",
111141
"nyc": "^13.3.0",
112-
"parcel-bundler": "^1.12.0",
142+
"parcel-bundler": "^1.12.3",
143+
"prettier": "1.16.4",
113144
"rxjs": "^6.4.0",
114-
"source-map-support": "^0.5.11",
145+
"sinon": "^7.3.1",
146+
"source-map-support": "^0.5.12",
115147
"sourcegraph": "^23.0.0",
116148
"ts-node": "^8.0.3",
117-
"tslint": "^5.13.1",
118-
"typescript": "^3.3.3333"
149+
"tslint": "^5.15.0",
150+
"typescript": "^3.4.2"
119151
}
120152
}

renovate.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
{
2-
"extends": [
3-
"config:base"
4-
]
2+
"extends": ["github>sourcegraph/renovate-config"]
53
}

src/extension.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ const SENTRYORGANIZATION = SETTINGSCONFIG['sentry.organization']
2828
*/
2929
const COMMON_ERRORLOG_PATTERNS = [
3030
/throw new Error+\(['"]([^'"]+)['"]\)/gi,
31-
/console\.(log|error|info|warn)\(['"`]([^'"`]+)['"`]\)/gi,
31+
/console\.(error|info|warn)\(['"`]([^'"`]+)['"`]\)/gi,
3232
/log\.(Printf|Print|Println)\(['"]([^'"]+)['"]\)/gi,
3333
]
3434

3535
// TODO: Refactor to use activeEditor
3636
export function activate(context: sourcegraph.ExtensionContext): void {
37-
sourcegraph.workspace.onDidOpenTextDocument.subscribe(textDocument => {
37+
sourcegraph.workspace.openedTextDocuments.subscribe(textDocument => {
3838
const params: Params = getParamsFromUriPath(textDocument.uri)
3939
const sentryProjects = SETTINGSCONFIG['sentry.projects']
4040

@@ -114,7 +114,7 @@ export function decorateLine(
114114
missingConfigData: string[],
115115
sentryProjectId?: string
116116
): sourcegraph.TextDocumentDecoration {
117-
const lineDecorationText = createDecoration(missingConfigData, sentryProjectId)
117+
const lineDecorationText = createDecoration(missingConfigData, SENTRYORGANIZATION, sentryProjectId)
118118
const decoration: sourcegraph.TextDocumentDecoration = {
119119
range: new sourcegraph.Range(index, 0, index, 0),
120120
isWholeLine: true,

src/handler.test.ts

-60
This file was deleted.

src/handler.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as sourcegraph from 'sourcegraph'
2-
import { resolveSettings, SentryProject, Settings } from './settings'
1+
import { SentryProject } from './settings'
32

43
interface Params {
54
repo: string | null
@@ -12,9 +11,6 @@ interface LineDecorationText {
1211
backgroundColor: string
1312
}
1413

15-
const SETTINGSCONFIG = resolveSettings(sourcegraph.configuration.get<Settings>().value)
16-
const SENTRYORGANIZATION = SETTINGSCONFIG['sentry.organization']
17-
1814
/**
1915
* Extract Sentry params from document URI necessary to
2016
* check if the current document sends log events to Sentry and
@@ -45,13 +41,13 @@ export function getParamsFromUriPath(textDocument: string): Params {
4541
*/
4642
export function matchSentryProject(params: Params, projects: SentryProject[]): SentryProject | undefined {
4743
if (!projects || !params.repo || !params.file) {
48-
return
44+
return undefined
4945
}
5046
// Check if a Sentry project is associated with this document's repo and retrieve the project.
5147
// TODO: Handle the null case instead of using a non-null assertion !
5248
const project = projects.find(p => !!new RegExp(p.patternProperties.repoMatch).exec(params.repo!))
5349
if (!project) {
54-
return
50+
return undefined
5551
}
5652
return project
5753
}
@@ -88,12 +84,16 @@ export function checkMissingConfig(settings: SentryProject): string[] {
8884
return missingConfig
8985
}
9086

91-
export function createDecoration(missingConfigData: string[], sentryProjectId?: string): LineDecorationText {
87+
export function createDecoration(
88+
missingConfigData: string[],
89+
sentryOrg?: string,
90+
sentryProjectId?: string
91+
): LineDecorationText {
9292
let contentText = ' View logs in Sentry » '
9393
let hoverText = ' View logs in Sentry » '
9494
const color = '#e03e2f'
9595

96-
if (!SENTRYORGANIZATION) {
96+
if (!sentryOrg) {
9797
contentText = ' Configure the Sentry extension to view logs. '
9898
hoverText = ' Configure the Sentry extension to view logs in Sentry. '
9999
} else if (!sentryProjectId) {

src/settings.ts

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface SentryProject {
1515
patternProperties: {
1616
repoMatch: RegExp
1717
fileMatches: RegExp[]
18+
// RexExp patterns to match log handeling code, e.g. /log\.(Printf|Print)\(['"]([^'"]+)['"]\)/
1819
lineMatches: RegExp[]
1920
}
2021
// TODO: Add these to v1.

0 commit comments

Comments
 (0)