Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Codecov to the Sentry extension #6

Merged
merged 17 commits into from
Apr 11, 2019
Merged
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
dist/
node_modules/
.cache/
.DS_Store
.nyc_output/
coverage/
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules/
.git/
coverage/
.cache/
lib/
dist/
package.json
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
language: node_js
node_js: '10'
cache: yarn
env:
global:
- FORCE_COLOR=1
jobs:
include:
- stage: test
script:
- npm run prettier-check
- npm run tslint
- npm run typecheck
- npm run build
- npm run cover
- nyc report --reporter json
- 'bash <(curl -s https://codecov.io/bash)'
stages:
- test
branches:
only:
- master
- /^renovate\//
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[![codecov](https://codecov.io/gh/sourcegraph/sourcegraph-sentry/branch/master/graph/badge.svg)](https://codecov.io/gh/sourcegraph/sourcegraph-sentry)

# WIP: Sentry Sourcegraph extension

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..

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.
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.

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

Expand Down
3 changes: 3 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage:
status:
patch: off
76 changes: 54 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,41 @@
"sentry.projects": {
"type": "array",
"items": {
"name": { "type" : "string" },
"type" : "object",
"name": {
"type": "string"
},
"type": "object",
"description": "Sentry project receiving logs",
"projectId": {
"description": "Sentry project id, e.g. 12351512",
"type": "string"
},
"patternProperties" : {
"patternProperties": {
"repoMatch": {
"type" : "string",
"type": "string",
"description": "Regex to match repos associated to this Sentry project, e.g. github\\.com/sourcegraph/sourcegraph"
},
"fileMatch": {
"type" : "string",
"type": "string",
"description": "Regex to match files associated with this project, e.g. (web|shared)/.*\\.tsx?$"
},
"lineMatch": {
"type" : "string",
"description" : "Regex to match lines associated with this project, e.g. throw new Error\\([\"']([^'\"]+)[\"']\\)"
"type": "string",
"description": "Regex to match lines associated with this project, e.g. throw new Error\\([\"']([^'\"]+)[\"']\\)"
}
},
"additionalProperties" : {
"additionalProperties": {
"contentText": {
"description" : "Text shown in Sentry link, e.g. View sourcegraph/sourcegraph_dot_com errors",
"type" : "string"
"description": "Text shown in Sentry link, e.g. View sourcegraph/sourcegraph_dot_com errors",
"type": "string"
},
"hoverMessage": {
"description" : "Hovertext shown on Sentry link, e.g. View errors matching '$1' in Sentry",
"type" : "string"
"description": "Hovertext shown on Sentry link, e.g. View errors matching '$1' in Sentry",
"type": "string"
},
"query": {
"description" : "Query derived from error handling code $1",
"type" : "string"
"description": "Query derived from error handling code $1",
"type": "string"
}
}
}
Expand All @@ -81,6 +83,8 @@
"license": "Apache-2.0",
"main": "dist/extension.js",
"scripts": {
"prettier-check": "npm run prettier -- --write=false",
"prettier": "prettier \"**/*.{ts,js,json,md}\" --list-different --write",
"tslint": "tslint -p tsconfig.json './src/**/*.ts'",
"typecheck": "tsc -p tsconfig.json",
"test": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' mocha --require ts-node/register --require source-map-support/register --opts mocha.opts",
Expand All @@ -92,6 +96,26 @@
"watch:build": "tsc -p tsconfig.dist.json -w",
"sourcegraph:prepublish": "npm run typecheck && npm run test && npm run build"
},
"mocha": {
"spec": "src/test/**/*.test.ts"
},
"nyc": {
"include": [
"src/**/*.ts?(x)"
],
"exclude": [
"**/*.test.ts?(x)",
"**/*.d.ts"
],
"extension": [
".tsx",
".ts"
],
"reporter": [
"text",
"json"
]
},
"browserslist": [
"last 1 Chrome versions",
"last 1 Firefox versions",
Expand All @@ -101,20 +125,28 @@
"devDependencies": {
"@sourcegraph/prettierrc": "^2.2.0",
"@sourcegraph/tsconfig": "^4.0.0",
"@sourcegraph/tslint-config": "^12.3.1",
"@types/expect": "^1.20.4",
"@sourcegraph/tslint-config": "^13.0.0",
"@types/expect": "1.20.4",
"@types/lodash": "4.14.123",
"@types/mocha": "^5.2.6",
"expect": "^24.4.0",
"@types/mock-require": "2.0.0",
"@types/node": "^11.13.3",
"@types/sinon": "7.0.11",
"expect": "24.1.0",
"lnfs-cli": "^2.1.0",
"lodash": "^4.17.11",
"mkdirp": "^0.5.1",
"mocha": "^6.0.2",
"mocha": "^6.1.2",
"mock-require": "^3.0.3",
"nyc": "^13.3.0",
"parcel-bundler": "^1.12.0",
"parcel-bundler": "^1.12.3",
"prettier": "1.16.4",
"rxjs": "^6.4.0",
"source-map-support": "^0.5.11",
"sinon": "^7.3.1",
"source-map-support": "^0.5.12",
"sourcegraph": "^23.0.0",
"ts-node": "^8.0.3",
"tslint": "^5.13.1",
"typescript": "^3.3.3333"
"tslint": "^5.15.0",
"typescript": "^3.4.2"
}
}
4 changes: 1 addition & 3 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"extends": [
"config:base"
]
"extends": ["github>sourcegraph/renovate-config"]
}
6 changes: 3 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ const SENTRYORGANIZATION = SETTINGSCONFIG['sentry.organization']
*/
const COMMON_ERRORLOG_PATTERNS = [
/throw new Error+\(['"]([^'"]+)['"]\)/gi,
/console\.(log|error|info|warn)\(['"`]([^'"`]+)['"`]\)/gi,
/console\.(error|info|warn)\(['"`]([^'"`]+)['"`]\)/gi,
/log\.(Printf|Print|Println)\(['"]([^'"]+)['"]\)/gi,
]

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

Expand Down Expand Up @@ -114,7 +114,7 @@ export function decorateLine(
missingConfigData: string[],
sentryProjectId?: string
): sourcegraph.TextDocumentDecoration {
const lineDecorationText = createDecoration(missingConfigData, sentryProjectId)
const lineDecorationText = createDecoration(missingConfigData, SENTRYORGANIZATION, sentryProjectId)
const decoration: sourcegraph.TextDocumentDecoration = {
range: new sourcegraph.Range(index, 0, index, 0),
isWholeLine: true,
Expand Down
60 changes: 0 additions & 60 deletions src/handler.test.ts

This file was deleted.

18 changes: 9 additions & 9 deletions src/handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as sourcegraph from 'sourcegraph'
import { resolveSettings, SentryProject, Settings } from './settings'
import { SentryProject } from './settings'

interface Params {
repo: string | null
Expand All @@ -12,9 +11,6 @@ interface LineDecorationText {
backgroundColor: string
}

const SETTINGSCONFIG = resolveSettings(sourcegraph.configuration.get<Settings>().value)
const SENTRYORGANIZATION = SETTINGSCONFIG['sentry.organization']

/**
* Extract Sentry params from document URI necessary to
* check if the current document sends log events to Sentry and
Expand Down Expand Up @@ -45,13 +41,13 @@ export function getParamsFromUriPath(textDocument: string): Params {
*/
export function matchSentryProject(params: Params, projects: SentryProject[]): SentryProject | undefined {
if (!projects || !params.repo || !params.file) {
return
return undefined
}
// Check if a Sentry project is associated with this document's repo and retrieve the project.
// TODO: Handle the null case instead of using a non-null assertion !
const project = projects.find(p => !!new RegExp(p.patternProperties.repoMatch).exec(params.repo!))
if (!project) {
return
return undefined
}
return project
}
Expand Down Expand Up @@ -88,12 +84,16 @@ export function checkMissingConfig(settings: SentryProject): string[] {
return missingConfig
}

export function createDecoration(missingConfigData: string[], sentryProjectId?: string): LineDecorationText {
export function createDecoration(
missingConfigData: string[],
sentryOrg?: string,
sentryProjectId?: string
): LineDecorationText {
let contentText = ' View logs in Sentry » '
let hoverText = ' View logs in Sentry » '
const color = '#e03e2f'

if (!SENTRYORGANIZATION) {
if (!sentryOrg) {
contentText = ' Configure the Sentry extension to view logs. '
hoverText = ' Configure the Sentry extension to view logs in Sentry. '
} else if (!sentryProjectId) {
Expand Down
1 change: 1 addition & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface SentryProject {
patternProperties: {
repoMatch: RegExp
fileMatches: RegExp[]
// RexExp patterns to match log handeling code, e.g. /log\.(Printf|Print)\(['"]([^'"]+)['"]\)/
lineMatches: RegExp[]
}
// TODO: Add these to v1.
Expand Down
Loading