Skip to content

Commit

Permalink
Merge branch 'master' into chore/add-semantic-release
Browse files Browse the repository at this point in the history
# Conflicts:
#	package-lock.json
#	package.json

changed deepcode to snyk in environment var name and renamed this package
  • Loading branch information
Arvid Paeglit committed Jan 28, 2021
2 parents 8b640f9 + 2ce905d commit 050c224
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 55 deletions.
33 changes: 21 additions & 12 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,31 @@ jobs:
docker:
- image: circleci/node:12
steps:
- restore_cache:
keys:
- v1-{{ .Branch }}-{{ .Revision }}
- v1-{{ .Branch }}
- v1-
- checkout
- run:
name: Install
command: npm install
- save_cache:
key: v1-{{ .Branch }}-{{ .Revision }}
paths:
- node_modules
- .git
- run: npm run test

release:
docker:
- image: circleci/node:12
steps:
- restore_cache:
keys:
- v1-{{ .Branch }}-{{ .Revision }}
- v1-{{ .Branch }}
- v1-
- checkout
- run:
name: Install
Expand All @@ -22,21 +38,14 @@ jobs:
command: npx semantic-release

workflows:
version: 2
test:
default_workflow:
jobs:
- test:
name: Test
#context: nodejs-install
filters:
branches:
ignore:
- master
release:
jobs:
context: nodejs-install
- release:
name: Release
#context: nodejs-lib-release
context: nodejs-lib-release
requires:
- test
filters:
branches:
only:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## [2.2.0] - 2021-01-28
- @deepcode/tsc is transitioning to @snyk/code-client
## [2.1.0] - 2021-01-05
- Added file field to marker positions for inte-file suggestions

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 DeepCodeAI
Copyright (c) 2020 Snyk Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
15 changes: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,24 @@

Typescript consumer of public API

[![deepcode](https://www.deepcode.ai/api/gh/badge?key=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwbGF0Zm9ybTEiOiJnaCIsIm93bmVyMSI6IkRlZXBDb2RlQUkiLCJyZXBvMSI6InRzYyIsImluY2x1ZGVMaW50IjpmYWxzZSwiYXV0aG9ySWQiOjEyNDY5LCJpYXQiOjE1OTYwOTY3MTJ9.I7rfzfZLPc-SMEModrFPFTMbKpnCkQ5ztPzrPOdruhU)](https://www.deepcode.ai/app/gh/DeepCodeAI/tsc/_/dashboard?utm_content=gh%2FDeepCodeAI%2Ftsc)

[![npm version](https://img.shields.io/npm/v/@deepcode/tsc.svg?style=flat-square)](https://www.npmjs.org/package/@deepcode/tsc)
[![npm downloads](https://img.shields.io/npm/dm/@deepcode/tsc.svg?style=flat-square)](http://npm-stat.com/charts.html?package=@deepcode/tsc)
[![npm version](https://img.shields.io/npm/v/@snyk/code-client.svg?style=flat-square)](https://www.npmjs.org/package/@snyk/code-client)
[![npm downloads](https://img.shields.io/npm/dm/@snyk/code-client.svg?style=flat-square)](http://npm-stat.com/charts.html?package=@snyk/code-client)

# Installation

```shell script
$ npm install --save @deepcode/tsc
$ npm install --save @snyk/code-client
```

# Usage

### Creates and initializes an instance

```javascript
import tsc from '@deepcode/tsc';
import tsc from '@snyk/code-client';

// An address of server which will be used in order to send code and analyse it.
// Default: 'https://www.deepcode.ai'.
const baseURL = 'https://www.deepcode.ai';
const baseURL = 'https://www.snyk.io';

```

Expand All @@ -31,7 +28,7 @@ const baseURL = 'https://www.deepcode.ai';
```javascript
const loginResponse = await tsc.startSession({
baseURL,
// An identificator for the editor using the DeepCode APIs
// An identificator for the editor using the Snyk APIs
source: 'atom',
});

Expand Down
18 changes: 7 additions & 11 deletions development.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,24 @@ $ npm install && npm run compile && npx yalc publish
After that you have to create symlink to your package in your project folder:
```shell script
$ cd <project-location>
$ npx yalc add @deepcode/tsc
$ npx yalc add @snyk/code-client
```

## Publishing

### Before publishing make sure test pass

Test variables:
- `DEEPCODE_URL` is the DC server URL (staging deployment if not provided)
- `DEEPCODE_API_KEY` is a sessionToken of a user with access to the DeepCodeAI organization
- `DEEPCODE_API_KEY_NO_ACCESS` is a sessionToken of a user with no access to the DeepCodeAI organization (even better if on a different platform than GitHub)
- `DEEPCODE_OAUTH_KEY` is a GitHub personal access token of a user with access to the DeepCodeAI organization
- `SNYK_URL` is the DC server URL (staging deployment if not provided)
- `SNYK_API_KEY` is a sessionToken of a user with access to the Snyk
- `SNYK_API_KEY_NO_ACCESS` is a sessionToken of a user with no access to the snyk organization (even better if on a different platform than GitHub)
- `SNYK_OAUTH_KEY` is a GitHub personal access token of a user with access to the snyk organization

```shell script
$ cd <package-location>
$ DEEPCODE_URL=... DEEPCODE_API_KEY=... DEEPCODE_API_KEY_NO_ACCESS=... DEEPCODE_AUTH_KEY=... npm run test
$ SNYK_URL=... SNYK_API_KEY=... SNYK_API_KEY_NO_ACCESS=... SNYK_AUTH_KEY=... npm run test
```

#### Compile and publish

```shell script
$ cd <package-location>
$ npm run compile
$ npm publish --access public
```
No need to do anything. We have CircleCI CI/CD pipeline with automatic semantic versioning
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@deepcode/tsc",
"description": "Typescript consumer of Deepcode public API",
"name": "@snyk/code-client",
"description": "Typescript consumer of SnykCode public API",
"main": "dist/index.js",
"module": "dist/index.es.js",
"types": "dist/index.d.ts",
Expand All @@ -16,18 +16,18 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/DeepCodeAI/tsc.git"
"url": "git+https://github.com/snyk/code-client.git"
},
"keywords": [
"deepcode",
"snyk",
"api client"
],
"author": "DeepCodeAI",
"author": "snyk",
"license": "MIT",
"bugs": {
"url": "https://github.com/DeepCodeAI/tsc/issues"
"url": "https://github.com/snyk/code-client/issues"
},
"homepage": "https://github.com/DeepCodeAI/tsc#readme",
"homepage": "https://github.com/snyk/code-client#readme",
"jest": {
"preset": "ts-jest",
"testEnvironment": "node"
Expand Down
2 changes: 1 addition & 1 deletion tests/analysis.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('Functional test of analysis', () => {
expect(bundle).toHaveProperty('supportedFiles');
expect(bundle).toHaveProperty('analysisURL');
expect(Object.keys(bundle.analysisResults.files).length).toEqual(4);
expect(Object.keys(bundle.analysisResults.files)[0]).toEqual(`${sampleProjectPath}/AnnotatorTest.cpp`);
expect(bundle.analysisResults.files.hasOwnProperty(`${sampleProjectPath}/AnnotatorTest.cpp`)).toBeTruthy();
expect(Object.keys(bundle.analysisResults.suggestions).length).toEqual(8);

expect(bundle.analysisResults.timing.analysis).toBeGreaterThanOrEqual(bundle.analysisResults.timing.fetchingCode);
Expand Down
29 changes: 19 additions & 10 deletions tests/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,29 +360,38 @@ describe('Requests to public API', () => {
'exampleCommitDescriptions',
'exampleCommitFixes',
]);
expect(suggestion.id).toEqual('cpp%2Fdc%2FCppSameEvalBinaryExpressionfalse');
expect(suggestion.leadURL).toEqual('');
expect(suggestion.repoDatasetSize).toEqual(0);
expect(suggestion.exampleCommitDescriptions).toEqual([]);
expect(suggestion.exampleCommitFixes).toEqual([]);
expect(suggestion.id).toEqual('javascript%2Fdc_interfile_project%2FDisablePoweredBy');
expect(suggestion.leadURL).toEqual('http://expressjs.com/en/advanced/best-practice-security.html#at-a-minimum-disable-x-powered-by-header');
expect(suggestion.repoDatasetSize).toEqual(874);
expect(suggestion.exampleCommitDescriptions).toEqual([
"Test without express",
"/server tests ()",
"secure the api with helmet",
]);
expect(suggestion.exampleCommitFixes.length).toEqual(3);
expect(suggestion.message).toEqual(
'The expression will always evaluate to false because both sides always hold the same value.',
'Disable X-Powered-By header for your Express app (consider using Helmet middleware), because it exposes information about the used framework to potential attackers.',
);
expect(suggestion.rule).toEqual('CppSameEvalBinaryExpressionfalse');
expect(suggestion.rule).toEqual('DisablePoweredBy');
expect(suggestion.severity).toEqual(2);

expect(suggestion.tags).toEqual([]);
expect(suggestion.tags).toEqual([
"maintenance",
"express",
"server",
"helmet",
]);
expect(Object.keys(response.value.analysisResults.files).length).toEqual(4);
const filePath = `/AnnotatorTest.cpp`;
expect(response.value.analysisResults.files[filePath]).toEqual({
'0': [
'2': [
{
cols: [8, 27],
markers: [],
rows: [5, 5],
},
],
'1': [
'3': [
{
cols: [6, 25],
markers: [
Expand Down
4 changes: 2 additions & 2 deletions tests/constants/base.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const baseURL = process.env.DEEPCODE_URL || 'https://www.deepcoded.com';
export const sessionToken = process.env.DEEPCODE_API_KEY || '';
export const baseURL = process.env.SNYK_URL || 'https://www.deepcoded.com';
export const sessionToken = process.env.SNYK_API_KEY || '';
export const TEST_TIMEOUT = 100000;
4 changes: 2 additions & 2 deletions tests/git.analysis.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { ErrorCodes } from '../src/constants';
import { IGitBundle } from '../src/interfaces/analysis-result.interface';
import { stringSplice, getArgumentsAndMessage } from '../src/sarif_converter';

const oAuthToken = process.env.DEEPCODE_OAUTH_KEY || '';
const sessionTokenNoRepoAccess = process.env.DEEPCODE_API_KEY_NO_ACCESS || '';
const oAuthToken = process.env.SNYK_OAUTH_KEY || '';
const sessionTokenNoRepoAccess = process.env.SNYK_API_KEY_NO_ACCESS || '';

// This trick is for automatic tests, where real oauth token is not available
const itif = (condition: boolean) => (condition ? it : it.skip);
Expand Down

0 comments on commit 050c224

Please sign in to comment.