Skip to content

Commit

Permalink
Merge pull request #15 from snyk/chore/test-and-release
Browse files Browse the repository at this point in the history
Chore/test and release
  • Loading branch information
adrukh committed Aug 6, 2018
2 parents dd14e90 + 5d90fa9 commit 8243aba
Show file tree
Hide file tree
Showing 13 changed files with 234 additions and 117 deletions.
52 changes: 52 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"parserOptions": {
"ecmaVersion": 6
},
"env": {
"node": true,
"es6": true
},
"rules": {
"array-bracket-spacing": [2, "never"],
"block-scoped-var": 2,
"brace-style": 2,
"camelcase": 1,
"comma-dangle": ["error", "always-multiline"],
"computed-property-spacing": [2, "never"],
"curly": 2,
"eol-last": 2,
"eqeqeq": [2, "smart"],
"guard-for-in": 1,
"indent": [
2,
2,
{
"SwitchCase": 1
}
],
"max-depth": [1, 3],
"max-len": [1, 80],
"max-statements": [1, 25],
"new-cap": 0,
"no-caller": 2,
"no-else-return": 2,
"no-extend-native": 2,
"no-mixed-spaces-and-tabs": 2,
"no-trailing-spaces": 2,
"no-undef": 2,
"no-unused-vars": 1,
"no-use-before-define": [2, "nofunc"],
"object-curly-spacing": [2, "never"],
"quotes": [2, "single", "avoid-escape"],
"semi": [2, "always"],
"keyword-spacing": [2, {"before": true, "after": true}],
"space-before-function-paren": [
2,
{
"anonymous": "ignore",
"named": "never"
}
],
"space-unary-ops": 2
}
}
13 changes: 8 additions & 5 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,18 @@ To release a major you need to add `BREAKING CHANGE: ` to the start of the body

## Code standards

Ensure that your code adheres to the included `.jshintrc` and `.jscsrc` configs.
Ensure that your code adheres to the included `.eslintrc` config by running `npm run lint`.

## Sending pull requests

- new command line options are generally discouraged unless there's a *really* good reason
- add tests for newly added code (and try to mirror directory and file structure if possible)
- spell check
- PRs will not be code reviewed unless all tests are passing
- PRs will not be code reviewed unless all tests are passing (run `npm test`)

*Important:* when fixing a bug, please commit a **failing test** first so that Travis CI (or I can) can show the code failing. Once that commit is in place, then commit the bug fix, so that we can test *before* and *after*.
*Important:* when fixing a bug, please commit a **failing test** first demonstrate the current code is failing. Once that commit is in place, then commit the bug fix, so that we can test *before* and *after*.

Remember that you're developing for multiple platforms and versions of node, so if the tests pass on your Mac or Linux or Windows machine, it *may* not pass elsewhere.
Remember that you're developing for multiple platforms and versions of node, so if the tests pass on your Mac or Linux or Windows machine, it *may* not pass elsewhere.

## Contributor Agreement

A pull-request will only be considered for merging into the upstream codebase after you have signed our [contributor agreement](https://github.com/snyk/snyk-sbt-plugin/blob/master/Contributor-Agreement.md), assigning us the rights to the contributed code and granting you a license to use it in return. If you submit a pull request, you will be prompted to review and sign the agreement with one click (we use [CLA assistant](https://cla-assistant.io/)).
14 changes: 0 additions & 14 deletions .jscsrc

This file was deleted.

6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ node_js:
cache:
directories:
- node_modules
script: npm run test
script:
- npm test
- npm run test-system
jobs:
include:
- stage: npm release
node_js: "8" # This *has* to be the "build leader"
script: skip
after_success:
- TRAVIS_JOB_NUMBER=WORKAROUND.1 npm run semantic-release
- npm run semantic-release
branches:
only:
- master
39 changes: 39 additions & 0 deletions Contributor-Agreement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Snyk CLI tool contributor agreement

This Snyk CLI tool Agreement (this **"Agreement"**) applies to any Contribution you make to any Work.

This is a binding legal agreement on you and any organization you represent. If you are signing this Agreement on behalf of your employer or other organization, you represent and warrant that you have the authority to agree to this Agreement on behalf of the organization.

## 1. Definitions

**"Contribution"** means any original work, including any modification of or addition to an existing work, that you submit to Snyk CLI tool repo in any manner for inclusion in any Work.

**"Snyk", "we"** and **"us"** means Snyk Ltd.

**"Work"** means any project, work or materials owned or managed by Snyk Ltd.

**"You"** and **"your"** means you and any organization on whose behalf you are entering this Agreement.

## 2. Copyright Assignment, License and Waiver

**(a) Assignment.** By submitting a Contribution, you assign to Snyk all right, title and interest in any copright you have in the Contribution, and you waive any rights, including any moral rights, database rights, etc., that may affect your ownership of the copyright in the Contribution.

**(b) License to Snyk.** If your assignment in Section 2(a) is ineffective for any reason, you grant to us and to any recipient of any Work distributed by use, a perpetual, worldwide, transferable, non-exclusive, no-charge, royalty-free, irrevocable, and sublicensable licence to use, reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute Contributions and any derivative work created based on a Contribution. If your license grant is ineffective for any reason, you irrevocably waive and covenant to not assert any claim you may have against us, our successors in interest, and any of our direct or indirect licensees and customers, arising out of our, our successors in interest's, or any of our direct or indirect licensees' or customers' use, reproduction, preparation of derivative works, public display, public performance, sublicense, and distribution of a Contribution. You also agree that we may publicly use your name and the name of any organization on whose behalf you're entering into this Agreement in connection with publicizing the Work.

**(c) License to you.** We grant to you a perpetual, worldwide, transferable, non-exclusive, no-charge, royalty-free, irrevocable, and sublicensable license to use, reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute a Contribution and any derivative works you create based on a Contribution.

## 3. Patent License
You grant to us and to any recipient of any Work distributed by us, a perpetual, worldwide, transferable, non-exclusive, no-charge, royalty-free, irrevocable, and sublicensable patent license to make, have made, use, sell, offer to sell, import, and otherwise transfer the Contribution in whole or in part, along or included in any Work under any patent you own, or license from a third party, that is necessarily infringed by the Contribution or by combination of the Contribution with any Work.

## 4. Your Representation and Warranties.
By submitting a Contribution, you represent and warrant that: (a) each Contribution you submit is an original work and you can legally grant the rights set out in this Agreement; (b) the Contribution does not, and any exercise of the rights granted by you will not, infringe any third party's intellectual property or other right; and (c) you are not aware of any claims, suits, or actions pertaining to the Contribution. You will notify us immediately if you become aware or have reason to believe that any of your representations and warranties is or becomes inaccurate.

##5. Intellectual Property
Except for the assignment and licenses set forth in this Agreement, this Agreement does not transfer any right, title or interest in any intellectual property right of either party to the other. If you choose to provide us with suggestions, ideas for improvement, recommendations or other feedback, on any Work we may use your feedback without any restriction or payment.

## Miscellaneous
English law governs this Agreement, excluding any applicable conflict of laws rules or principles, and the parties agree to the exclusive jurisdiction of the courts in England, UK. This Agreement does not create a partnership, agency relationship, or joint venture between the parties. We may assign this Agreement without notice or restriction. If any provision of this Agreement is unenforcable, that provision will be modified to render it enforceable to the extent possible to effect the parties' intention and the remaining provisions will not be affected. The parties may amend this Agreement only in a written amendment signed by both parties. This Agreement comprises the parties' entire agreement relating to the subject matter of this Agreement.

**Agreed and accepted on my behalf and on behalf of my organization**

Our contributor agreement is based on the [mongoDB contributor agreement] (https://www.mongodb.com/legal/contributor-agreement).
34 changes: 34 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# https://www.appveyor.com/docs/appveyor-yml

# to disable automatic builds
build: off
branches:
only:
- master

init:
- git config --global core.autocrlf true

shallow_clone: true
clone_depth: 1

cache:
- node_modules -> package.json

environment:
matrix:
- nodejs_version: "8"
- nodejs_version: "6"
- nodejs_version: "4"

matrix:
fast_finish: true

install:
- ps: Install-Product node $env:nodejs_version
- node --version
- npm --version
- npm install

test_script:
- npm test
52 changes: 27 additions & 25 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,38 @@ module.exports.__tests = {
};

function inspect(root, targetFile, options) {
if (!options) { options = { dev: false }; }
if (!options) {
options = {dev: false};
}
return subProcess.execute('sbt',
buildArgs(root, targetFile, options.args),
{ cwd: root })
.then(function (result) {
var packageName = path.basename(root);
var packageVersion = '0.0.0';
var depTree = parser.parse(result, packageName, packageVersion);
depTree.packageFormatVersion = packageFormatVersion;
{cwd: root})
.then(function (result) {
var packageName = path.basename(root);
var packageVersion = '0.0.0';
var depTree = parser.parse(result, packageName, packageVersion);
depTree.packageFormatVersion = packageFormatVersion;

return {
plugin: {
name: 'bundled:sbt',
runtime: 'unknown',
},
package: depTree,
};
})
.catch(function (error) {
debug(error);
if (typeof error == 'string') {
var thrownError = parser.parseError(error);
if (thrownError) {
throw thrownError;
return {
plugin: {
name: 'bundled:sbt',
runtime: 'unknown',
},
package: depTree,
};
})
.catch(function (error) {
debug(error);
if (typeof error == 'string') {
var thrownError = parser.parseError(error);
if (thrownError) {
throw thrownError;
}
throw new Error('snyk-sbt-plugin error: ' + error);
}
throw new Error('snyk-sbt-plugin error: ' + error);
}

throw error;
});
throw error;
});
}

function buildArgs(root, targetFile, sbtArgs) {
Expand Down
58 changes: 30 additions & 28 deletions lib/parse-sbt.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,36 @@ var tabdown = require('./tabdown');
function convertStrToTree(dependenciesTextTree) {
var lines = dependenciesTextTree.toString().split('\n') || [];
var newLines = lines
.map(function (line) {
return line.replace(/\u001b\[0m/g, '');
})
.filter(function (line) {
if (line.indexOf('[info] ') === 0 && line.indexOf('+-') > -1) {
return true;
}
var match = line.match(/\[info\]\s[\w_\.\-]+:[\w_\.\-]+:[\w_\.\-]+/);
if (match && match[0].length === line.length) {
return true;
}
match = line.match(/\[info\]\s[\w_\.\-]+:[\w_\.\-]+:[\w_\.\-]+\s\[S\]/);
if (match && match[0].length === line.length) {
return true;
}
return false;
})
.map(function (line) {
return line
.slice(7, line.length) // slice off '[info] '
.replace(' [S]', '')
.replace(/\|/g, ' ')
.replace('+-', '')
.replace(/\s\s/g, '\t');
});
.map(function (line) {
return line.replace(/\u001b\[0m/g, '');
})
.filter(function (line) {
if (line.indexOf('[info] ') === 0 && line.indexOf('+-') > -1) {
return true;
}
var match = line.match(/\[info\]\s[\w_\.\-]+:[\w_\.\-]+:[\w_\.\-]+/);
if (match && match[0].length === line.length) {
return true;
}
match = line.match(/\[info\]\s[\w_\.\-]+:[\w_\.\-]+:[\w_\.\-]+\s\[S\]/);
if (match && match[0].length === line.length) {
return true;
}
return false;
})
.map(function (line) {
return line
.slice(7, line.length) // slice off '[info] '
.replace(' [S]', '')
.replace(/\|/g, ' ')
.replace('+-', '')
.replace(/\s\s/g, '\t');
});
var tree = tabdown.parse(newLines, '\t');
return tree;
}

function walkInTree(toNode, fromNode, parentNode) {
function walkInTree(toNode, fromNode) {
if (fromNode.children && fromNode.children.length > 0) {
for (var j = 0; j < fromNode.children.length; j++) {
var externalNode = getPackageNameAndVersion(
Expand Down Expand Up @@ -67,7 +67,7 @@ function getPackageNameAndVersion(packageDependency) {
app = app.split('\t').join('');
app = app.trim();
version = version.trim();
return { name: app, version: version };
return {name: app, version: version};
}

function convertDepArrayToObject(depsArr) {
Expand Down Expand Up @@ -125,7 +125,9 @@ module.exports = {
function getKeys(obj) {
var keys = [];
for (var key in obj) {
if (obj.hasOwnProperty(key)) { keys.push(key); }
if (obj.hasOwnProperty(key)) {
keys.push(key);
}
}
return keys;
}
10 changes: 7 additions & 3 deletions lib/sub-process.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var childProcess = require('child_process');

module.exports.execute = function (command, args, options) {
var spawnOptions = { shell: true };
var spawnOptions = {shell: true};
if (options && options.cwd) {
spawnOptions.cwd = options.cwd;
}
Expand All @@ -11,8 +11,12 @@ module.exports.execute = function (command, args, options) {
var stderr = '';

var proc = childProcess.spawn(command, args, spawnOptions);
proc.stdout.on('data', function (data) { stdout = stdout + data; });
proc.stderr.on('data', function (data) { stderr = stderr + data; });
proc.stdout.on('data', function (data) {
stdout = stdout + data;
});
proc.stderr.on('data', function (data) {
stderr = stderr + data;
});

proc.on('close', function (code) {
if (code !== 0) {
Expand Down
6 changes: 1 addition & 5 deletions lib/tabdown.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
exports.parse = function (lines, marker) {

var populatefn = populatefn || function (obj) { return obj; };
marker = marker || '\t';

exports.parse = function (lines) {
function addHiddenProperties(scope, props) {
for (var p in props) {
Object.defineProperty(scope, p, {enumerable: false, value: props[p]});
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
"main": "lib/index.js",
"scripts": {
"test": "npm run lint && npm run test-functional",
"lint": "jscs `find ./lib -name '*.js'` -v && jscs `find ./test -name '*.js'` -v",
"test-functional": "tap `find ./test/functional -name '*.test.js'`",
"test-system": "tap --timeout=300 `find ./test/system -name '*.test.js'`",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
"lint": "eslint -c .eslintrc lib test",
"test-functional": "tap -R spec ./test/functional/*.test.js",
"test-system": "tap -R spec --timeout=300 ./test/system/*.test.js",
"semantic-release": "semantic-release"
},
"author": "snyk.io",
"license": "Apache-2.0",
"dependencies": {
"debug": "^2.2.0"
"debug": "^3.1.0"
},
"devDependencies": {
"jscs": "^3.0.7",
"semantic-release": "^6.3.6",
"eslint": "^4.11.0",
"semantic-release": "^15",
"sinon": "^2.4.1",
"tap": "^10.7.0",
"tap": "^12.0.1",
"tap-only": "0.0.5"
}
}

0 comments on commit 8243aba

Please sign in to comment.